diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-03-30 15:42:35 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-03-30 15:42:35 +0000 |
commit | 8564e0de96d18eba9d8501611591c7c3ef9d8be3 (patch) | |
tree | bf347579cd0f6b821d744a0d2e8bb38c2ec25bf5 /llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | |
parent | 03fd67260905170cb1dabe09089c2afc51af4510 (diff) | |
download | bcm5719-llvm-8564e0de96d18eba9d8501611591c7c3ef9d8be3.tar.gz bcm5719-llvm-8564e0de96d18eba9d8501611591c7c3ef9d8be3.zip |
InstCombine: If the divisor of an fdiv has an exact inverse, turn it into an fmul.
Fixes PR9587.
llvm-svn: 128546
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp index d1a1fd6ddfa..66513874815 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -452,6 +452,18 @@ Instruction *InstCombiner::visitFDiv(BinaryOperator &I) { if (Value *V = SimplifyFDivInst(Op0, Op1, TD)) return ReplaceInstUsesWith(I, V); + if (ConstantFP *Op1C = dyn_cast<ConstantFP>(Op1)) { + const APFloat &Op1F = Op1C->getValueAPF(); + + // If the divisor has an exact multiplicative inverse we can turn the fdiv + // into a cheaper fmul. + APFloat Reciprocal(Op1F.getSemantics()); + if (Op1F.getExactInverse(&Reciprocal)) { + ConstantFP *RFP = ConstantFP::get(Builder->getContext(), Reciprocal); + return BinaryOperator::CreateFMul(Op0, RFP); + } + } + return 0; } |