[llvm] [llvm][LICM] Add flag to control re-association (PR #149829)
Theodoros Theodoridis via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 21 07:51:48 PDT 2025
https://github.com/thetheodor created https://github.com/llvm/llvm-project/pull/149829
Add a command line flag that controls the amount of binary-op re-association based on the number of uses.
>From 583f17ec2e20f8d01b23163365a7b6dae58ffc39 Mon Sep 17 00:00:00 2001
From: Theodoros Theodoridis <ttheodoridis at nvidia.com>
Date: Wed, 4 Jun 2025 14:34:40 +0000
Subject: [PATCH] [llvm][LICM] Flag to control re-association
Add a command line flag that controls the amount of binary op
re-association based on the number of uses.
---
llvm/lib/Transforms/Scalar/LICM.cpp | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp
index 68094c354cf46..35d2dc0a0e641 100644
--- a/llvm/lib/Transforms/Scalar/LICM.cpp
+++ b/llvm/lib/Transforms/Scalar/LICM.cpp
@@ -146,6 +146,11 @@ static cl::opt<unsigned> IntAssociationUpperLimit(
"Set upper limit for the number of transformations performed "
"during a single round of hoisting the reassociated expressions."));
+static cl::opt<unsigned> BOAssociationUserLimit(
+ "licm-hoist-bo-association-user-limit", cl::init(2), cl::Hidden,
+ cl::desc("Limit the number of users of the variant operand when "
+ "reassociating a binary operator for hoisting."));
+
// Experimental option to allow imprecision in LICM in pathological cases, in
// exchange for faster compile. This is to be removed if MemorySSA starts to
// address the same issue. LICM calls MemorySSAWalker's
@@ -2850,7 +2855,7 @@ static bool hoistBOAssociation(Instruction &I, Loop &L,
bool LVInRHS = L.isLoopInvariant(BO->getOperand(0));
auto *BO0 = dyn_cast<BinaryOperator>(BO->getOperand(LVInRHS));
if (!BO0 || BO0->getOpcode() != Opcode || !BO0->isAssociative() ||
- BO0->hasNUsesOrMore(3))
+ BO0->hasNUsesOrMore(BOAssociationUserLimit + 1))
return false;
Value *LV = BO0->getOperand(0);
More information about the llvm-commits
mailing list