diff options
author | Sanjay Patel <spatel@rotateright.com> | 2019-04-15 13:23:38 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2019-04-15 13:23:38 +0000 |
commit | 5e13cd2e61cb187f28d743c15141333530cc1adf (patch) | |
tree | 0c076066762a394b8dc9ddfd8e6435fed8cf4abc /llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | |
parent | 5db281cd4eda2e288b581be20b8ee41316c1a2fd (diff) | |
download | bcm5719-llvm-5e13cd2e61cb187f28d743c15141333530cc1adf.tar.gz bcm5719-llvm-5e13cd2e61cb187f28d743c15141333530cc1adf.zip |
[InstCombine] canonicalize fdiv after fmul if reassociation is allowed
(X / Y) * Z --> (X * Z) / Y
This can allow other optimizations/reassociations as shown in the test diffs.
llvm-svn: 358404
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 7edae55cb3e..a9e3e5f00f6 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -430,6 +430,14 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) { } } + Value *Z; + if (match(&I, m_c_FMul(m_OneUse(m_FDiv(m_Value(X), m_Value(Y))), + m_Value(Z)))) { + // Sink division: (X / Y) * Z --> (X * Z) / Y + Value *NewFMul = Builder.CreateFMulFMF(X, Z, &I); + return BinaryOperator::CreateFDivFMF(NewFMul, Y, &I); + } + // sqrt(X) * sqrt(Y) -> sqrt(X * Y) // nnan disallows the possibility of returning a number if both operands are // negative (in that case, we should return NaN). |