[Mlir-commits] [mlir] [mlir][SPIR-V] Derive Aligned memory operand for PhysicalStorageBuffer in vector.load/store (PR #214200)

Igor Wodiany llvmlistbot at llvm.org
Mon Oct 19 13:48:14 PDT 2026


================
@@ -53,6 +53,49 @@ static int getNumBits(Type type) {
   return type.getIntOrFloatBitWidth();
 }
 
+namespace {
+struct MemoryRequirements {
+  spirv::MemoryAccessAttr memoryAccess;
+  IntegerAttr alignment;
+};
+} // namespace
+
+/// PhysicalStorageBuffer pointers always need Aligned, derived from pointee
+/// element size unless preferredAlignment is set. Other storage classes may
+/// omit it.
+static FailureOr<MemoryRequirements>
+calculateMemoryRequirements(Value accessedPtr, uint64_t preferredAlignment) {
+  if (preferredAlignment >= std::numeric_limits<uint32_t>::max())
+    return failure();
+
+  MLIRContext *ctx = accessedPtr.getContext();
+  auto ptrType = cast<spirv::PointerType>(accessedPtr.getType());
+  bool mayOmitAlignment =
+      !preferredAlignment &&
+      ptrType.getStorageClass() != spirv::StorageClass::PhysicalStorageBuffer;
+  if (mayOmitAlignment)
+    return MemoryRequirements{spirv::MemoryAccessAttr{}, IntegerAttr{}};
+
+  // PhysicalStorageBuffer pointers require Aligned. The vector pointer is a
+  // bitcast of a scalar element pointer, so only element alignment is known.
+  std::optional<int64_t> sizeInBytes;
+  Type pointeeType = ptrType.getPointeeType();
+  if (auto vecType = dyn_cast<VectorType>(pointeeType))
+    pointeeType = vecType.getElementType();
----------------
IgWod wrote:

nit: Could this use `getElementTypeOrSelf`? Or would it make it too general/it wouldn't work?

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


More information about the Mlir-commits mailing list