diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-02-28 16:36:24 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-02-28 16:36:24 +0000 |
commit | 8fdd87f9292cdd2419f3f10b3d8c12bcef5aee36 (patch) | |
tree | dafbee07e9bc079dbfa4edae6714340f5d91a7e1 /llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | |
parent | 9de940b93bdbb0cf032b8337c5390630ba5e1acd (diff) | |
download | bcm5719-llvm-8fdd87f9292cdd2419f3f10b3d8c12bcef5aee36.tar.gz bcm5719-llvm-8fdd87f9292cdd2419f3f10b3d8c12bcef5aee36.zip |
[InstCombine] move constant check into foldBinOpIntoSelectOrPhi; NFCI
Also, rename 'foldOpWithConstantIntoOperand' because that's annoyingly
vague. The constant check is redundant in some cases, but it allows
removing duplication for most of the calls.
llvm-svn: 326329
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 815af57fc7a..bd319ef83df 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -251,22 +251,20 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { } } + if (Instruction *FoldedMul = foldBinOpIntoSelectOrPhi(I)) + return FoldedMul; + // Simplify mul instructions with a constant RHS. if (isa<Constant>(Op1)) { - if (Instruction *FoldedMul = foldOpWithConstantIntoOperand(I)) - return FoldedMul; - // Canonicalize (X+C1)*CI -> X*CI+C1*CI. - { - Value *X; - Constant *C1; - if (match(Op0, m_OneUse(m_Add(m_Value(X), m_Constant(C1))))) { - Value *Mul = Builder.CreateMul(C1, Op1); - // Only go forward with the transform if C1*CI simplifies to a tidier - // constant. - if (!match(Mul, m_Mul(m_Value(), m_Value()))) - return BinaryOperator::CreateAdd(Builder.CreateMul(X, Op1), Mul); - } + Value *X; + Constant *C1; + if (match(Op0, m_OneUse(m_Add(m_Value(X), m_Constant(C1))))) { + Value *Mul = Builder.CreateMul(C1, Op1); + // Only go forward with the transform if C1*CI simplifies to a tidier + // constant. + if (!match(Mul, m_Mul(m_Value(), m_Value()))) + return BinaryOperator::CreateAdd(Builder.CreateMul(X, Op1), Mul); } } @@ -555,11 +553,11 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) { bool AllowReassociate = I.isFast(); + if (Instruction *FoldedMul = foldBinOpIntoSelectOrPhi(I)) + return FoldedMul; + // Simplify mul instructions with a constant RHS. if (auto *C = dyn_cast<Constant>(Op1)) { - if (Instruction *FoldedMul = foldOpWithConstantIntoOperand(I)) - return FoldedMul; - // -X * C --> X * -C Value *X; if (match(Op0, m_FNeg(m_Value(X)))) @@ -900,7 +898,7 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) { } if (!C2->isNullValue()) // avoid X udiv 0 - if (Instruction *FoldedDiv = foldOpWithConstantIntoOperand(I)) + if (Instruction *FoldedDiv = foldBinOpIntoSelectOrPhi(I)) return FoldedDiv; } |