diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-04-05 23:21:15 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-04-05 23:21:15 +0000 |
commit | 04683de82f5d6812555a5ddf6983ee4b67b76be3 (patch) | |
tree | 85569746462ca8f625c2fdb8355cac2805cb541f /llvm/lib/Transforms/InstCombine | |
parent | b4e3129356f8f24ddcbbf30c09783581b1627a37 (diff) | |
download | bcm5719-llvm-04683de82f5d6812555a5ddf6983ee4b67b76be3.tar.gz bcm5719-llvm-04683de82f5d6812555a5ddf6983ee4b67b76be3.zip |
[InstCombine] FP: Z - (X - Y) --> Z + (Y - X)
This restores what was lost with rL73243 but without
re-introducing the bug that was present in the old code.
Note that we already have these transforms if the ops are
marked 'fast' (and I assume that's happening somewhere in
the code added with rL170471), but we clearly don't need
all of 'fast' for these transforms.
llvm-svn: 329362
Diffstat (limited to 'llvm/lib/Transforms/InstCombine')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 0541eb7b291..fac3ea86359 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1698,6 +1698,7 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) { SQ.getWithInstruction(&I))) return replaceInstUsesWith(I, V); + Value *X, *Y; if (I.hasNoSignedZeros()) { // Subtraction from -0.0 is the canonical form of fneg. // fsub nsz 0, X ==> fsub nsz -0.0, X @@ -1705,11 +1706,20 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) { 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); } + // More generally than above, if Op0 is not -0.0: Z - (X - Y) --> Z + (Y - X) + // Canonicalize to fadd to make analysis easier. + // This can also help codegen because fadd is commutative. + if (I.hasNoSignedZeros() || CannotBeNegativeZero(Op0, SQ.TLI)) { + if (match(Op1, m_OneUse(m_FSub(m_Value(X), m_Value(Y))))) { + Value *NewSub = Builder.CreateFSubFMF(Y, X, &I); + return BinaryOperator::CreateFAddFMF(Op0, NewSub, &I); + } + } + if (isa<Constant>(Op0)) if (SelectInst *SI = dyn_cast<SelectInst>(Op1)) if (Instruction *NV = FoldOpIntoSelect(I, SI)) @@ -1721,7 +1731,6 @@ Instruction *InstCombiner::visitFSub(BinaryOperator &I) { return BinaryOperator::CreateFAddFMF(Op0, ConstantExpr::getFNeg(C), &I); // X - (-Y) --> X + Y - Value *Y; if (match(Op1, m_FNeg(m_Value(Y)))) return BinaryOperator::CreateFAddFMF(Op0, Y, &I); |