[llvm] [NaryReassociate] Teach NaryReassociate about UniformityAnalysis (PR #175167)
Sameer Sahasrabuddhe via llvm-commits
llvm-commits at lists.llvm.org
Wed May 6 22:04:35 PDT 2026
================
@@ -379,14 +396,32 @@ NaryReassociatePass::tryReassociateGEPAtIndex(GetElementPtrInst *GEP,
Value *LHS = AO->getOperand(0), *RHS = AO->getOperand(1);
// IndexToSplit = LHS + RHS.
- if (auto *NewGEP = tryReassociateGEPAtIndex(GEP, I, LHS, RHS, IndexedType))
- return NewGEP;
- // Symmetrically, try IndexToSplit = RHS + LHS.
- if (LHS != RHS) {
- if (auto *NewGEP =
+ // tryReassociateGEPAtIndex(GEP, I, LHS, RHS, ...) looks for a dominating
+ // GEP with LHS as index, then creates: NewGEP = existingGEP + RHS * scale.
+ // So the RHS becomes the "remaining" index calculation.
+
+ // When LHS == RHS, both call orders are identical, so only try once.
+ if (LHS == RHS)
+ return tryReassociateGEPAtIndex(GEP, I, LHS, RHS, IndexedType);
+
+ // When uniformity analysis is available, prefer the remaining calculation
+ // to be uniform, keeping uniform computations grouped together.
+ // Default order tries LHS first (RHS as remainder). If LHS is uniform and
+ // RHS is divergent, try RHS first so uniform LHS becomes the remainder.
+ if (UI && UI->isUniform(LHS) && !UI->isUniform(RHS)) {
----------------
ssahasra wrote:
Just a fly-by note, need not be addressed in this PR: We should probably rename "isUniform" to "isUniformDef" so that any one inserting the call has to think about which one they want.
https://github.com/llvm/llvm-project/pull/175167
More information about the llvm-commits
mailing list