Skip to content

Commit 265db14

Browse files
committed
[Transforms] Remove one-time check if other logic operand (Y) is constant
By using isa<Constant>(W), we do not need to worry about one-time use anymore.
1 parent 1048b59 commit 265db14

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,14 @@ 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());
374+
if (isa<Constant>(W)) {
375+
return match(V, (m_BinOp(ShiftOpcode, m_Value(X), m_Constant(C0)))) &&
376+
match(ConstantExpr::getAdd(C0, C1),
377+
m_SpecificInt_ICMP(ICmpInst::ICMP_ULT, Threshold));
378+
}
375379
return match(V,
376380
m_OneUse(m_BinOp(ShiftOpcode, m_Value(X), m_Constant(C0)))) &&
377381
match(ConstantExpr::getAdd(C0, C1),
@@ -382,9 +386,9 @@ static Instruction *foldShiftOfShiftedBinOp(BinaryOperator &I,
382386
// is not so we cannot reoder if we match operand(1) and need to keep the
383387
// operands in their original positions.
384388
bool FirstShiftIsOp1 = false;
385-
if (matchFirstShift(BinInst->getOperand(0)))
389+
if (matchFirstShift(BinInst->getOperand(0), BinInst->getOperand(1)))
386390
Y = BinInst->getOperand(1);
387-
else if (matchFirstShift(BinInst->getOperand(1))) {
391+
else if (matchFirstShift(BinInst->getOperand(1), BinInst->getOperand(0))) {
388392
Y = BinInst->getOperand(0);
389393
FirstShiftIsOp1 = BinInst->getOpcode() == Instruction::Sub;
390394
} else

0 commit comments

Comments
 (0)