]> granicus.if.org Git - llvm/commitdiff
[InstCombine] rearrange code to remove repeated constant check; NFCI
authorSanjay Patel <spatel@rotateright.com>
Fri, 13 Oct 2017 16:43:58 +0000 (16:43 +0000)
committerSanjay Patel <spatel@rotateright.com>
Fri, 13 Oct 2017 16:43:58 +0000 (16:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315703 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineAddSub.cpp
lib/Transforms/InstCombine/InstCombineInternal.h

index e12bff01376d009ec1e79605b776dc96f04338cf..75cc683b7a657fb4524a7662037a98c3b47f8c65 100644 (file)
@@ -950,13 +950,15 @@ static Value *checkForNegativeOperand(BinaryOperator &I,
   return nullptr;
 }
 
-static Instruction *foldAddWithConstant(BinaryOperator &Add,
-                                        InstCombiner::BuilderTy &Builder) {
+Instruction *InstCombiner::foldAddWithConstant(BinaryOperator &Add) {
   Value *Op0 = Add.getOperand(0), *Op1 = Add.getOperand(1);
   Constant *Op1C;
   if (!match(Op1, m_Constant(Op1C)))
     return nullptr;
 
+  if (Instruction *NV = foldOpWithConstantIntoOperand(Add))
+    return NV;
+
   Value *X;
   Type *Ty = Add.getType();
   if (match(Op0, m_ZExt(m_Value(X))) &&
@@ -1037,7 +1039,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
   if (Value *V = SimplifyUsingDistributiveLaws(I))
     return replaceInstUsesWith(I, V);
 
-  if (Instruction *X = foldAddWithConstant(I, Builder))
+  if (Instruction *X = foldAddWithConstant(I))
     return X;
 
   // FIXME: This should be moved into the above helper function to allow these
@@ -1085,10 +1087,6 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
     }
   }
 
-  if (isa<Constant>(RHS))
-    if (Instruction *NV = foldOpWithConstantIntoOperand(I))
-      return NV;
-
   if (I.getType()->isIntOrIntVectorTy(1))
     return BinaryOperator::CreateXor(LHS, RHS);
 
index f1404facaf33ebf99de9a045f00d590b8cd34f1b..88ce4de31df06e7d3dbb550dab0ec3d9a09523b8 100644 (file)
@@ -663,6 +663,8 @@ private:
   /// This is a convenience wrapper function for the above two functions.
   Instruction *foldOpWithConstantIntoOperand(BinaryOperator &I);
 
+  Instruction *foldAddWithConstant(BinaryOperator &Add);
+
   /// \brief Try to rotate an operation below a PHI node, using PHI nodes for
   /// its operands.
   Instruction *FoldPHIArgOpIntoPHI(PHINode &PN);