[llvm] [InstCombine] Iterative replacement in PtrReplacer (PR #137215)
Anshil Gandhi via llvm-commits
llvm-commits at lists.llvm.org
Tue May 27 10:04:29 PDT 2025
================
@@ -270,80 +268,125 @@ 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()) {
+ Instruction *Inst = Worklist.pop_back_val();
+ if (!Inst)
+ return false;
----------------
gandhi56 wrote:
The condition below is also irrelevant, as only unavailable users are pushed into the worklist.
https://github.com/llvm/llvm-project/pull/137215
More information about the llvm-commits
mailing list