Skip to content

Commit 4a425a4

Browse files
authored
NaryReassociate: Check pattern before user scan (#134587)
1 parent 04bb8ec commit 4a425a4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

llvm/lib/Transforms/Scalar/NaryReassociate.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,15 +611,15 @@ Value *NaryReassociatePass::tryReassociateMinOrMax(Instruction *I,
611611
Value *A = nullptr, *B = nullptr;
612612
MaxMinT m_MaxMin(m_Value(A), m_Value(B));
613613

614+
if (!match(LHS, m_MaxMin))
615+
return nullptr;
616+
614617
if (LHS->hasNUsesOrMore(3) ||
615618
// The optimization is profitable only if LHS can be removed in the end.
616619
// In other words LHS should be used (directly or indirectly) by I only.
617-
llvm::any_of(LHS->users(),
618-
[&](auto *U) {
619-
return U != I &&
620-
!(U->hasOneUser() && *U->users().begin() == I);
621-
}) ||
622-
!match(LHS, m_MaxMin))
620+
llvm::any_of(LHS->users(), [&](auto *U) {
621+
return U != I && !(U->hasOneUser() && *U->users().begin() == I);
622+
}))
623623
return nullptr;
624624

625625
auto tryCombination = [&](Value *A, const SCEV *AExpr, Value *B,

0 commit comments

Comments
 (0)