[llvm] 020d2fb - InstCombine: Avoid repeated m_OneUse checks
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 2 07:43:03 PDT 2023
Author: Matt Arsenault
Date: 2023-08-02T10:42:56-04:00
New Revision: 020d2fb7711d70e296f19d83565f8d93d2cfda71
URL: https://github.com/llvm/llvm-project/commit/020d2fb7711d70e296f19d83565f8d93d2cfda71
DIFF: https://github.com/llvm/llvm-project/commit/020d2fb7711d70e296f19d83565f8d93d2cfda71.diff
LOG: InstCombine: Avoid repeated m_OneUse checks
The check was repeated for the fmul and fdiv case, and the caller was
already checking anyway.
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 b43ea523795231..5dc778daec2485 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -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;
}
@@ -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)))) {
More information about the llvm-commits
mailing list