[llvm] [SLSR] Avoid repeatedly calling canReuseInstruction for the same Basis (PR #196545)

Igor Wodiany via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 4 04:29:51 PDT 2026


================
@@ -981,7 +979,16 @@ void StraightLineStrengthReduce::allocateCandidatesAndFindBasis(
   LLVM_DEBUG(dbgs() << "Allocated Candidate: " << C << "\n");
   Candidates.push_back(C);
   RewriteCandidates[C.Ins].push_back(&Candidates.back());
-  CandidateDict.add(Candidates.back());
+  // Only add to the dict if this instruction is safe to reuse as a basis. By
+  // doing this early we avoid calling canReuseInstruction repeatedly for the
+  // same instruction. The DropList is stored on the Candidate so
+  // candidatePredicate can drop the flags when a rewrite is being done.
+  if (!EnablePoisonReuseGuard) {
+    CandidateDict.add(Candidates.back());
+  } else if (SE->canReuseInstruction(SE->getSCEV(I), I,
+                                     Candidates.back().DropList)) {
+    CandidateDict.add(Candidates.back());
+  }
----------------
IgWod wrote:

Thanks, done!

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


More information about the llvm-commits mailing list