summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-11-05 17:26:42 +0000
committerSanjay Patel <spatel@rotateright.com>2018-11-05 17:26:42 +0000
commitc26fd1e77258d2a1ebeff25638636291ac64671a (patch)
treea83e71fd2c85d27a7e54095d1922ca8e8f08b944 /llvm/lib
parentc50240dac133451b3eae5b89cecca4c1c4af9fd4 (diff)
downloadbcm5719-llvm-c26fd1e77258d2a1ebeff25638636291ac64671a.tar.gz
bcm5719-llvm-c26fd1e77258d2a1ebeff25638636291ac64671a.zip
[InstCombine] canonicalize -0.0 to +0.0 in fcmp
As stated in IEEE-754 and discussed in: https://bugs.llvm.org/show_bug.cgi?id=38086 ...the sign of zero does not affect any FP compare predicate. Known regressions were fixed with: rL346097 (D54001) rL346143 The transform will help reduce pattern-matching complexity to solve: https://bugs.llvm.org/show_bug.cgi?id=39475 ...as well as improve CSE and codegen (a zero constant is almost always easier to produce than 0x80..00). llvm-svn: 346147
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 9155ad12598..059f7523ff9 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -5397,6 +5397,13 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
return nullptr;
}
+ // The sign of 0.0 is ignored by fcmp, so canonicalize to +0.0:
+ // fcmp Pred X, -0.0 --> fcmp Pred X, 0.0
+ if (match(Op1, m_AnyZeroFP()) && !match(Op1, m_PosZeroFP())) {
+ I.setOperand(1, ConstantFP::getNullValue(Op1->getType()));
+ return &I;
+ }
+
// Handle fcmp with instruction LHS and constant RHS.
Instruction *LHSI;
Constant *RHSC;
OpenPOWER on IntegriCloud