diff options
author | Sanjay Patel <spatel@rotateright.com> | 2021-06-07 11:48:45 -0400 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2021-06-07 13:22:49 -0400 |
commit | 519e98cd9af0d4b47a2daf0899b69d1254750c13 (patch) | |
tree | 7c473b253230a8ce2ff76bac8c891525bf5ac1eb /llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | |
parent | dc173254e754f1c363218548040642c6c53da8ed (diff) | |
download | llvm-519e98cd9af0d4b47a2daf0899b69d1254750c13.zip llvm-519e98cd9af0d4b47a2daf0899b69d1254750c13.tar.gz llvm-519e98cd9af0d4b47a2daf0899b69d1254750c13.tar.bz2 |
[InstCombine] refactor match clauses; NFC
We need to adjust the FMF propagation on at least
one of these transforms as discussed in:
https://llvm.org/PR49654
...so this should make it easier to intersect flags.
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 2a77f56..2e0d3bf 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -2125,27 +2125,30 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) { /// This eliminates floating-point negation in either 'fneg(X)' or /// 'fsub(-0.0, X)' form by combining into a constant operand. static Instruction *foldFNegIntoConstant(Instruction &I) { + // This is limited with one-use because fneg is assumed better for + // reassociation and cheaper in codegen than fmul/fdiv. + // TODO: Should the m_OneUse restriction be removed? + Instruction *FNegOp; + if (!match(&I, m_FNeg(m_OneUse(m_Instruction(FNegOp))))) + return nullptr; + Value *X; Constant *C; - // Fold negation into constant operand. This is limited with one-use because - // fneg is assumed better for analysis and cheaper in codegen than fmul/fdiv. + // Fold negation into constant operand. // -(X * C) --> X * (-C) - // FIXME: It's arguable whether these should be m_OneUse or not. The current - // belief is that the FNeg allows for better reassociation opportunities. - if (match(&I, m_FNeg(m_OneUse(m_FMul(m_Value(X), m_Constant(C)))))) + if (match(FNegOp, m_FMul(m_Value(X), m_Constant(C)))) return BinaryOperator::CreateFMulFMF(X, ConstantExpr::getFNeg(C), &I); // -(X / C) --> X / (-C) - if (match(&I, m_FNeg(m_OneUse(m_FDiv(m_Value(X), m_Constant(C)))))) + if (match(FNegOp, m_FDiv(m_Value(X), m_Constant(C)))) return BinaryOperator::CreateFDivFMF(X, ConstantExpr::getFNeg(C), &I); // -(C / X) --> (-C) / X - if (match(&I, m_FNeg(m_OneUse(m_FDiv(m_Constant(C), m_Value(X)))))) + if (match(FNegOp, m_FDiv(m_Constant(C), m_Value(X)))) return BinaryOperator::CreateFDivFMF(ConstantExpr::getFNeg(C), X, &I); // With NSZ [ counter-example with -0.0: -(-0.0 + 0.0) != 0.0 + -0.0 ]: // -(X + C) --> -X + -C --> -C - X - if (I.hasNoSignedZeros() && - match(&I, m_FNeg(m_OneUse(m_FAdd(m_Value(X), m_Constant(C)))))) + if (I.hasNoSignedZeros() && match(FNegOp, m_FAdd(m_Value(X), m_Constant(C)))) return BinaryOperator::CreateFSubFMF(ConstantExpr::getFNeg(C), X, &I); return nullptr; |