[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 20 04:26:37 PDT 2026


================
@@ -5852,3 +5822,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 ||
+          !isSafeToLoadUnconditionally(Underlying, LI.getType(), LI.getAlign(),
+                                       Plan.getDataLayout(), &LI,
+                                       /*AC=*/nullptr, /*DT=*/nullptr, &TLI))
+        continue;
+      DebugLoc DbgLoc = UniformGather->getDebugLoc();
+      auto *ScalarLoad =
+          new VPReplicateRecipe(&LI, {Addr}, /*IsSingleScalar=*/true,
----------------
artagnon wrote:

```suggestion
          new VPReplicateRecipe(&LI, Addr, /*IsSingleScalar=*/true,
```

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


More information about the llvm-commits mailing list