[llvm] [NaryReassociate] Teach NaryReassociate about UniformityAnalysis (PR #175167)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 20 04:42:33 PST 2026
================
@@ -379,6 +392,33 @@ NaryReassociatePass::tryReassociateGEPAtIndex(GetElementPtrInst *GEP,
Value *LHS = AO->getOperand(0), *RHS = AO->getOperand(1);
// IndexToSplit = LHS + RHS.
+ // 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.
+ //
+ // For uniformity: prefer the remaining calculation to be uniform, as it
+ // can then stay in scalar registers.
+ //
+ // Default order tries LHS first (RHS as remainder). If LHS is uniform and
+ // RHS is divergent, we want to try RHS first so uniform LHS becomes the
+ // remainder. The case where RHS is uniform and LHS is divergent is already
+ // handled by the default order.
+ if (UI && UI->isUniform(LHS) && !UI->isUniform(RHS)) {
+ LLVM_DEBUG(
+ dbgs() << "NARY: Preferring uniform remainder for GEP index\n");
+ // LHS is uniform, prefer it as remainder - try RHS first
+ if (LHS != RHS) {
+ if (auto *NewGEP =
----------------
arsenm wrote:
No auto
https://github.com/llvm/llvm-project/pull/175167
More information about the llvm-commits
mailing list