summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2019-07-26 19:56:59 +0000
committerSanjay Patel <spatel@rotateright.com>2019-07-26 19:56:59 +0000
commita9ab31558caa28e9619647678e9118fde737abde (patch)
treef9a0e829215677be9592debf1f65920cc0b220ef /llvm/lib/Transforms
parent487e95777593e264c26b35377b53c703fd535ef3 (diff)
downloadbcm5719-llvm-a9ab31558caa28e9619647678e9118fde737abde.tar.gz
bcm5719-llvm-a9ab31558caa28e9619647678e9118fde737abde.zip
[InstCombine] canonicalize negated operand of fdiv
This is a transform that we use with fmul, so use it for fdiv too for consistency. llvm-svn: 367146
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index cc753ce0531..30861bfe6c5 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -1234,6 +1234,16 @@ Instruction *InstCombiner::visitFDiv(BinaryOperator &I) {
return &I;
}
+ // Sink negation: -X / Y --> -(X / Y)
+ // But don't transform constant expressions because there's an inverse fold.
+ if (match(Op0, m_OneUse(m_FNeg(m_Value(X)))) && !isa<ConstantExpr>(Op0))
+ return BinaryOperator::CreateFNegFMF(Builder.CreateFDivFMF(X, Op1, &I), &I);
+
+ // Sink negation: Y / -X --> -(Y / X)
+ // But don't transform constant expressions because there's an inverse fold.
+ if (match(Op1, m_OneUse(m_FNeg(m_Value(X)))) && !isa<ConstantExpr>(Op1))
+ return BinaryOperator::CreateFNegFMF(Builder.CreateFDivFMF(Op0, X, &I), &I);
+
// X / (X * Y) --> 1.0 / Y
// Reassociate to (X / X -> 1.0) is legal when NaNs are not allowed.
// We can ignore the possibility that X is infinity because INF/INF is NaN.
OpenPOWER on IntegriCloud