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

via llvm-commits llvm-commits at lists.llvm.org
Wed May 14 15:46:33 PDT 2025


================
@@ -1084,6 +1084,40 @@ void VPlanTransforms::simplifyRecipes(VPlan &Plan, Type &CanonicalIVTy) {
   }
 }
 
+static void convertToUniformRecipes(VPlan &Plan) {
+  auto TryToNarrow = [](VPBasicBlock *VPBB) {
+    for (VPRecipeBase &R : make_early_inc_range(reverse(*VPBB))) {
+      // Try to narrow wide and replicating recipes to uniform recipes, based on
+      // VPlan analysis.
+      auto *Def = dyn_cast<VPSingleDefRecipe>(&R);
+      if (!Def || !isa<VPReplicateRecipe, VPWidenRecipe>(Def) ||
+          !Def->getUnderlyingValue())
+        continue;
+
+      auto *RepR = dyn_cast<VPReplicateRecipe>(&R);
+      if (RepR && RepR->isUniform())
+        continue;
+
+      // Skip recipes that aren't uniform and don't have only their scalar
+      // results used. In the later case, we would introduce extra broadcasts.
+      if (!vputils::isUniformAfterVectorization(Def) ||
----------------
ayalz wrote:

The term "UniformAfterVectorization" and VPReplicateRecipe's "uniform" field should be renamed. Being uniform (having same value for all lanes) is independent of being before or after vectorization. The term stands for "singleLane" or "singleScalar", which is typically associated with the first lane (as in unit-stride, i.e., clearly non-uniform, GEPs whose first lane is the only one used), and with all lanes when the value is uniform.

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


More information about the llvm-commits mailing list