[llvm] r281139 - [InstCombine] rename and reorganize some icmp folding functions; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 10 08:03:45 PDT 2016


Author: spatel
Date: Sat Sep 10 10:03:44 2016
New Revision: 281139

URL: http://llvm.org/viewvc/llvm-project?rev=281139&view=rev
Log:
[InstCombine] rename and reorganize some icmp folding functions; NFC

Everything under foldICmpInstWithConstant() should now be working for
splat vectors via m_APInt matchers. Ie, I've removed all of the FIXMEs
that I added while cleaning that section up. Note that not all of the
associated FIXMEs in the regression tests are gone though, because some
of the tests require earlier folds that are still scalar-only. 

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
    llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=281139&r1=281138&r2=281139&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Sat Sep 10 10:03:44 2016
@@ -2159,8 +2159,9 @@ Instruction *InstCombiner::foldICmpAddCo
   return nullptr;
 }
 
-/// Try to fold integer comparisons with a constant operand: icmp Pred X, C.
-Instruction *InstCombiner::foldICmpWithConstant(ICmpInst &Cmp) {
+/// Try to fold integer comparisons with a constant operand: icmp Pred X, C
+/// where X is some kind of instruction.
+Instruction *InstCombiner::foldICmpInstWithConstant(ICmpInst &Cmp) {
   const APInt *C;
   if (!match(Cmp.getOperand(1), m_APInt(C)))
     return nullptr;
@@ -2212,6 +2213,9 @@ Instruction *InstCombiner::foldICmpWithC
     default:
       break;
     }
+    // TODO: These folds could be refactored to be part of the above calls.
+    if (Instruction *I = foldICmpBinOpEqualityWithConstant(Cmp, BO, C))
+      return I;
   }
 
   Instruction *LHSI;
@@ -2220,18 +2224,19 @@ Instruction *InstCombiner::foldICmpWithC
     if (Instruction *I = foldICmpTruncConstant(Cmp, LHSI, C))
       return I;
 
+  if (Instruction *I = foldICmpIntrinsicWithConstant(Cmp, C))
+    return I;
+
   return nullptr;
 }
 
 /// Simplify icmp_eq and icmp_ne instructions with binary operator LHS and
-/// integer constant RHS.
-Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
-  BinaryOperator *BO;
-  const APInt *RHSV;
+/// integer scalar or splat vector constant RHS.
+Instruction *InstCombiner::foldICmpBinOpEqualityWithConstant(
+    ICmpInst &ICI, BinaryOperator *BO, const APInt *RHSV) {
   // FIXME: Some of these folds could work with arbitrary constants, but this
   // match is limited to scalars and vector splat constants.
-  if (!ICI.isEquality() || !match(ICI.getOperand(0), m_BinOp(BO)) ||
-      !match(ICI.getOperand(1), m_APInt(RHSV)))
+  if (!ICI.isEquality())
     return nullptr;
 
   Constant *RHS = cast<Constant>(ICI.getOperand(1));
@@ -2367,10 +2372,10 @@ Instruction *InstCombiner::foldICmpEqual
   return nullptr;
 }
 
-Instruction *InstCombiner::foldICmpIntrinsicWithConstant(ICmpInst &ICI) {
+Instruction *InstCombiner::foldICmpIntrinsicWithConstant(ICmpInst &ICI,
+                                                         const APInt *Op1C) {
   IntrinsicInst *II = dyn_cast<IntrinsicInst>(ICI.getOperand(0));
-  const APInt *Op1C;
-  if (!II || !ICI.isEquality() || !match(ICI.getOperand(1), m_APInt(Op1C)))
+  if (!II || !ICI.isEquality())
     return nullptr;
 
   // Handle icmp {eq|ne} <intrinsic>, intcst.
@@ -3665,16 +3670,7 @@ Instruction *InstCombiner::visitICmpInst
           (SI->getOperand(2) == Op0 && SI->getOperand(1) == Op1))
         return nullptr;
 
-  // See if we are doing a comparison between a constant and an instruction that
-  // can be folded into the comparison.
-
-  if (Instruction *Res = foldICmpWithConstant(I))
-    return Res;
-
-  if (Instruction *Res = foldICmpEqualityWithConstant(I))
-    return Res;
-
-  if (Instruction *Res = foldICmpIntrinsicWithConstant(I))
+  if (Instruction *Res = foldICmpInstWithConstant(I))
     return Res;
 
   // Handle icmp with constant (but not simple integer constant) RHS

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h?rev=281139&r1=281138&r2=281139&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h Sat Sep 10 10:03:44 2016
@@ -555,7 +555,8 @@ private:
   Instruction *foldICmpAddOpConst(Instruction &ICI, Value *X, ConstantInt *CI,
                                   ICmpInst::Predicate Pred);
   Instruction *foldICmpWithCastAndCast(ICmpInst &ICI);
-  Instruction *foldICmpWithConstant(ICmpInst &Cmp);
+
+  Instruction *foldICmpInstWithConstant(ICmpInst &Cmp);
 
   Instruction *foldICmpTruncConstant(ICmpInst &Cmp, Instruction *Trunc,
                                      const APInt *C);
@@ -584,8 +585,10 @@ private:
   Instruction *foldICmpAndShift(ICmpInst &Cmp, BinaryOperator *And,
                                 const APInt *C1, const APInt *C2);
 
-  Instruction *foldICmpEqualityWithConstant(ICmpInst &ICI);
-  Instruction *foldICmpIntrinsicWithConstant(ICmpInst &ICI);
+  Instruction *foldICmpBinOpEqualityWithConstant(ICmpInst &Cmp,
+                                                 BinaryOperator *BO,
+                                                 const APInt *C);
+  Instruction *foldICmpIntrinsicWithConstant(ICmpInst &ICI, const APInt *C);
 
   Instruction *OptAndOp(Instruction *Op, ConstantInt *OpRHS,
                         ConstantInt *AndRHS, BinaryOperator &TheAnd);




More information about the llvm-commits mailing list