[llvm] [WIP][VPlan] Sink recipes from the vector loop region in licm. (PR #168031)
Mel Chen via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 21 06:48:18 PST 2025
================
@@ -2224,16 +2224,46 @@ void VPlanTransforms::cse(VPlan &Plan) {
}
}
-/// Move loop-invariant recipes out of the vector loop region in \p Plan.
-static void licm(VPlan &Plan) {
- VPBasicBlock *Preheader = Plan.getVectorPreheader();
+/// Sink recipes with no users inside the vector loop region into a dedicated
+/// exit block.
+static void sinkRecipesFromLoopRegion(VPRegionBlock *LoopRegion) {
+ auto *SingleExit = cast<VPBasicBlock>(LoopRegion->getSingleSuccessor());
+ // Check whether there is a unique dedicated exit block.
+ // TODO: Should check all predecessors of the exit block.
+ if (SingleExit->getSinglePredecessor() != LoopRegion)
+ return;
+
+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+ vp_depth_first_shallow(LoopRegion->getEntry()))) {
+ for (VPRecipeBase &R : make_early_inc_range(reverse(*VPBB))) {
+ if (isDeadRecipe(R)) {
+ R.eraseFromParent();
+ continue;
+ }
+
+ if (cannotHoistOrSinkRecipe(R))
+ continue;
+
+ auto *Def = cast<VPSingleDefRecipe>(&R);
+ if (any_of(Def->users(), [LoopRegion](VPUser *U) {
+ auto *UR = cast<VPRecipeBase>(U);
+ return UR->getParent()->getEnclosingLoopRegion();
+ }))
+ continue;
+
+ Def->moveBefore(*SingleExit, SingleExit->getFirstNonPhi());
+ }
+ }
+}
+
+static void hoistRecipesFromLoopRegion(VPRegionBlock *LoopRegion) {
+ VPBasicBlock *Preheader = LoopRegion->getPlan()->getVectorPreheader();
// Hoist any loop invariant recipes from the vector loop region to the
// preheader. Preform a shallow traversal of the vector loop region, to
----------------
Mel-Chen wrote:
Remove the hoistRecipesFromLoopRegion so that we don't need to move it, thanks.
https://github.com/llvm/llvm-project/pull/168031
More information about the llvm-commits
mailing list