Skip to content

Commit

Permalink
InstCombine: Avoid repeated m_OneUse checks
Browse files Browse the repository at this point in the history
The check was repeated for the fmul and fdiv case, and the caller was
already checking anyway.
  • Loading branch information
arsenm committed Aug 2, 2023
1 parent ed0dbfe commit 020d2fb
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2520,18 +2520,17 @@ static Instruction *foldFNegIntoConstant(Instruction &I, const DataLayout &DL) {
return nullptr;
}

static Instruction *hoistFNegAboveFMulFDiv(Instruction &I,
static Instruction *hoistFNegAboveFMulFDiv(Value *FNegOp,
Instruction &FMFSource,
InstCombiner::BuilderTy &Builder) {
Value *FNeg;
if (!match(&I, m_FNeg(m_Value(FNeg))))
return nullptr;

Value *X, *Y;
if (match(FNeg, m_OneUse(m_FMul(m_Value(X), m_Value(Y)))))
return BinaryOperator::CreateFMulFMF(Builder.CreateFNegFMF(X, &I), Y, &I);
if (match(FNegOp, m_FMul(m_Value(X), m_Value(Y))))
return BinaryOperator::CreateFMulFMF(Builder.CreateFNegFMF(X, &FMFSource),
Y, &FMFSource);

if (match(FNeg, m_OneUse(m_FDiv(m_Value(X), m_Value(Y)))))
return BinaryOperator::CreateFDivFMF(Builder.CreateFNegFMF(X, &I), Y, &I);
if (match(FNegOp, m_FDiv(m_Value(X), m_Value(Y))))
return BinaryOperator::CreateFDivFMF(Builder.CreateFNegFMF(X, &FMFSource),
Y, &FMFSource);

return nullptr;
}
Expand All @@ -2553,13 +2552,13 @@ Instruction *InstCombinerImpl::visitFNeg(UnaryOperator &I) {
match(Op, m_OneUse(m_FSub(m_Value(X), m_Value(Y)))))
return BinaryOperator::CreateFSubFMF(Y, X, &I);

if (Instruction *R = hoistFNegAboveFMulFDiv(I, Builder))
return R;

Value *OneUse;
if (!match(Op, m_OneUse(m_Value(OneUse))))
return nullptr;

if (Instruction *R = hoistFNegAboveFMulFDiv(OneUse, I, Builder))
return R;

// Try to eliminate fneg if at least 1 arm of the select is negated.
Value *Cond;
if (match(OneUse, m_Select(m_Value(Cond), m_Value(X), m_Value(Y)))) {
Expand Down

0 comments on commit 020d2fb

Please sign in to comment.