[llvm] [VPlan] Add convertToUniformRecipe transform. (PR #139150)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Fri May 16 08:36:11 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(),
----------------
david-arm wrote:
If this is already a `VPReplicateRecipe` class can we avoid the clone and simply set the `IsUniform` flag to true on the existing object?
https://github.com/llvm/llvm-project/pull/139150
More information about the llvm-commits
mailing list