[llvm] [VPlan] Lower safe uniform load to unconditional scalar load (Alt. approach) (PR #217564)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 27 00:06:33 PDT 2026
================
@@ -5852,3 +5823,36 @@ void VPlanTransforms::convertToStridedAccesses(VPlan &Plan,
}
}
}
+
+void VPlanTransforms::lowerSafeUniformLoads(VPlan &Plan,
+ const TargetLibraryInfo &TLI) {
+ for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(
+ vp_depth_first_deep(Plan.getEntry()))) {
+ for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
+ auto *UniformGather = dyn_cast<VPWidenLoadRecipe>(&R);
+ if (!UniformGather ||
+ !vputils::isUniformAcrossVFsAndUFs(UniformGather->getAddr()))
+ continue;
+
+ auto &LI = cast<LoadInst>(UniformGather->getIngredient());
+ VPValue *Addr = UniformGather->getAddr();
+ Value *Underlying = Addr->getUnderlyingValue();
+ if (!Underlying ||
+ !isDereferenceableAndAlignedPointer(
+ Underlying, LI.getType(), LI.getAlign(),
+ SimplifyQuery(Plan.getDataLayout(), &TLI, /*DT=*/nullptr,
+ /*AC=*/nullptr, &LI)))
+ continue;
+ DebugLoc DbgLoc = UniformGather->getDebugLoc();
+ auto *ScalarLoad =
+ new VPReplicateRecipe(&LI, Addr, /*IsSingleScalar=*/true,
+ /*Mask=*/nullptr, {}, *UniformGather, DbgLoc);
+ ScalarLoad->insertBefore(UniformGather);
+ auto *Broadcast =
+ new VPInstruction(VPInstruction::Broadcast, {ScalarLoad});
+ Broadcast->insertBefore(UniformGather);
----------------
artagnon wrote:
```suggestion
VPBuilder Builder(UniformGather);
VPSingleDefRecipe *ScalarLoad =
Builder.createSingleScalarOp(Instruction::Load, Addr,
/*Mask=*/nullptr, {}, *UniformGather, DbgLoc, &LI);
VPInstruction *Broadcast =
Builder.createNaryOp(VPInstruction::Broadcast, ScalarLoad, DbgLoc);
```
https://github.com/llvm/llvm-project/pull/217564
More information about the llvm-commits
mailing list