[Mlir-commits] [mlir] [mlir][SPIR-V] Use converted vector type in VectorStoreOpConverter (PR #202962)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Jun 10 06:06:46 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-spirv
Author: Arseniy Obolenskiy (aobolensk)
<details>
<summary>Changes</summary>
Mirror VectorLoadOpConverter implementation and fix the crash
Convert the vector type before building the bitcast pointer so emulated element types (like index) do not produce type mismatch
---
Full diff: https://github.com/llvm/llvm-project/pull/202962.diff
2 Files Affected:
- (modified) mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp (+7-1)
- (modified) mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir (+13)
``````````diff
diff --git a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
index 921075736e97b..423f2840851d4 100644
--- a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
+++ b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
@@ -824,7 +824,13 @@ struct VectorStoreOpConverter final
spirv::StorageClass storageClass = attr.getValue();
auto vectorType = storeOp.getVectorType();
- auto vectorPtrType = spirv::PointerType::get(vectorType, storageClass);
+ // Use the converted vector type instead of original (single element vector
+ // would get converted to scalar).
+ auto spirvVectorType = typeConverter.convertType(vectorType);
+ if (!spirvVectorType)
+ return rewriter.notifyMatchFailure(storeOp, "unsupported vector type");
+
+ auto vectorPtrType = spirv::PointerType::get(spirvVectorType, storageClass);
// For single element vectors, we don't need to bitcast the access chain to
// the original vector type. Both is going to be the same, a pointer
diff --git a/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir b/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir
index 48a1298bc4877..152d32a81133d 100644
--- a/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir
+++ b/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir
@@ -1211,6 +1211,19 @@ func.func @vector_store_2d(%arg0 : memref<4x4xf32, #spirv.storage_class<StorageB
return
}
+// CHECK-LABEL: @vector_store_index
+// CHECK-SAME: (%[[ARG0:.*]]: memref<4xindex, #spirv.storage_class<StorageBuffer>>
+// CHECK-SAME: %[[ARG1:.*]]: vector<4xindex>
+// CHECK: %[[S0:.+]] = builtin.unrealized_conversion_cast %[[ARG0]] : memref<4xindex, #spirv.storage_class<StorageBuffer>> to !spirv.ptr<!spirv.struct<(!spirv.array<4 x i32, stride=4> [0])>, StorageBuffer>
+// CHECK: %[[S1:.+]] = builtin.unrealized_conversion_cast %[[ARG1]] : vector<4xindex> to vector<4xi32>
+// CHECK: %[[S5:.+]] = spirv.Bitcast %{{.+}} : !spirv.ptr<i32, StorageBuffer> to !spirv.ptr<vector<4xi32>, StorageBuffer>
+// CHECK: spirv.Store "StorageBuffer" %[[S5]], %[[S1]] : vector<4xi32>
+func.func @vector_store_index(%arg0 : memref<4xindex, #spirv.storage_class<StorageBuffer>>, %arg1 : vector<4xindex>) {
+ %idx = arith.constant 0 : index
+ vector.store %arg1, %arg0[%idx] : memref<4xindex, #spirv.storage_class<StorageBuffer>>, vector<4xindex>
+ return
+}
+
} // end module
// -----
``````````
</details>
https://github.com/llvm/llvm-project/pull/202962
More information about the Mlir-commits
mailing list