[llvm] [SLSR] Skipping rewriting based on liveness (PR #218470)

Igor Wodiany via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 02:55:36 PDT 2026


================
@@ -1427,11 +1813,28 @@ bool StraightLineStrengthReduce::runOnFunction(Function &F) {
   }
   sortCandidateInstructions();
 
+  // Keep picked candidates not to call pickRewriteCandidate() again.
+  DenseMap<Instruction *, Candidate *> PickedCandidateMap;
+  for (Instruction *I : SortedCandidateInsts)
+    if (Candidate *C = pickRewriteCandidate(I))
+      PickedCandidateMap[I] = C;
+
+  // Candidates whose rewrite would push their block's register pressure past
+  // what the target can allocate. Evaluated on the original IR, before any
+  // rewriteCandidate mutates it: rewriting inserts instructions and calls
+  // replaceAllUsesWith, which would invalidate the liveness
+  // analyses the filter relies on.
+  RewriteFilter RewriteFilter(&F, PickedCandidateMap, TTI);
+  DenseSet<const Instruction *> ToSkipRewrite = RewriteFilter.run();
----------------
IgWod wrote:

Makes sense, I'm happy for it to stay as it is.

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


More information about the llvm-commits mailing list