[llvm] [VPlan] Lower safe uniform load to unconditional scalar load (PR #216767)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 13:50:52 PDT 2026


================
@@ -5499,6 +5480,29 @@ void VPlanTransforms::makeMemOpWideningDecisions(VPlan &Plan, VFRange &Range,
         return ReplaceWith(VPI, StoreR);
       });
 
+  // Lower safe uniform (potentially masked) loads to unconditional scalar
+  // loads.
+  VPlanTransforms::runPass(
+      "lowerSafeUniformLoads", ProcessSubset, Plan, [&](VPInstruction *VPI) {
+        if (VPI->getOpcode() != Instruction::Load)
+          return false;
+        VPValue *Addr = VPI->getOperand(0);
+        if (!vputils::isUniformAcrossVFsAndUFs(Addr))
+          return false;
+        auto &LI = cast<LoadInst>(*VPI->getUnderlyingInstr());
+        Value *Underlying = Addr->getUnderlyingValue();
+        if (!Underlying || !isSafeToLoadUnconditionally(
+                               Underlying, LI.getType(), LI.getAlign(),
+                               Plan.getDataLayout(), &LI,
+                               /*AC=*/nullptr, /*DT=*/nullptr, &CostCtx.TLI))
+          return false;
----------------
fhahn wrote:

Yep we should not be using IR based analysis at this point, but `isSafeToLoadUnconditionally` in particular is not intended to be used for this kind of analysis in general I think.

It looks like the alternative approach already is using the Loads.h helper https://github.com/llvm/llvm-project/pull/217564/changes

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


More information about the llvm-commits mailing list