[llvm] [LoopStrengthReduce] Mitigation of issues introduced by compilation time optimization in SolveRecurse. (PR #147588)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 8 18:11:11 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) {
----------------
arsenm wrote:
```suggestion
stable_sort(
NewOrder, NewOrder, [](const LSRUse *L, const LSRUse *R) {
```
https://github.com/llvm/llvm-project/pull/147588
More information about the llvm-commits
mailing list