[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:45:24 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))) {
----------------
Mel-Chen wrote:

Could you give me an example to show we have to checking that the operands are defined outside loop regions?

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


More information about the llvm-commits mailing list