Skip to content

Conversation

artagnon
Copy link
Contributor

Combine the worklist and the seen containers into a single container that acts as both the worklist and the seen-tracker.

Combine the worklist and the seen containers into a single container
that acts as both the worklist and the seen-tracker.
@llvmbot
Copy link
Member

llvmbot commented Oct 10, 2025

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-vectorizers

Author: Ramkumar Ramachandra (artagnon)

Changes

Combine the worklist and the seen containers into a single container that acts as both the worklist and the seen-tracker.


Full diff: https://github.com/llvm/llvm-project/pull/162815.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp (+6-11)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index c8a2d84a535d3..b73a526f142b5 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -924,20 +924,15 @@ static void removeRedundantExpandSCEVRecipes(VPlan &Plan) {
 }
 
 static void recursivelyDeleteDeadRecipes(VPValue *V) {
-  SmallVector<VPValue *> WorkList;
-  SmallPtrSet<VPValue *, 8> Seen;
-  WorkList.push_back(V);
+  SetVector<VPValue *> WorkList;
+  WorkList.insert(V);
 
-  while (!WorkList.empty()) {
-    VPValue *Cur = WorkList.pop_back_val();
-    if (!Seen.insert(Cur).second)
-      continue;
+  for (unsigned I = 0; I < WorkList.size(); ++I) {
+    VPValue *Cur = WorkList[I];
     VPRecipeBase *R = Cur->getDefiningRecipe();
-    if (!R)
-      continue;
-    if (!isDeadRecipe(*R))
+    if (!R || !isDeadRecipe(*R))
       continue;
-    WorkList.append(R->op_begin(), R->op_end());
+    WorkList.insert_range(R->operands());
     R->eraseFromParent();
   }
 }

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure if this is a strict improvement, it has slightly fewer lines, but SetVector probably is a bit less efficient than separate set + vector, as SetVector will continously grow?

@artagnon
Copy link
Contributor Author

Hmm, not sure if this is a strict improvement, it has slightly fewer lines, but SetVector probably is a bit less efficient than separate set + vector, as SetVector will continously grow?

Hm, wouldn't it be exactly the size of the set, as we previously had to insert every element into the set to check for duplicates?

@artagnon artagnon closed this Oct 13, 2025
@artagnon artagnon deleted the vplan-dead-recipes-nfc branch October 13, 2025 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants