1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

[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.
This commit is contained in:
Sanjay Patel 2021-06-07 11:48:45 -04:00
parent 2243b0992e
commit 927aaff338

View File

@ -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;