[llvm] [LSR] Narrow search space by merging users outside and inside loop (PR #202676)

Björn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 22 06:00:12 PDT 2026


================
@@ -5220,6 +5221,77 @@ void LSRInstance::NarrowSearchSpaceByFilterPostInc() {
   LLVM_DEBUG(dbgs() << "After pre-selection:\n"; print_uses(dbgs()));
 }
 
+void LSRInstance::NarrowSearchSpaceByMergingUsesOutsideLoop() {
+  if (EstimateSearchSpaceComplexity() < ComplexityLimit)
+    return;
+
+  LLVM_DEBUG(
+      dbgs() << "The search space is too complex.\n"
+                "Narrowing the search space by merging uses with fixups "
+                "entirely outside the loop with uses inside the loop.\n");
+
+  for (size_t LUIdx = 0, NumUses = Uses.size(); LUIdx != NumUses; ++LUIdx) {
+    LSRUse &LU = Uses[LUIdx];
+    if (!LU.AllFixupsOutsideLoop || LU.Formulae.empty())
+      continue;
+
+    LLVM_DEBUG(dbgs() << "  Trying to eliminate use "; LU.print(dbgs());
+               dbgs() << '\n');
+
+    // Find a compatible LSRUse inside the loop that we could merge LU with
+    LSRUse *LUToMergeWith = nullptr;
+    const Formula &ThisF = LU.Formulae[0];
+    for (LSRUse &OtherLU : Uses) {
+      // Only merge with uses inside the loop
----------------
bjope wrote:

Not sure if this is a problem, but `OtherLU.AllFixupsOutsideLoop == false` doesn't imply "all uses inside loop", right? So the comment and the code doesn't really match here.

https://github.com/llvm/llvm-project/pull/202676


More information about the llvm-commits mailing list