[llvm] 519e98c - [InstCombine] refactor match clauses; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 7 10:22:58 PDT 2021
Author: Sanjay Patel
Date: 2021-06-07T13:22:49-04:00
New Revision: 519e98cd9af0d4b47a2daf0899b69d1254750c13
URL: https://github.com/llvm/llvm-project/commit/519e98cd9af0d4b47a2daf0899b69d1254750c13
DIFF: https://github.com/llvm/llvm-project/commit/519e98cd9af0d4b47a2daf0899b69d1254750c13.diff
LOG: [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.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 2a77f56e569c8..2e0d3bf0a24b9 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;
More information about the llvm-commits
mailing list