diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2018-02-12 19:39:21 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2018-02-12 19:39:21 +0000 |
| commit | 4a4f35f32411abb73360247e53d59e1fea1ca7c8 (patch) | |
| tree | 94cff55bc16e12f81486d7a9cca0e4315fcf2c13 /llvm/lib | |
| parent | ee4257f676b81681c38cbb1ef7f3fed0ad6af4ce (diff) | |
| download | bcm5719-llvm-4a4f35f32411abb73360247e53d59e1fea1ca7c8.tar.gz bcm5719-llvm-4a4f35f32411abb73360247e53d59e1fea1ca7c8.zip | |
[InstCombine] X / (X * Y) --> 1.0 / Y
This is similar to the instsimplify fold added with D42385
( rL323716 )
...but this can't be in instsimplify because we're creating/morphing
a different instruction.
llvm-svn: 324927
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index 3cd24035f3d..b1cad6ba009 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -1523,6 +1523,16 @@ Instruction *InstCombiner::visitFDiv(BinaryOperator &I) { return &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. + if (I.hasNoNaNs() && I.hasAllowReassoc() && + match(Op1, m_c_FMul(m_Specific(Op0), m_Value(Y)))) { + I.setOperand(0, ConstantFP::get(I.getType(), 1.0)); + I.setOperand(1, Y); + return &I; + } + return nullptr; } |

