[llvm] [llvm][LICM] Add flag to control re-association (PR #149829)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 21 07:52:22 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Theodoros Theodoridis (thetheodor)
<details>
<summary>Changes</summary>
Add a command line flag that controls the amount of binary-op re-association based on the number of uses.
---
Full diff: https://github.com/llvm/llvm-project/pull/149829.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Scalar/LICM.cpp (+6-1)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/149829
More information about the llvm-commits
mailing list