[llvm] 8689463 - [InstCombine] make pattern matching more consistent; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 2 13:02:11 PDT 2022


Author: Sanjay Patel
Date: 2022-06-02T16:01:23-04:00
New Revision: 8689463bfb013af5c0e6d01b80f4582f7d269a08

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

LOG: [InstCombine] make pattern matching more consistent; NFC

We could go either way on this and several similar matches.
Just matching as a binop is possibly slightly more efficient;
we don't need to re-confirm the opcode of the instruction.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index da31d6260c88b..54acfe04e308a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -384,7 +384,7 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
   // TODO: We are not checking one-use because the elimination of the multiply
   //       is better for analysis?
   const APInt *C;
-  if (match(&I, m_c_Mul(m_LShr(m_Value(X), m_APInt(C)), m_Value(Y))) &&
+  if (match(&I, m_c_BinOp(m_LShr(m_Value(X), m_APInt(C)), m_Value(Y))) &&
       *C == C->getBitWidth() - 1) {
     Value *IsNeg = Builder.CreateIsNeg(X, "isneg");
     return SelectInst::Create(IsNeg, Y, ConstantInt::getNullValue(Ty));
@@ -393,9 +393,9 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
   // ((ashr X, 31) | 1) * X --> abs(X)
   // X * ((ashr X, 31) | 1) --> abs(X)
   if (match(&I, m_c_BinOp(m_Or(m_AShr(m_Value(X),
-                                    m_SpecificIntAllowUndef(BitWidth - 1)),
-                             m_One()),
-                        m_Deferred(X)))) {
+                                      m_SpecificIntAllowUndef(BitWidth - 1)),
+                               m_One()),
+                          m_Deferred(X)))) {
     Value *Abs = Builder.CreateBinaryIntrinsic(
         Intrinsic::abs, X,
         ConstantInt::getBool(I.getContext(), I.hasNoSignedWrap()));


        


More information about the llvm-commits mailing list