[llvm] [InstCombine] Iterative replacement in PtrReplacer (PR #137215)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed May 21 14:36:26 PDT 2025
================
@@ -270,80 +268,132 @@ class PointerReplacer {
} // end anonymous namespace
bool PointerReplacer::collectUsers() {
- if (!collectUsersRecursive(Root))
- return false;
-
- // Ensure that all outstanding (indirect) users of I
- // are inserted into the Worklist. Return false
- // otherwise.
- return llvm::set_is_subset(ValuesToRevisit, Worklist);
-}
+ SmallVector<Instruction *> Worklist;
+ SmallSetVector<Instruction *, 4> ValuesToRevisit;
+
+ auto PushUsersToWorklist = [&](Instruction *Inst) {
+ for (auto *U : Inst->users()) {
+ if (auto *I = dyn_cast<Instruction>(U)) {
+ if (!isAvailable(I) && !ValuesToRevisit.contains(I))
+ Worklist.emplace_back(I);
+ }
+ }
+ };
-bool PointerReplacer::collectUsersRecursive(Instruction &I) {
- for (auto *U : I.users()) {
- auto *Inst = cast<Instruction>(&*U);
+ PushUsersToWorklist(&Root);
+ while (!Worklist.empty()) {
+ auto *Inst = Worklist.pop_back_val();
----------------
arsenm wrote:
```suggestion
Instruction *Inst = Worklist.pop_back_val();
```
https://github.com/llvm/llvm-project/pull/137215
More information about the llvm-commits
mailing list