[llvm] [VPlan] Factor collectGroupedReplicateMemOps (NFCI) (PR #179506)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 2 07:26:31 PST 2026
================
@@ -4595,51 +4668,32 @@ 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;
+void VPlanTransforms::hoistInvariantLoads(VPlan &Plan,
+ PredicatedScalarEvolution &PSE,
+ const Loop *L) {
+ VPBasicBlock *Preheader = Plan.getVectorPreheader();
+ auto IsInvariantLoad = [](VPReplicateRecipe *RepR) {
+ if (RepR->isPredicated() || !RepR->isSingleScalar() ||
+ RepR->getOpcode() != Instruction::Load)
+ return false;
+ VPValue *Addr = RepR->getOperand(0);
+ return Addr->isDefinedOutsideLoopRegions();
+ };
+ auto Groups = collectGroupedReplicateMemOps<Instruction::Load>(
+ Plan, PSE, L, IsInvariantLoad);
+ for (auto Group : Groups) {
+ VPReplicateRecipe *EarliestLoad = Group[0];
----------------
fhahn wrote:
Just from the changes, it's not clear to me that this is NFC. Previosuly we would not hoist if there would be an aliasing store anywhere in the loop region, but now we just check between entry & last load.
If we would have a later aliasing store, then we would need to reload on each iteration, no? There may be something that prevents this case from happening, but would be good to clarify
https://github.com/llvm/llvm-project/pull/179506
More information about the llvm-commits
mailing list