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