[llvm] c2ab7e2 - [InstCombine] simplify code for matching shift-logic-shift pattern; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 18 05:13:44 PST 2023


Author: Sanjay Patel
Date: 2023-01-18T08:13:37-05:00
New Revision: c2ab7e2abd834d4ef7b0f27709d9f7fce3140eb3

URL: https://github.com/llvm/llvm-project/commit/c2ab7e2abd834d4ef7b0f27709d9f7fce3140eb3
DIFF: https://github.com/llvm/llvm-project/commit/c2ab7e2abd834d4ef7b0f27709d9f7fce3140eb3.diff

LOG: [InstCombine] simplify code for matching shift-logic-shift pattern; NFC

We can match and capture in one statement. Also, make the
code more closely resemble the description comment by using
the constant name of an operand value.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index d8c66f9a87fad..ec505381cc868 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -346,8 +346,8 @@ static Instruction *foldShiftOfShiftedLogic(BinaryOperator &I,
   Value *X, *Y;
   auto matchFirstShift = [&](Value *V) {
     APInt Threshold(Ty->getScalarSizeInBits(), Ty->getScalarSizeInBits());
-    return match(V, m_BinOp(ShiftOpcode, m_Value(), m_Value())) &&
-           match(V, m_OneUse(m_Shift(m_Value(X), m_Constant(C0)))) &&
+    return match(V,
+                 m_OneUse(m_BinOp(ShiftOpcode, m_Value(X), m_Constant(C0)))) &&
            match(ConstantExpr::getAdd(C0, C1),
                  m_SpecificInt_ICMP(ICmpInst::ICMP_ULT, Threshold));
   };
@@ -363,7 +363,7 @@ static Instruction *foldShiftOfShiftedLogic(BinaryOperator &I,
   // shift (logic (shift X, C0), Y), C1 -> logic (shift X, C0+C1), (shift Y, C1)
   Constant *ShiftSumC = ConstantExpr::getAdd(C0, C1);
   Value *NewShift1 = Builder.CreateBinOp(ShiftOpcode, X, ShiftSumC);
-  Value *NewShift2 = Builder.CreateBinOp(ShiftOpcode, Y, I.getOperand(1));
+  Value *NewShift2 = Builder.CreateBinOp(ShiftOpcode, Y, C1);
   return BinaryOperator::Create(LogicInst->getOpcode(), NewShift1, NewShift2);
 }
 


        


More information about the llvm-commits mailing list