diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-03-18 14:12:25 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-03-18 14:12:25 +0000 |
commit | 95ec4a4dfe4655044a5f689f792e5394d73ea248 (patch) | |
tree | 4cb18b2ab447b7121ff75a6bbc36b14c16d81d94 /llvm/lib/Analysis/InstructionSimplify.cpp | |
parent | 541992203dfc2f2e62309dfc0860677b685a80de (diff) | |
download | bcm5719-llvm-95ec4a4dfe4655044a5f689f792e5394d73ea248.tar.gz bcm5719-llvm-95ec4a4dfe4655044a5f689f792e5394d73ea248.zip |
[InstSimplify] loosen FMF for sqrt(X) * sqrt(X) --> X
As shown in the code comment, we don't need all of 'fast',
but we do need reassoc + nsz + nnan.
Differential Revision: https://reviews.llvm.org/D43765
llvm-svn: 327796
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index cf350ea2a1b..13e4fca781f 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -4249,10 +4249,13 @@ static Value *SimplifyFMulInst(Value *Op0, Value *Op1, FastMathFlags FMF, if (FMF.noNaNs() && FMF.noSignedZeros() && match(Op1, m_AnyZeroFP())) return ConstantFP::getNullValue(Op0->getType()); - // sqrt(X) * sqrt(X) --> X + // sqrt(X) * sqrt(X) --> X, if we can: + // 1. Remove the intermediate rounding (reassociate). + // 2. Ignore non-zero negative numbers because sqrt would produce NAN. + // 3. Ignore -0.0 because sqrt(-0.0) == -0.0, but -0.0 * -0.0 == 0.0. Value *X; - if (FMF.isFast() && Op0 == Op1 && - match(Op0, m_Intrinsic<Intrinsic::sqrt>(m_Value(X)))) + if (Op0 == Op1 && match(Op0, m_Intrinsic<Intrinsic::sqrt>(m_Value(X))) && + FMF.allowReassoc() && FMF.noNaNs() && FMF.noSignedZeros()) return X; return nullptr; |