summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2014-12-31 22:14:05 +0000
committerSanjay Patel <spatel@rotateright.com>2014-12-31 22:14:05 +0000
commite68f71574f9c61f72d1aca2811d85da9e4bc0a69 (patch)
tree542273ea5e87168e9ec96a46f80efb3c267b688c /llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
parent0dfd2400688266e688c00b62b38491d4a297c20c (diff)
downloadbcm5719-llvm-e68f71574f9c61f72d1aca2811d85da9e4bc0a69.tar.gz
bcm5719-llvm-e68f71574f9c61f72d1aca2811d85da9e4bc0a69.zip
InstCombine: fsub nsz 0, X ==> fsub nsz -0.0, X
Some day the backend may handle instruction-level fast math flags and make this transform unnecessary, but it's still better practice to use the canonical representation of fneg when possible (use a -0.0). This is a partial fix for PR20870 ( http://llvm.org/bugs/show_bug.cgi?id=20870 ). See also http://reviews.llvm.org/D6723. Differential Revision: http://reviews.llvm.org/D6731 llvm-svn: 225050
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 9ea4bc57cf2..7e6ead4190c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1713,6 +1713,14 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) {
TLI, DT, AT))
return ReplaceInstUsesWith(I, V);
+ // fsub nsz 0, X ==> fsub nsz -0.0, X
+ if (I.getFastMathFlags().noSignedZeros() && match(Op0, m_Zero())) {
+ // Subtraction from -0.0 is the canonical form of fneg.
+ Instruction *NewI = BinaryOperator::CreateFNeg(Op1);
+ NewI->copyFastMathFlags(&I);
+ return NewI;
+ }
+
if (isa<Constant>(Op0))
if (SelectInst *SI = dyn_cast<SelectInst>(Op1))
if (Instruction *NV = FoldOpIntoSelect(I, SI))
OpenPOWER on IntegriCloud