[llvm] [InstCombine] Remove one-time check if other logic operand (Y) is constant (PR #77973)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 12 12:31:07 PST 2024


================
@@ -368,10 +368,14 @@ static Instruction *foldShiftOfShiftedBinOp(BinaryOperator &I,
 
   // Find a matching one-use shift by constant. The fold is not valid if the sum
   // of the shift values equals or exceeds bitwidth.
-  // TODO: Remove the one-use check if the other logic operand (Y) is constant.
   Value *X, *Y;
-  auto matchFirstShift = [&](Value *V) {
+  auto matchFirstShift = [&](Value *V, Value *W) {
     APInt Threshold(Ty->getScalarSizeInBits(), Ty->getScalarSizeInBits());
+    if (isa<Constant>(W)) {
+      return match(V, (m_BinOp(ShiftOpcode, m_Value(X), m_Constant(C0)))) &&
+             match(ConstantExpr::getAdd(C0, C1),
+                   m_SpecificInt_ICMP(ICmpInst::ICMP_ULT, Threshold));
+    }
----------------
nikic wrote:

Replace the `m_OneUse` with something like `(isa<Constant>(W) || V->hasOneUse())` instead of duplicating the code. Also better replace `isa<Constant>(W)` with `match(W, m_ImmConstant())`.

https://github.com/llvm/llvm-project/pull/77973


More information about the llvm-commits mailing list