[llvm] [VPlan] Add convertToUniformRecipe transform. (PR #139150)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu May 15 13:38:34 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) ||
+ any_of(Def->users(),
+ [Def](VPUser *U) { return !U->usesScalars(Def); }))
+ continue;
+
+ auto *Clone = new VPReplicateRecipe(Def->getUnderlyingInstr(),
+ Def->operands(), /*IsUniform*/ true);
+ Clone->insertBefore(Def);
+ Def->replaceAllUsesWith(Clone);
+ Def->eraseFromParent();
+ }
+ };
+
+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+ vp_depth_first_shallow(Plan.getVectorLoopRegion()->getEntry())))
+ TryToNarrow(VPBB);
----------------
fhahn wrote:
I have some follow-up patches that may calls this on additional blocks, which was why I had the lambda originally. Inlined for now, thanks
https://github.com/llvm/llvm-project/pull/139150
More information about the llvm-commits
mailing list