[llvm] 4a425a4 - NaryReassociate: Check pattern before user scan (#134587)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 7 01:25:07 PDT 2025
Author: Matt Arsenault
Date: 2025-04-07T15:25:03+07:00
New Revision: 4a425a4966d6421674d4300e32b0eb57ebade65a
URL: https://github.com/llvm/llvm-project/commit/4a425a4966d6421674d4300e32b0eb57ebade65a
DIFF: https://github.com/llvm/llvm-project/commit/4a425a4966d6421674d4300e32b0eb57ebade65a.diff
LOG: NaryReassociate: Check pattern before user scan (#134587)
Added:
Modified:
llvm/lib/Transforms/Scalar/NaryReassociate.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/NaryReassociate.cpp b/llvm/lib/Transforms/Scalar/NaryReassociate.cpp
index 3b3f32a0ea591..ec17443b37143 100644
--- a/llvm/lib/Transforms/Scalar/NaryReassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/NaryReassociate.cpp
@@ -611,15 +611,15 @@ Value *NaryReassociatePass::tryReassociateMinOrMax(Instruction *I,
Value *A = nullptr, *B = nullptr;
MaxMinT m_MaxMin(m_Value(A), m_Value(B));
+ if (!match(LHS, m_MaxMin))
+ return nullptr;
+
if (LHS->hasNUsesOrMore(3) ||
// The optimization is profitable only if LHS can be removed in the end.
// In other words LHS should be used (directly or indirectly) by I only.
- llvm::any_of(LHS->users(),
- [&](auto *U) {
- return U != I &&
- !(U->hasOneUser() && *U->users().begin() == I);
- }) ||
- !match(LHS, m_MaxMin))
+ llvm::any_of(LHS->users(), [&](auto *U) {
+ return U != I && !(U->hasOneUser() && *U->users().begin() == I);
+ }))
return nullptr;
auto tryCombination = [&](Value *A, const SCEV *AExpr, Value *B,
More information about the llvm-commits
mailing list