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

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 22 14:24:25 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:

Is the idea that we pass a recipe to `simplifyRecipe`, which then maximally simplifies it, by running over the same code multiple times using a worklist every time a new recipe is introduced by a simplification? Wouldn't it be preferable to instead call `simplifyRecipe` multiple times, and maintain the worklist in `simplifyRecipes`, in the interest of having `simplifyRecipe` do one thing? I would imagine that if we took the former route, `simplifyRecipe` would be called something like `maximallySimplifyRecipe` instead?

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


More information about the llvm-commits mailing list