aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2013-07-26 21:40:29 +0000
committerOwen Anderson <resistor@mac.com>2013-07-26 21:40:29 +0000
commit0c326f07ca713fa00d0dcba8ec9b61e91298f690 (patch)
tree7799e51b91aa712aa13e7cb0a34e2730ad69dec1 /lib
parentd063a326b2567c3ca759f069e7680979036b9d5e (diff)
downloadexternal_llvm-0c326f07ca713fa00d0dcba8ec9b61e91298f690.zip
external_llvm-0c326f07ca713fa00d0dcba8ec9b61e91298f690.tar.gz
external_llvm-0c326f07ca713fa00d0dcba8ec9b61e91298f690.tar.bz2
When InstCombine tries to fold away (fsub x, (fneg y)) into (fadd x, y), it is
also worthwhile for it to look through FP extensions and truncations, whose application commutes with fneg. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187249 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/InstCombine/InstCombineAddSub.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 0aa301b..8d4677b 100644
--- a/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1528,9 +1528,21 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) {
if (Instruction *NV = FoldOpIntoSelect(I, SI))
return NV;
- // If this is a 'B = x-(-A)', change to B = x+A...
+ // If this is a 'B = x-(-A)', change to B = x+A, potentially looking
+ // through FP extensions/truncations along the way.
if (Value *V = dyn_castFNegVal(Op1))
return BinaryOperator::CreateFAdd(Op0, V);
+ if (FPTruncInst *FPTI = dyn_cast<FPTruncInst>(Op1)) {
+ if (Value *V = dyn_castFNegVal(FPTI->getOperand(0))) {
+ Value *NewTrunc = Builder->CreateFPTrunc(V, I.getType());
+ return BinaryOperator::CreateFAdd(Op0, NewTrunc);
+ }
+ } else if (FPExtInst *FPEI = dyn_cast<FPExtInst>(Op1)) {
+ if (Value *V = dyn_castFNegVal(FPEI->getOperand(0))) {
+ Value *NewTrunc = Builder->CreateFPExt(V, I.getType());
+ return BinaryOperator::CreateFAdd(Op0, NewTrunc);
+ }
+ }
if (I.hasUnsafeAlgebra()) {
if (Value *V = FAddCombine(Builder).simplify(&I))