[llvm-branch-commits] [llvm] [llubi] Add support for vp.strided.load and vp.strided.store (PR #241715)

Luke Lau via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Nov 13 00:04:12 PST 2026


================
@@ -1075,6 +1075,35 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
                                         std::move(Data), Mode, IsStore);
   }
 
+  /// Implements llvm.experimental.vp.strided.{load,store} as a vp.gather or
+  /// vp.scatter of the pointers <Ptr, Ptr + Stride, Ptr + 2 * Stride, ...>.
+  /// \p Stride is signed and the arithmetic wraps in the pointer index type. An
+  /// align attribute on the base pointer applies to every lane's pointer.
+  AnyValue callVPStridedLoadStoreIntrinsic(CallBase &CB, const AnyValue &Ptr,
+                                           const AnyValue &Stride,
+                                           const AnyValue &Mask,
+                                           const AnyValue &EVL, AnyValue Data,
+                                           bool IsStore) {
+    const unsigned IndexBW =
+        DL.getIndexTypeSizeInBits(CB.getArgOperand(IsStore ? 1 : 0)->getType());
+    std::vector<AnyValue> LanePtrs(Mask.asAggregate().size(),
+                                   AnyValue::poison());
+    if (!Stride.isPoison()) {
+      const APInt StrideIdx = Stride.asInteger().sextOrTrunc(IndexBW);
+      for (auto [I, LanePtr] : enumerate(LanePtrs)) {
+        AnyValue AccumulatedOffset = AnyValue::poison();
+        LanePtr = Ctx.computePtrAdd(Ptr, StrideIdx * APInt(IndexBW, I),
+                                    GEPNoWrapFlags::none(), AccumulatedOffset);
+      }
+    }
+    AnyValue Ptrs(std::move(LanePtrs));
+    if (MaybeAlign Alignment = CB.getParamAlign(IsStore ? 1 : 0))
----------------
lukel97 wrote:

I've fixed this in 29bc10124270ab6db8f2527da83b79d47b42b801, so now:

a) the base ptr must be align attribute aligned, or default ABI alignment aligned
b) subsequent lane pointers have no alignment (align 1)

But this means the RISCV lowering is wrong since `vp.strided.load.nxv2i32(ptr %p, stride=1)` is now well defined. The RISC-V backend will lower this to a `vlse.v` on 32 bit integers with a stride of 1 byte, which will trap without "+unaligned-vector-mem".

This isn't an issue today though because the loop vectorizer + SLP will check `isLegalStridedLoadStore` before emitting these unaligned strides, which queries for `+unaligned-vector-mem`. Something to fix on the RISC-V backend.

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


More information about the llvm-branch-commits mailing list