[llvm] [VPlan] Hoist loads with invariant addresses using noalias metadata. (PR #166247)

via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 22 05:50:14 PST 2025


================
@@ -3914,6 +3920,54 @@ void VPlanTransforms::materializeBroadcasts(VPlan &Plan) {
   }
 }
 
+void VPlanTransforms::hoistInvariantLoads(VPlan &Plan) {
+  VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion();
+
+  // Collect candidate loads with invariant addresses and noalias scopes
+  // metadata and memory-writing recipes with noalias metadata.
+  SmallVector<std::pair<VPRecipeBase *, MemoryLocation>> CandidateLoads;
+  SmallVector<MemoryLocation> Stores;
+  for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+           vp_depth_first_shallow(LoopRegion->getEntry()))) {
+    for (VPRecipeBase &R : *VPBB) {
+      // Only handle single-scalar replicated loads with invariant addresses.
+      if (auto *RepR = dyn_cast<VPReplicateRecipe>(&R)) {
+        if (RepR->isPredicated() || !RepR->isSingleScalar() ||
+            RepR->getOpcode() != Instruction::Load)
+          continue;
----------------
ayalz wrote:

What about replicating recipes of stores? Ensure RepR may not write to memory before continue disregards it, or check first if R.mayWriteToMemory() and then if R is a replicating single scalar load.

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


More information about the llvm-commits mailing list