summaryrefslogtreecommitdiff
path: root/lib/Transforms/InstCombine
diff options
context:
space:
mode:
authorStephen Lin <stephenwlin@gmail.com>2013-07-20 07:13:13 +0000
committerStephen Lin <stephenwlin@gmail.com>2013-07-20 07:13:13 +0000
commita98ce503b958821fd2530aad585c21e730695a9e (patch)
tree79e6abda82bb990e8dab9dfbcb19c0c9da3cb8d8 /lib/Transforms/InstCombine
parentff29d235ed70d8d7aa03b2d9f9665d2b85f0e195 (diff)
downloadllvm-a98ce503b958821fd2530aad585c21e730695a9e.tar.gz
llvm-a98ce503b958821fd2530aad585c21e730695a9e.tar.bz2
llvm-a98ce503b958821fd2530aad585c21e730695a9e.tar.xz
InstCombine: call FoldOpIntoSelect for all floating binops, not just fmul
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186759 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine')
-rw-r--r--lib/Transforms/InstCombine/InstCombineAddSub.cpp17
-rw-r--r--lib/Transforms/InstCombine/InstCombineMulDivRem.cpp9
2 files changed, 23 insertions, 3 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index fecbd5c301..0aa301bc7a 100644
--- a/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1186,9 +1186,15 @@ Instruction *InstCombiner::visitFAdd(BinaryOperator &I) {
if (Value *V = SimplifyFAddInst(LHS, RHS, I.getFastMathFlags(), TD))
return ReplaceInstUsesWith(I, V);
- if (isa<Constant>(RHS) && isa<PHINode>(LHS))
- if (Instruction *NV = FoldOpIntoPhi(I))
- return NV;
+ if (isa<Constant>(RHS)) {
+ if (isa<PHINode>(LHS))
+ if (Instruction *NV = FoldOpIntoPhi(I))
+ return NV;
+
+ if (SelectInst *SI = dyn_cast<SelectInst>(LHS))
+ if (Instruction *NV = FoldOpIntoSelect(I, SI))
+ return NV;
+ }
// -A + B --> B - A
// -A + -B --> -(A + B)
@@ -1517,6 +1523,11 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) {
if (Value *V = SimplifyFSubInst(Op0, Op1, I.getFastMathFlags(), TD))
return ReplaceInstUsesWith(I, V);
+ if (isa<Constant>(Op0))
+ if (SelectInst *SI = dyn_cast<SelectInst>(Op1))
+ if (Instruction *NV = FoldOpIntoSelect(I, SI))
+ return NV;
+
// If this is a 'B = x-(-A)', change to B = x+A...
if (Value *V = dyn_castFNegVal(Op1))
return BinaryOperator::CreateFAdd(Op0, V);
diff --git a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index c3621af638..780e0eb0dc 100644
--- a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -990,10 +990,19 @@ Instruction *InstCombiner::visitFDiv(BinaryOperator &I) {
if (Value *V = SimplifyFDivInst(Op0, Op1, TD))
return ReplaceInstUsesWith(I, V);
+ if (isa<Constant>(Op0))
+ if (SelectInst *SI = dyn_cast<SelectInst>(Op1))
+ if (Instruction *R = FoldOpIntoSelect(I, SI))
+ return R;
+
bool AllowReassociate = I.hasUnsafeAlgebra();
bool AllowReciprocal = I.hasAllowReciprocal();
if (ConstantFP *Op1C = dyn_cast<ConstantFP>(Op1)) {
+ if (SelectInst *SI = dyn_cast<SelectInst>(Op0))
+ if (Instruction *R = FoldOpIntoSelect(I, SI))
+ return R;
+
if (AllowReassociate) {
ConstantFP *C1 = 0;
ConstantFP *C2 = Op1C;