summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-04-06 17:24:08 +0000
committerSanjay Patel <spatel@rotateright.com>2018-04-06 17:24:08 +0000
commita9ca709011d0621afa54fee11de39502db4b261b (patch)
tree80ebb921be9e1373c86f38640e16fb3d42d51fcc /llvm/lib
parente0c2c49a15fb9e1f5a424c9269ab820038c480eb (diff)
downloadbcm5719-llvm-a9ca709011d0621afa54fee11de39502db4b261b.tar.gz
bcm5719-llvm-a9ca709011d0621afa54fee11de39502db4b261b.zip
[InstCombine] limit nsz: -(X - Y) --> Y - X to hasOneUse()
As noted in the post-commit discussion for r329350, we shouldn't generally assume that fsub is the same cost as fneg. llvm-svn: 329429
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index fac3ea86359..5efdc546472 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1698,21 +1698,18 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) {
SQ.getWithInstruction(&I)))
return replaceInstUsesWith(I, V);
- Value *X, *Y;
- if (I.hasNoSignedZeros()) {
- // Subtraction from -0.0 is the canonical form of fneg.
- // fsub nsz 0, X ==> fsub nsz -0.0, X
- if (match(Op0, m_PosZeroFP()))
- return BinaryOperator::CreateFNegFMF(Op1, &I);
-
- // With no-signed-zeros: -(X - Y) --> Y - X
- if (match(Op0, m_NegZeroFP()) && match(Op1, m_FSub(m_Value(X), m_Value(Y))))
- return BinaryOperator::CreateFSubFMF(Y, X, &I);
- }
+ // Subtraction from -0.0 is the canonical form of fneg.
+ // fsub nsz 0, X ==> fsub nsz -0.0, X
+ if (I.hasNoSignedZeros() && match(Op0, m_PosZeroFP()))
+ return BinaryOperator::CreateFNegFMF(Op1, &I);
- // More generally than above, if Op0 is not -0.0: Z - (X - Y) --> Z + (Y - X)
+ // If Op0 is not -0.0 or we can ignore -0.0: Z - (X - Y) --> Z + (Y - X)
// Canonicalize to fadd to make analysis easier.
// This can also help codegen because fadd is commutative.
+ // Note that if this fsub was really an fneg, the fadd with -0.0 will get
+ // killed later. We still limit that particular transform with 'hasOneUse'
+ // because an fneg is assumed better/cheaper than a generic fsub.
+ Value *X, *Y;
if (I.hasNoSignedZeros() || CannotBeNegativeZero(Op0, SQ.TLI)) {
if (match(Op1, m_OneUse(m_FSub(m_Value(X), m_Value(Y))))) {
Value *NewSub = Builder.CreateFSubFMF(Y, X, &I);
OpenPOWER on IntegriCloud