[llvm] r315703 - [InstCombine] rearrange code to remove repeated constant check; NFCI
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 13 09:43:58 PDT 2017
Author: spatel
Date: Fri Oct 13 09:43:58 2017
New Revision: 315703
URL: http://llvm.org/viewvc/llvm-project?rev=315703&view=rev
Log:
[InstCombine] rearrange code to remove repeated constant check; NFCI
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp?rev=315703&r1=315702&r2=315703&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Fri Oct 13 09:43:58 2017
@@ -950,13 +950,15 @@ static Value *checkForNegativeOperand(Bi
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(Bina
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(Bina
}
}
- if (isa<Constant>(RHS))
- if (Instruction *NV = foldOpWithConstantIntoOperand(I))
- return NV;
-
if (I.getType()->isIntOrIntVectorTy(1))
return BinaryOperator::CreateXor(LHS, RHS);
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h?rev=315703&r1=315702&r2=315703&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h Fri Oct 13 09:43:58 2017
@@ -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);
More information about the llvm-commits
mailing list