[llvm] VPlan: introduce worklist in simplifyRecipes (PR #105699)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 14:02:28 PDT 2024


================
@@ -1009,8 +1015,16 @@ static void simplifyRecipes(VPlan &Plan, LLVMContext &Ctx) {
       Plan.getEntry());
   VPTypeAnalysis TypeInfo(Plan.getCanonicalIV()->getScalarType(), Ctx);
   for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
-    for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
-      simplifyRecipe(R, TypeInfo);
+    // Populate a Worklist, as simplifyRecipe might return a new recipe that we
+    // need to re-process.
+    SmallVector<VPRecipeBase *> Worklist;
+    for (auto &R : VPBB->getRecipeList())
+      Worklist.push_back(&R);
+
+    while (!Worklist.empty()) {
+      VPRecipeBase *R = Worklist.pop_back_val();
+      for (VPRecipeBase *Cand : simplifyRecipe(*R, TypeInfo))
+        Worklist.push_back(Cand);
----------------
artagnon wrote:

Hm, not sure I understand why we'd want to have the worklist in `simplifyRecipe`: I was thinking that we could keep `simplifyRecipe` simple, simply handling different patterns like the way it's done in InstCombine. I'm, in fact, quite fond of the approach I've taken.

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


More information about the llvm-commits mailing list