@@ -395,9 +395,8 @@ class GenXSimdCFConformance {
395
395
BasicBlock *PhiPredBlock = nullptr );
396
396
Value *lowerPHIUse (PHINode *PN, SetVector<Value *> &ToRemove);
397
397
Value *lowerArgumentUse (Argument *Arg);
398
- Value *insertCond (Value *OldVal, Value *NewVal, const Twine &Name,
399
- IRBuilder<> &IRB);
400
- Value *truncateCond (Value *In, Type *Ty, const Twine &Name, IRBuilder<> &IRB);
398
+ Value *insertCond (Value *OldVal, Value *NewVal, const Twine &Name, Instruction *InsertBefore, const DebugLoc &DL);
399
+ Value *truncateCond (Value *In, Type *Ty, const Twine &Name, Instruction *InsertBefore, const DebugLoc &DL);
401
400
void lowerGoto (CallInst *Goto);
402
401
void lowerJoin (CallInst *Join);
403
402
void replaceGotoJoinUses (CallInst *GotoJoin, ArrayRef<Value *> Vals);
@@ -3485,7 +3484,8 @@ void GenXSimdCFConformance::checkInterference(SetVector<SimpleValue> *Vals,
3485
3484
* Return: value, possibly the same as the input value
3486
3485
*/
3487
3486
Value *GenXSimdCFConformance::insertCond (Value *OldVal, Value *NewVal,
3488
- const Twine &Name, IRBuilder<> &IRB) {
3487
+ const Twine &Name, Instruction *InsertBefore, const DebugLoc &DL)
3488
+ {
3489
3489
unsigned OldWidth =
3490
3490
cast<IGCLLVM::FixedVectorType>(OldVal->getType ())->getNumElements ();
3491
3491
unsigned NewWidth =
@@ -3497,24 +3497,27 @@ Value *GenXSimdCFConformance::insertCond(Value *OldVal, Value *NewVal,
3497
3497
// GenXLowering decides whether this is suitable to lower to wrpredregion, or
3498
3498
// needs to be lowered to something less efficient.
3499
3499
SmallVector<Constant *, 32 > Indices;
3500
+ Type *I32Ty = Type::getInt32Ty (InsertBefore->getContext ());
3500
3501
unsigned i;
3501
3502
for (i = 0 ; i != NewWidth; ++i)
3502
- Indices.push_back (IRB. getInt32 ( i));
3503
- auto UndefIndex = UndefValue::get (IRB. getInt32Ty () );
3503
+ Indices.push_back (ConstantInt::get (I32Ty, i));
3504
+ auto UndefIndex = UndefValue::get (I32Ty );
3504
3505
for (; i != OldWidth; ++i)
3505
3506
Indices.push_back (UndefIndex);
3506
- auto SV = IRB. CreateShuffleVector (NewVal, UndefValue::get (NewVal->getType ()),
3507
- ConstantVector::get (Indices),
3508
- NewVal-> getName () + " .extend " );
3507
+ auto SV1 = new ShuffleVectorInst (NewVal, UndefValue::get (NewVal->getType ()),
3508
+ ConstantVector::get (Indices), NewVal-> getName () + " .extend " , InsertBefore);
3509
+ SV1-> setDebugLoc (DL );
3509
3510
if (isa<UndefValue>(OldVal))
3510
- return SV ;
3511
+ return SV1 ;
3511
3512
Indices.clear ();
3512
3513
for (i = 0 ; i != NewWidth; ++i)
3513
- Indices.push_back (IRB. getInt32 ( i + OldWidth));
3514
+ Indices.push_back (ConstantInt::get (I32Ty, i + OldWidth));
3514
3515
for (; i != OldWidth; ++i)
3515
- Indices.push_back (IRB.getInt32 (i));
3516
- return IRB.CreateShuffleVector (OldVal, SV, ConstantVector::get (Indices),
3517
- Name);
3516
+ Indices.push_back (ConstantInt::get (I32Ty, i));
3517
+ auto SV2 = new ShuffleVectorInst (OldVal, SV1, ConstantVector::get (Indices),
3518
+ Name, InsertBefore);
3519
+ SV2->setDebugLoc (DL);
3520
+ return SV2;
3518
3521
}
3519
3522
3520
3523
/* **********************************************************************
@@ -3529,19 +3532,23 @@ Value *GenXSimdCFConformance::insertCond(Value *OldVal, Value *NewVal,
3529
3532
* Return: value, possibly the same as the input value
3530
3533
*/
3531
3534
Value *GenXSimdCFConformance::truncateCond (Value *In, Type *Ty,
3532
- const Twine &Name,
3533
- IRBuilder<> &IRB) {
3535
+ const Twine &Name, Instruction *InsertBefore, const DebugLoc &DL)
3536
+ {
3534
3537
unsigned InWidth =
3535
3538
cast<IGCLLVM::FixedVectorType>(In->getType ())->getNumElements ();
3536
3539
unsigned TruncWidth = cast<IGCLLVM::FixedVectorType>(Ty)->getNumElements ();
3537
3540
if (InWidth == TruncWidth)
3538
3541
return In;
3539
3542
// Do the truncate with shufflevector. GenXLowering lowers it to rdpredregion.
3540
- SmallVector<Constant *, 32 > Indices (TruncWidth);
3541
- for (unsigned i = 0 ; i < TruncWidth; ++i)
3542
- Indices.push_back (IRB.getInt32 (i));
3543
- return IRB.CreateShuffleVector (In, UndefValue::get (In->getType ()),
3544
- ConstantVector::get (Indices), Name);
3543
+ SmallVector<Constant *, 32 > Indices;
3544
+ Type *I32Ty = Type::getInt32Ty (InsertBefore->getContext ());
3545
+ unsigned i;
3546
+ for (i = 0 ; i != TruncWidth; ++i)
3547
+ Indices.push_back (ConstantInt::get (I32Ty, i));
3548
+ auto SV = new ShuffleVectorInst (In, UndefValue::get (In->getType ()),
3549
+ ConstantVector::get (Indices), Name, InsertBefore);
3550
+ SV->setDebugLoc (DL);
3551
+ return SV;
3545
3552
}
3546
3553
3547
3554
/* **********************************************************************
@@ -3555,33 +3562,44 @@ Value *GenXSimdCFConformance::truncateCond(Value *In, Type *Ty,
3555
3562
void GenXSimdCFConformance::lowerGoto (CallInst *Goto)
3556
3563
{
3557
3564
LLVM_DEBUG (dbgs () << " lowerGoto: " << *Goto << " \n " );
3558
- IRBuilder<> IRB ( Goto);
3565
+ const DebugLoc &DL = Goto-> getDebugLoc ( );
3559
3566
if (EnableGenXGotoJoin && !lowerSimdCF)
3560
3567
DiagnosticInfoSimdCF::emit (Goto, " failed to optimize SIMD branch" , DS_Warning);
3561
3568
Value *Results[3 ];
3562
3569
auto EM = Goto->getOperand (0 );
3563
3570
auto Cond = Goto->getOperand (2 );
3564
3571
// EM is always 32 bit. Extract SubEM, of the same width as Cond, from it.
3565
- auto OldSubEM =
3566
- truncateCond (EM, Cond-> getType (), EM-> getName () + " .sub" , IRB );
3572
+ auto OldSubEM = truncateCond (EM, Cond-> getType (),
3573
+ EM-> getName () + " .sub" , Goto, DL );
3567
3574
// Result 1: NewRM = OldRM | (SubEM & ~Cond)
3568
- auto NotCond = IRB.CreateXor (Cond, Constant::getAllOnesValue (Cond->getType ()),
3569
- Goto->getName () + " .notcond" );
3570
- auto NotCondAndSubEM =
3571
- IRB.CreateAnd (NotCond, OldSubEM, Goto->getName () + " .disabling" );
3575
+ auto NotCond = BinaryOperator::Create (Instruction::Xor, Cond,
3576
+ Constant::getAllOnesValue (Cond->getType ()),
3577
+ Goto->getName () + " .notcond" , Goto);
3578
+ NotCond->setDebugLoc (DL);
3579
+ auto NotCondAndSubEM = BinaryOperator::Create (Instruction::And, NotCond,
3580
+ OldSubEM, Goto->getName () + " .disabling" , Goto);
3581
+ NotCondAndSubEM->setDebugLoc (DL);
3572
3582
Value *OldRM = Goto->getArgOperand (1 );
3573
- auto NewRM = IRB.CreateOr (OldRM, NotCondAndSubEM, Goto->getName () + " .newRM" );
3583
+ auto NewRM = BinaryOperator::Create (Instruction::Or, OldRM, NotCondAndSubEM,
3584
+ Goto->getName () + " .newRM" , Goto);
3585
+ NewRM->setDebugLoc (DL);
3574
3586
Results[1 ] = NewRM;
3575
3587
// And SubEM with Cond.
3576
- auto SubEM = IRB.CreateAnd (OldSubEM, Cond, Goto->getName () + " .subEM" );
3588
+ auto SubEM = BinaryOperator::Create (Instruction::And, OldSubEM, Cond,
3589
+ Goto->getName () + " .subEM" , Goto);
3590
+ SubEM->setDebugLoc (DL);
3577
3591
// Insert that back into EM. That is result 0.
3578
- Results[0 ] = EM = insertCond (EM, SubEM, Goto->getName () + " .EM" , IRB );
3592
+ Results[0 ] = EM = insertCond (EM, SubEM, Goto->getName () + " .EM" , Goto, DL );
3579
3593
// Result 2: BranchCond = !any(SubEM)
3580
3594
Function *AnyFunc = GenXIntrinsic::getGenXDeclaration (M, GenXIntrinsic::genx_any,
3581
3595
SubEM->getType ());
3582
- auto Any = IRB.CreateCall (AnyFunc, SubEM, SubEM->getName () + " .any" );
3583
- auto Not = IRB.CreateXor (Any, Constant::getAllOnesValue (Any->getType ()),
3584
- Any->getName () + " .not" );
3596
+ auto Any = CallInst::Create (AnyFunc, SubEM,
3597
+ SubEM->getName () + " .any" , Goto);
3598
+ Any->setDebugLoc (DL);
3599
+ auto Not = BinaryOperator::Create (Instruction::Xor, Any,
3600
+ Constant::getAllOnesValue (Any->getType ()),
3601
+ Any->getName () + " .not" , Goto);
3602
+ Not->setDebugLoc (DL);
3585
3603
Results[2 ] = Not;
3586
3604
// Replace uses.
3587
3605
replaceGotoJoinUses (Goto, Results);
@@ -3595,22 +3613,29 @@ void GenXSimdCFConformance::lowerGoto(CallInst *Goto)
3595
3613
void GenXSimdCFConformance::lowerJoin (CallInst *Join)
3596
3614
{
3597
3615
LLVM_DEBUG (dbgs () << " lowerJoin: " << *Join << " \n " );
3598
- IRBuilder<> IRB ( Join);
3616
+ const DebugLoc &DL = Join-> getDebugLoc ( );
3599
3617
Value *Results[2 ];
3600
3618
auto EM = Join->getOperand (0 );
3601
3619
auto RM = Join->getOperand (1 );
3602
3620
// EM is always 32 bit. Extract SubEM, of the same width as RM, from it.
3603
- auto OldSubEM = truncateCond (EM, RM->getType (), EM->getName () + " .sub" , IRB);
3621
+ auto OldSubEM = truncateCond (EM, RM->getType (), EM->getName () + " .sub" ,
3622
+ Join, DL);
3604
3623
// Or it with RM.
3605
- auto SubEM = IRB.CreateOr (OldSubEM, RM, Join->getName () + " .subEM" );
3624
+ auto SubEM = BinaryOperator::Create (Instruction::Or, OldSubEM, RM,
3625
+ Join->getName () + " .subEM" , Join);
3626
+ SubEM->setDebugLoc (DL);
3606
3627
// Insert that back into EM. That is result 0.
3607
- Results[0 ] = EM = insertCond (EM, SubEM, Join->getName () + " .EM" , IRB );
3628
+ Results[0 ] = EM = insertCond (EM, SubEM, Join->getName () + " .EM" , Join, DL );
3608
3629
// Result 1: BranchCond = !any(SubEM)
3609
3630
Function *AnyFunc = GenXIntrinsic::getGenXDeclaration (M, GenXIntrinsic::genx_any,
3610
3631
SubEM->getType ());
3611
- auto Any = IRB.CreateCall (AnyFunc, SubEM, SubEM->getName () + " .any" );
3612
- auto Not = IRB.CreateXor (Any, Constant::getAllOnesValue (Any->getType ()),
3613
- Any->getName () + " .not" );
3632
+ auto Any = CallInst::Create (AnyFunc, SubEM,
3633
+ SubEM->getName () + " .any" , Join);
3634
+ Any->setDebugLoc (DL);
3635
+ auto Not = BinaryOperator::Create (Instruction::Xor, Any,
3636
+ Constant::getAllOnesValue (Any->getType ()),
3637
+ Any->getName () + " .not" , Join);
3638
+ Not->setDebugLoc (DL);
3614
3639
Results[1 ] = Not;
3615
3640
// Replace uses.
3616
3641
replaceGotoJoinUses (Join, Results);
0 commit comments