[llvm] [LoopStrengthReduce] Mitigation of issues introduced by compilation time optimization in SolveRecurse. (PR #147588)

Sergey Shcherbinin via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 9 03:21:14 PDT 2025


================
@@ -5368,6 +5369,46 @@ void LSRInstance::NarrowSearchSpaceUsingHeuristics() {
     NarrowSearchSpaceByPickingWinnerRegs();
 }
 
+/// Sort LSRUses to address side effects of compile time optimization done in
+/// SolveRecurse which filters out formulae not including required registers.
+/// Such optimization makes the found best solution sensitive to the order
+/// of LSRUses processing, hence it's important to ensure that that order
+/// isn't random to avoid fluctuations and sub-optimal results.
+///
+/// Also check that all LSRUses have formulae as otherwise the situation is
+/// unsolvable.
+bool LSRInstance::SortLSRUses() {
+  SmallVector<LSRUse *, 16> NewOrder;
+  for (auto &LU : Uses) {
+    if (!LU.Formulae.size()) {
+      return false;
+    }
+    NewOrder.push_back(&LU);
+  }
+
+  std::stable_sort(
+      NewOrder.begin(), NewOrder.end(), [](const LSRUse *L, const LSRUse *R) {
----------------
SergeyShch01 wrote:

ok, fixed by second commit - but one NewOrder in your suggestion is redundant

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


More information about the llvm-commits mailing list