Skip to content

Commit 10b2f49

Browse files
committed
[Transforms] Remove one-time check if other logic operand (Y) is constant
By using match(W, m_ImmConstant()), we do not need to worry about one-time use anymore.
1 parent 3dc7294 commit 10b2f49

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,11 @@ static Instruction *foldShiftOfShiftedBinOp(BinaryOperator &I,
368368

369369
// Find a matching one-use shift by constant. The fold is not valid if the sum
370370
// of the shift values equals or exceeds bitwidth.
371-
// TODO: Remove the one-use check if the other logic operand (Y) is constant.
372371
Value *X, *Y;
373-
auto matchFirstShift = [&](Value *V) {
372+
auto matchFirstShift = [&](Value *V, Value *W) {
374373
APInt Threshold(Ty->getScalarSizeInBits(), Ty->getScalarSizeInBits());
375-
return match(V,
376-
m_OneUse(m_BinOp(ShiftOpcode, m_Value(X), m_Constant(C0)))) &&
374+
return match(V, m_BinOp(ShiftOpcode, m_Value(X), m_Constant(C0))) &&
375+
(V->hasOneUse() || match(W, m_ImmConstant())) &&
377376
match(ConstantExpr::getAdd(C0, C1),
378377
m_SpecificInt_ICMP(ICmpInst::ICMP_ULT, Threshold));
379378
};
@@ -382,9 +381,9 @@ static Instruction *foldShiftOfShiftedBinOp(BinaryOperator &I,
382381
// is not so we cannot reoder if we match operand(1) and need to keep the
383382
// operands in their original positions.
384383
bool FirstShiftIsOp1 = false;
385-
if (matchFirstShift(BinInst->getOperand(0)))
384+
if (matchFirstShift(BinInst->getOperand(0), BinInst->getOperand(1)))
386385
Y = BinInst->getOperand(1);
387-
else if (matchFirstShift(BinInst->getOperand(1))) {
386+
else if (matchFirstShift(BinInst->getOperand(1), BinInst->getOperand(0))) {
388387
Y = BinInst->getOperand(0);
389388
FirstShiftIsOp1 = BinInst->getOpcode() == Instruction::Sub;
390389
} else

0 commit comments

Comments
 (0)