[llvm] [SPIR-V] Avoid exponential path enumeration in findPathsToMatch (PR #212933)
Juan Manuel Martinez CaamaƱo via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 04:57:03 PDT 2026
================
@@ -213,29 +214,52 @@ class ConvergenceRegionAnalyzer {
SmallPtrSet<BasicBlock *, 0>
findPathsToMatch(LoopInfo &LI, BasicBlock *From,
std::function<bool(const BasicBlock *)> isMatch) const {
- SmallPtrSet<BasicBlock *, 0> Output;
-
- if (isMatch(From))
- Output.insert(From);
+ // Compute the postorder of the blocks forward-reachable from |From|,
+ // ignoring back edges. Successors therefore always appear before their
+ // predecessors in the resulting list.
+ SmallVector<BasicBlock *, 16> PostOrder;
+ SmallPtrSet<BasicBlock *, 16> Visited;
+ SmallVector<std::pair<BasicBlock *, unsigned>, 16> Stack;
+
+ Visited.insert(From);
+ Stack.push_back({From, 0});
+ while (!Stack.empty()) {
+ auto &[BB, NextSuccessor] = Stack.back();
----------------
jmmartinez wrote:
`NextSuccessor` is always 0 ?
https://github.com/llvm/llvm-project/pull/212933
More information about the llvm-commits
mailing list