@@ -6391,10 +6391,13 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
6391
6391
return nullptr ;
6392
6392
}
6393
6393
6394
- static Value *simplifyIntrinsic (CallBase *Call, const SimplifyQuery &Q) {
6395
-
6396
- unsigned NumOperands = Call->arg_size ();
6397
- Function *F = cast<Function>(Call->getCalledFunction ());
6394
+ static Value *simplifyIntrinsic (CallBase *Call, Value *Callee,
6395
+ ArrayRef<Value *> Args,
6396
+ const SimplifyQuery &Q) {
6397
+ // Operand bundles should not be in Args.
6398
+ assert (Call->arg_size () == Args.size ());
6399
+ unsigned NumOperands = Args.size ();
6400
+ Function *F = cast<Function>(Callee);
6398
6401
Intrinsic::ID IID = F->getIntrinsicID ();
6399
6402
6400
6403
// Most of the intrinsics with no operands have some kind of side effect.
@@ -6420,42 +6423,40 @@ static Value *simplifyIntrinsic(CallBase *Call, const SimplifyQuery &Q) {
6420
6423
}
6421
6424
6422
6425
if (NumOperands == 1 )
6423
- return simplifyUnaryIntrinsic (F, Call-> getArgOperand ( 0 ) , Q);
6426
+ return simplifyUnaryIntrinsic (F, Args[ 0 ] , Q);
6424
6427
6425
6428
if (NumOperands == 2 )
6426
- return simplifyBinaryIntrinsic (F, Call->getArgOperand (0 ),
6427
- Call->getArgOperand (1 ), Q);
6429
+ return simplifyBinaryIntrinsic (F, Args[0 ], Args[1 ], Q);
6428
6430
6429
6431
// Handle intrinsics with 3 or more arguments.
6430
6432
switch (IID) {
6431
6433
case Intrinsic::masked_load:
6432
6434
case Intrinsic::masked_gather: {
6433
- Value *MaskArg = Call-> getArgOperand ( 2 ) ;
6434
- Value *PassthruArg = Call-> getArgOperand ( 3 ) ;
6435
+ Value *MaskArg = Args[ 2 ] ;
6436
+ Value *PassthruArg = Args[ 3 ] ;
6435
6437
// If the mask is all zeros or undef, the "passthru" argument is the result.
6436
6438
if (maskIsAllZeroOrUndef (MaskArg))
6437
6439
return PassthruArg;
6438
6440
return nullptr ;
6439
6441
}
6440
6442
case Intrinsic::fshl:
6441
6443
case Intrinsic::fshr: {
6442
- Value *Op0 = Call->getArgOperand (0 ), *Op1 = Call->getArgOperand (1 ),
6443
- *ShAmtArg = Call->getArgOperand (2 );
6444
+ Value *Op0 = Args[0 ], *Op1 = Args[1 ], *ShAmtArg = Args[2 ];
6444
6445
6445
6446
// If both operands are undef, the result is undef.
6446
6447
if (Q.isUndefValue (Op0) && Q.isUndefValue (Op1))
6447
6448
return UndefValue::get (F->getReturnType ());
6448
6449
6449
6450
// If shift amount is undef, assume it is zero.
6450
6451
if (Q.isUndefValue (ShAmtArg))
6451
- return Call-> getArgOperand ( IID == Intrinsic::fshl ? 0 : 1 ) ;
6452
+ return Args[ IID == Intrinsic::fshl ? 0 : 1 ] ;
6452
6453
6453
6454
const APInt *ShAmtC;
6454
6455
if (match (ShAmtArg, m_APInt (ShAmtC))) {
6455
6456
// If there's effectively no shift, return the 1st arg or 2nd arg.
6456
6457
APInt BitWidth = APInt (ShAmtC->getBitWidth (), ShAmtC->getBitWidth ());
6457
6458
if (ShAmtC->urem (BitWidth).isZero ())
6458
- return Call-> getArgOperand ( IID == Intrinsic::fshl ? 0 : 1 ) ;
6459
+ return Args[ IID == Intrinsic::fshl ? 0 : 1 ] ;
6459
6460
}
6460
6461
6461
6462
// Rotating zero by anything is zero.
@@ -6469,31 +6470,24 @@ static Value *simplifyIntrinsic(CallBase *Call, const SimplifyQuery &Q) {
6469
6470
return nullptr ;
6470
6471
}
6471
6472
case Intrinsic::experimental_constrained_fma: {
6472
- Value *Op0 = Call->getArgOperand (0 );
6473
- Value *Op1 = Call->getArgOperand (1 );
6474
- Value *Op2 = Call->getArgOperand (2 );
6475
6473
auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
6476
- if (Value *V =
6477
- simplifyFPOp ({Op0, Op1, Op2}, {}, Q, *FPI->getExceptionBehavior (),
6478
- *FPI->getRoundingMode ()))
6474
+ if (Value *V = simplifyFPOp (Args, {}, Q, *FPI->getExceptionBehavior (),
6475
+ *FPI->getRoundingMode ()))
6479
6476
return V;
6480
6477
return nullptr ;
6481
6478
}
6482
6479
case Intrinsic::fma:
6483
6480
case Intrinsic::fmuladd: {
6484
- Value *Op0 = Call->getArgOperand (0 );
6485
- Value *Op1 = Call->getArgOperand (1 );
6486
- Value *Op2 = Call->getArgOperand (2 );
6487
- if (Value *V = simplifyFPOp ({Op0, Op1, Op2}, {}, Q, fp::ebIgnore,
6481
+ if (Value *V = simplifyFPOp (Args, {}, Q, fp::ebIgnore,
6488
6482
RoundingMode::NearestTiesToEven))
6489
6483
return V;
6490
6484
return nullptr ;
6491
6485
}
6492
6486
case Intrinsic::smul_fix:
6493
6487
case Intrinsic::smul_fix_sat: {
6494
- Value *Op0 = Call-> getArgOperand ( 0 ) ;
6495
- Value *Op1 = Call-> getArgOperand ( 1 ) ;
6496
- Value *Op2 = Call-> getArgOperand ( 2 ) ;
6488
+ Value *Op0 = Args[ 0 ] ;
6489
+ Value *Op1 = Args[ 1 ] ;
6490
+ Value *Op2 = Args[ 2 ] ;
6497
6491
Type *ReturnType = F->getReturnType ();
6498
6492
6499
6493
// Canonicalize constant operand as Op1 (ConstantFolding handles the case
@@ -6520,9 +6514,9 @@ static Value *simplifyIntrinsic(CallBase *Call, const SimplifyQuery &Q) {
6520
6514
return nullptr ;
6521
6515
}
6522
6516
case Intrinsic::vector_insert: {
6523
- Value *Vec = Call-> getArgOperand ( 0 ) ;
6524
- Value *SubVec = Call-> getArgOperand ( 1 ) ;
6525
- Value *Idx = Call-> getArgOperand ( 2 ) ;
6517
+ Value *Vec = Args[ 0 ] ;
6518
+ Value *SubVec = Args[ 1 ] ;
6519
+ Value *Idx = Args[ 2 ] ;
6526
6520
Type *ReturnType = F->getReturnType ();
6527
6521
6528
6522
// (insert_vector Y, (extract_vector X, 0), 0) -> X
@@ -6539,51 +6533,52 @@ static Value *simplifyIntrinsic(CallBase *Call, const SimplifyQuery &Q) {
6539
6533
}
6540
6534
case Intrinsic::experimental_constrained_fadd: {
6541
6535
auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
6542
- return simplifyFAddInst (
6543
- FPI-> getArgOperand ( 0 ), FPI-> getArgOperand ( 1 ), FPI->getFastMathFlags (),
6544
- Q, *FPI-> getExceptionBehavior (), *FPI->getRoundingMode ());
6536
+ return simplifyFAddInst (Args[ 0 ], Args[ 1 ], FPI-> getFastMathFlags (), Q,
6537
+ * FPI->getExceptionBehavior (),
6538
+ *FPI->getRoundingMode ());
6545
6539
}
6546
6540
case Intrinsic::experimental_constrained_fsub: {
6547
6541
auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
6548
- return simplifyFSubInst (
6549
- FPI-> getArgOperand ( 0 ), FPI-> getArgOperand ( 1 ), FPI->getFastMathFlags (),
6550
- Q, *FPI-> getExceptionBehavior (), *FPI->getRoundingMode ());
6542
+ return simplifyFSubInst (Args[ 0 ], Args[ 1 ], FPI-> getFastMathFlags (), Q,
6543
+ * FPI->getExceptionBehavior (),
6544
+ *FPI->getRoundingMode ());
6551
6545
}
6552
6546
case Intrinsic::experimental_constrained_fmul: {
6553
6547
auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
6554
- return simplifyFMulInst (
6555
- FPI-> getArgOperand ( 0 ), FPI-> getArgOperand ( 1 ), FPI->getFastMathFlags (),
6556
- Q, *FPI-> getExceptionBehavior (), *FPI->getRoundingMode ());
6548
+ return simplifyFMulInst (Args[ 0 ], Args[ 1 ], FPI-> getFastMathFlags (), Q,
6549
+ * FPI->getExceptionBehavior (),
6550
+ *FPI->getRoundingMode ());
6557
6551
}
6558
6552
case Intrinsic::experimental_constrained_fdiv: {
6559
6553
auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
6560
- return simplifyFDivInst (
6561
- FPI-> getArgOperand ( 0 ), FPI-> getArgOperand ( 1 ), FPI->getFastMathFlags (),
6562
- Q, *FPI-> getExceptionBehavior (), *FPI->getRoundingMode ());
6554
+ return simplifyFDivInst (Args[ 0 ], Args[ 1 ], FPI-> getFastMathFlags (), Q,
6555
+ * FPI->getExceptionBehavior (),
6556
+ *FPI->getRoundingMode ());
6563
6557
}
6564
6558
case Intrinsic::experimental_constrained_frem: {
6565
6559
auto *FPI = cast<ConstrainedFPIntrinsic>(Call);
6566
- return simplifyFRemInst (
6567
- FPI-> getArgOperand ( 0 ), FPI-> getArgOperand ( 1 ), FPI->getFastMathFlags (),
6568
- Q, *FPI-> getExceptionBehavior (), *FPI->getRoundingMode ());
6560
+ return simplifyFRemInst (Args[ 0 ], Args[ 1 ], FPI-> getFastMathFlags (), Q,
6561
+ * FPI->getExceptionBehavior (),
6562
+ *FPI->getRoundingMode ());
6569
6563
}
6570
6564
default :
6571
6565
return nullptr ;
6572
6566
}
6573
6567
}
6574
6568
6575
- static Value *tryConstantFoldCall (CallBase *Call, const SimplifyQuery &Q) {
6576
- auto *F = dyn_cast<Function>(Call->getCalledOperand ());
6569
+ static Value *tryConstantFoldCall (CallBase *Call, Value *Callee,
6570
+ ArrayRef<Value *> Args,
6571
+ const SimplifyQuery &Q) {
6572
+ auto *F = dyn_cast<Function>(Callee);
6577
6573
if (!F || !canConstantFoldCallTo (Call, F))
6578
6574
return nullptr ;
6579
6575
6580
6576
SmallVector<Constant *, 4 > ConstantArgs;
6581
- unsigned NumArgs = Call->arg_size ();
6582
- ConstantArgs.reserve (NumArgs);
6583
- for (auto &Arg : Call->args ()) {
6584
- Constant *C = dyn_cast<Constant>(&Arg);
6577
+ ConstantArgs.reserve (Args.size ());
6578
+ for (Value *Arg : Args) {
6579
+ Constant *C = dyn_cast<Constant>(Arg);
6585
6580
if (!C) {
6586
- if (isa<MetadataAsValue>(Arg. get () ))
6581
+ if (isa<MetadataAsValue>(Arg))
6587
6582
continue ;
6588
6583
return nullptr ;
6589
6584
}
@@ -6593,34 +6588,38 @@ static Value *tryConstantFoldCall(CallBase *Call, const SimplifyQuery &Q) {
6593
6588
return ConstantFoldCall (Call, F, ConstantArgs, Q.TLI );
6594
6589
}
6595
6590
6596
- Value *llvm::simplifyCall (CallBase *Call, const SimplifyQuery &Q) {
6591
+ Value *llvm::simplifyCall (CallBase *Call, Value *Callee, ArrayRef<Value *> Args,
6592
+ const SimplifyQuery &Q) {
6593
+ // Args should not contain operand bundle operands.
6594
+ assert (Call->arg_size () == Args.size ());
6595
+
6597
6596
// musttail calls can only be simplified if they are also DCEd.
6598
6597
// As we can't guarantee this here, don't simplify them.
6599
6598
if (Call->isMustTailCall ())
6600
6599
return nullptr ;
6601
6600
6602
6601
// call undef -> poison
6603
6602
// call null -> poison
6604
- Value *Callee = Call->getCalledOperand ();
6605
6603
if (isa<UndefValue>(Callee) || isa<ConstantPointerNull>(Callee))
6606
6604
return PoisonValue::get (Call->getType ());
6607
6605
6608
- if (Value *V = tryConstantFoldCall (Call, Q))
6606
+ if (Value *V = tryConstantFoldCall (Call, Callee, Args, Q))
6609
6607
return V;
6610
6608
6611
6609
auto *F = dyn_cast<Function>(Callee);
6612
6610
if (F && F->isIntrinsic ())
6613
- if (Value *Ret = simplifyIntrinsic (Call, Q))
6611
+ if (Value *Ret = simplifyIntrinsic (Call, Callee, Args, Q))
6614
6612
return Ret;
6615
6613
6616
6614
return nullptr ;
6617
6615
}
6618
6616
6619
6617
Value *llvm::simplifyConstrainedFPCall (CallBase *Call, const SimplifyQuery &Q) {
6620
6618
assert (isa<ConstrainedFPIntrinsic>(Call));
6621
- if (Value *V = tryConstantFoldCall (Call, Q))
6619
+ SmallVector<Value *, 4 > Args (Call->args ());
6620
+ if (Value *V = tryConstantFoldCall (Call, Call->getCalledOperand (), Args, Q))
6622
6621
return V;
6623
- if (Value *Ret = simplifyIntrinsic (Call, Q))
6622
+ if (Value *Ret = simplifyIntrinsic (Call, Call-> getCalledOperand (), Args, Q))
6624
6623
return Ret;
6625
6624
return nullptr ;
6626
6625
}
@@ -6775,8 +6774,9 @@ static Value *simplifyInstructionWithOperands(Instruction *I,
6775
6774
case Instruction::PHI:
6776
6775
return simplifyPHINode (cast<PHINode>(I), NewOps, Q);
6777
6776
case Instruction::Call:
6778
- // TODO: Use NewOps
6779
- return simplifyCall (cast<CallInst>(I), Q);
6777
+ return simplifyCall (
6778
+ cast<CallInst>(I), NewOps.back (),
6779
+ NewOps.drop_back (1 + cast<CallInst>(I)->getNumTotalBundleOperands ()), Q);
6780
6780
case Instruction::Freeze:
6781
6781
return llvm::simplifyFreezeInst (NewOps[0 ], Q);
6782
6782
#define HANDLE_CAST_INST (num, opc, clas ) case Instruction::opc:
0 commit comments