[llvm] [VPlan] Add convertToUniformRecipe transform. (PR #139150)

via llvm-commits llvm-commits at lists.llvm.org
Fri May 16 05:26:41 PDT 2025


================
@@ -1086,6 +1086,40 @@ void VPlanTransforms::simplifyRecipes(VPlan &Plan, Type &CanonicalIVTy) {
   }
 }
 
+static void convertToUniformRecipes(VPlan &Plan) {
+  if (Plan.hasScalarVFOnly())
+    return;
+
+  for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+           vp_depth_first_shallow(Plan.getVectorLoopRegion()->getEntry()))) {
+    for (VPRecipeBase &R : make_early_inc_range(reverse(*VPBB))) {
+      // Try to narrow wide and replicating recipes to uniform recipes, based on
+      // VPlan analysis.
+      auto *RepR = dyn_cast<VPReplicateRecipe>(&R);
+      if (!RepR && !isa<VPWidenRecipe>(&R))
+        continue;
+      if (RepR && RepR->isUniform())
+        continue;
+
+      auto *RepOrWidenR = cast<VPSingleDefRecipe>(&R);
+      // Skip recipes that aren't uniform and don't have only their scalar
+      // results used. In the latter case, we would introduce extra broadcasts.
+      if (!vputils::isUniformAfterVectorization(RepOrWidenR) ||
+          any_of(RepOrWidenR->users(), [RepOrWidenR](VPUser *U) {
+            return !U->usesScalars(RepOrWidenR);
+          }))
+        continue;
+
+      auto *Clone =
+          new VPReplicateRecipe(RepOrWidenR->getUnderlyingInstr(),
+                                RepOrWidenR->operands(), /*IsUniform*/ true);
----------------
ayalz wrote:

```suggestion
                                RepOrWidenR->operands(), /*IsSingleScalar*/ true);
```

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


More information about the llvm-commits mailing list