[llvm] [VPlan] Sink vector loop region recipes in licm (PR #172343)
Mel Chen via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 6 02:06:45 PST 2026
================
@@ -2521,6 +2521,34 @@ static void licm(VPlan &Plan) {
R.moveBefore(*Preheader, Preheader->end());
}
}
+
+ // Sink any recipes which don't have any users in the region to the nearest
+ // common dominator of its users.
+ VPDominatorTree VPDT(Plan);
+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+ vp_post_order_shallow(LoopRegion->getEntry()))) {
+ for (VPRecipeBase &R : make_early_inc_range(reverse(*VPBB))) {
+ if (cannotHoistOrSinkRecipe(R))
+ continue;
+ SmallSetVector<VPBasicBlock *, 4> UserVPBBs;
+ // Check that R doesn't have any users inside a loop region.
+ if (any_of(R.definedValues(), [&UserVPBBs](VPValue *V) {
+ return any_of(V->users(), [&UserVPBBs](VPUser *U) {
+ auto *UR = cast<VPRecipeBase>(U);
+ UserVPBBs.insert(UR->getParent());
+ return UR->getParent()->getEnclosingLoopRegion();
+ });
+ }))
+ continue;
+ if (UserVPBBs.empty())
+ continue;
+ VPBasicBlock *SinkVPBB = UserVPBBs.front();
+ for (auto *UserVPBB : drop_begin(UserVPBBs))
+ SinkVPBB = cast<VPBasicBlock>(
+ VPDT.findNearestCommonDominator(SinkVPBB, UserVPBB));
+ R.moveBefore(*SinkVPBB, SinkVPBB->begin());
----------------
Mel-Chen wrote:
Should not insert to `SinkVPBB->getFirstNonPhi()`? Like: https://github.com/llvm/llvm-project/pull/168031/files#diff-53267225b83e943ceae51c326c9941e323fd7aaf74a08b5e6998d6456f88d1ddR2544
https://github.com/llvm/llvm-project/pull/172343
More information about the llvm-commits
mailing list