summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
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
commite37c2e4d11a4bbd34a7908774a12e4666687d087 (patch)
treebef6bff29f7f2ca569775e295c92dda94d68098c /llvm/lib/Transforms
parent419f7c2345b7a2b553629e909ed29297bdeeb566 (diff)
downloadbcm5719-llvm-e37c2e4d11a4bbd34a7908774a12e4666687d087.tar.gz
bcm5719-llvm-e37c2e4d11a4bbd34a7908774a12e4666687d087.zip
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. llvm-svn: 187249
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 0aa301bc7a8..8d4677b0ec6 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/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))
OpenPOWER on IntegriCloud