@@ -366,14 +366,14 @@ static Instruction *foldShiftOfShiftedBinOp(BinaryOperator &I,
366
366
367
367
Type *Ty = I.getType ();
368
368
369
- // Find a matching one-use shift by constant. The fold is not valid if the sum
369
+ // Find a matching shift by constant. The fold is not valid if the sum
370
370
// of the shift values equals or exceeds bitwidth.
371
- // TODO: Remove the one-use check if the other logic operand (Y) is constant.
372
371
Value *X, *Y;
373
- auto matchFirstShift = [&](Value *V) {
374
- APInt Threshold (Ty->getScalarSizeInBits (), Ty->getScalarSizeInBits ());
375
- return match (V,
376
- m_OneUse (m_BinOp (ShiftOpcode, m_Value (X), m_Constant (C0)))) &&
372
+ auto matchFirstShift = [&](Value *V, Value *W) {
373
+ unsigned Size = Ty->getScalarSizeInBits ();
374
+ APInt Threshold (Size, Size);
375
+ return match (V, m_BinOp (ShiftOpcode, m_Value (X), m_Constant (C0))) &&
376
+ (V->hasOneUse () || match (W, m_ImmConstant ())) &&
377
377
match (ConstantExpr::getAdd (C0, C1),
378
378
m_SpecificInt_ICMP (ICmpInst::ICMP_ULT, Threshold));
379
379
};
@@ -382,9 +382,9 @@ static Instruction *foldShiftOfShiftedBinOp(BinaryOperator &I,
382
382
// is not so we cannot reoder if we match operand(1) and need to keep the
383
383
// operands in their original positions.
384
384
bool FirstShiftIsOp1 = false ;
385
- if (matchFirstShift (BinInst->getOperand (0 )))
385
+ if (matchFirstShift (BinInst->getOperand (0 ), BinInst-> getOperand ( 1 ) ))
386
386
Y = BinInst->getOperand (1 );
387
- else if (matchFirstShift (BinInst->getOperand (1 ))) {
387
+ else if (matchFirstShift (BinInst->getOperand (1 ), BinInst-> getOperand ( 0 ) )) {
388
388
Y = BinInst->getOperand (0 );
389
389
FirstShiftIsOp1 = BinInst->getOpcode () == Instruction::Sub;
390
390
} else
0 commit comments