diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2018-04-05 21:37:17 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2018-04-05 21:37:17 +0000 |
| commit | 03e2526728d4548be925ad4c023dd41d8f6f363e (patch) | |
| tree | c7bc86a730e106a667a11c8876590048ec04fa84 /llvm/lib/Transforms | |
| parent | daa8da1ff4cd09c879a97e1ea1d624bd7aec5a98 (diff) | |
| download | bcm5719-llvm-03e2526728d4548be925ad4c023dd41d8f6f363e.tar.gz bcm5719-llvm-03e2526728d4548be925ad4c023dd41d8f6f363e.zip | |
[InstCombine] nsz: -(X - Y) --> Y - X
This restores part of the fold that was removed with rL73243 (PR4374).
llvm-svn: 329350
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 578ba23604d..0541eb7b291 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1698,10 +1698,17 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) { SQ.getWithInstruction(&I))) return replaceInstUsesWith(I, V); - // Subtraction from -0.0 is the canonical form of fneg. - // fsub nsz 0, X ==> fsub nsz -0.0, X - if (I.getFastMathFlags().noSignedZeros() && match(Op0, m_PosZeroFP())) - return BinaryOperator::CreateFNegFMF(Op1, &I); + if (I.hasNoSignedZeros()) { + // Subtraction from -0.0 is the canonical form of fneg. + // fsub nsz 0, X ==> fsub nsz -0.0, X + if (match(Op0, m_PosZeroFP())) + return BinaryOperator::CreateFNegFMF(Op1, &I); + + // With no-signed-zeros: -(X - Y) --> Y - X + Value *X, *Y; + if (match(Op0, m_NegZeroFP()) && match(Op1, m_FSub(m_Value(X), m_Value(Y)))) + return BinaryOperator::CreateFSubFMF(Y, X, &I); + } if (isa<Constant>(Op0)) if (SelectInst *SI = dyn_cast<SelectInst>(Op1)) |

