diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2015-06-14 18:53:58 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2015-06-14 18:53:58 +0000 |
| commit | 4f0524614e664c56cc4a516439022af87c543247 (patch) | |
| tree | 6807f172ea6ce1cf895be79114b14b0d46643470 /llvm/lib | |
| parent | 5e49697138f0015d80939318cfe2b46bebeeccf0 (diff) | |
| download | bcm5719-llvm-4f0524614e664c56cc4a516439022af87c543247.tar.gz bcm5719-llvm-4f0524614e664c56cc4a516439022af87c543247.zip | |
[InstSimplify] Add self-fdiv identities for -ffinite-math-only.
When NaNs and Infs are ignored we can fold
X / X -> 1.0
-X / X -> -1.0
X / -X -> -1.0
llvm-svn: 239701
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index ec56d888dc2..5e3b415a2a6 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1126,6 +1126,21 @@ static Value *SimplifyFDivInst(Value *Op0, Value *Op1, FastMathFlags FMF, if (FMF.noNaNs() && FMF.noSignedZeros() && match(Op0, m_AnyZero())) return Op0; + if (FMF.noNaNs() && FMF.noInfs()) { + // X / X -> 1.0 iff NaNs and infinities are ignored. + if (Op0 == Op1) + return ConstantFP::get(Op0->getType(), 1.0); + + // -X / X -> -1.0 and + // X / -X -> -1.0 iff NaNs and infinities are ignored. + // We can ignore signed zeros because +-0.0/+-0.0 is NaN and ignored. + if ((BinaryOperator::isFNeg(Op0, /*IgnoreZeroSign=*/true) && + BinaryOperator::getFNegArgument(Op0) == Op1) || + (BinaryOperator::isFNeg(Op1, /*IgnoreZeroSign=*/true) && + BinaryOperator::getFNegArgument(Op1) == Op0)) + return ConstantFP::get(Op0->getType(), -1.0); + } + return nullptr; } |

