-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[mlir][vector][spirv] Fix a crash in VectorLoadOpConverter
#149964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This PR adds null check for `spirvVectorType` in VectorLoadOpConverter to prevent a crash.
|
@llvm/pr-subscribers-mlir Author: Longsheng Mou (CoTinker) ChangesThis PR adds null check for Full diff: https://github.com/llvm/llvm-project/pull/149964.diff 2 Files Affected:
diff --git a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
index 750ce85049409..06b19335f2aed 100644
--- a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
+++ b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
@@ -793,6 +793,9 @@ struct VectorLoadOpConverter final
// 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(loadOp, "unsupported vector type");
+
auto vectorPtrType = spirv::PointerType::get(spirvVectorType, storageClass);
// For single element vectors, we don't need to bitcast the access chain to
diff --git a/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir b/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir
index 44941f0d0ac5d..f43a41a0af2f4 100644
--- a/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir
+++ b/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir
@@ -1161,3 +1161,15 @@ func.func @vector_store_2d(%arg0 : memref<4x4xf32, #spirv.storage_class<StorageB
}
} // end module
+
+// -----
+
+// Ensure the case without module attributes not crash.
+
+// CHECK-LABEL: @vector_load
+// CHECK: vector.load
+func.func @vector_load(%arg0 : memref<4xf32, #spirv.storage_class<StorageBuffer>>) -> vector<4xf32> {
+ %idx = arith.constant 0 : index
+ %0 = vector.load %arg0[%idx] : memref<4xf32, #spirv.storage_class<StorageBuffer>>, vector<4xf32>
+ return %0: vector<4xf32>
+}
|
|
@llvm/pr-subscribers-mlir-spirv Author: Longsheng Mou (CoTinker) ChangesThis PR adds null check for Full diff: https://github.com/llvm/llvm-project/pull/149964.diff 2 Files Affected:
diff --git a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
index 750ce85049409..06b19335f2aed 100644
--- a/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
+++ b/mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
@@ -793,6 +793,9 @@ struct VectorLoadOpConverter final
// 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(loadOp, "unsupported vector type");
+
auto vectorPtrType = spirv::PointerType::get(spirvVectorType, storageClass);
// For single element vectors, we don't need to bitcast the access chain to
diff --git a/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir b/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir
index 44941f0d0ac5d..f43a41a0af2f4 100644
--- a/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir
+++ b/mlir/test/Conversion/VectorToSPIRV/vector-to-spirv.mlir
@@ -1161,3 +1161,15 @@ func.func @vector_store_2d(%arg0 : memref<4x4xf32, #spirv.storage_class<StorageB
}
} // end module
+
+// -----
+
+// Ensure the case without module attributes not crash.
+
+// CHECK-LABEL: @vector_load
+// CHECK: vector.load
+func.func @vector_load(%arg0 : memref<4xf32, #spirv.storage_class<StorageBuffer>>) -> vector<4xf32> {
+ %idx = arith.constant 0 : index
+ %0 = vector.load %arg0[%idx] : memref<4xf32, #spirv.storage_class<StorageBuffer>>, vector<4xf32>
+ return %0: vector<4xf32>
+}
|
kuhar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks a lot.
…9964) This PR adds null check for `spirvVectorType` in VectorLoadOpConverter to prevent a crash. Fixes llvm#149956.
This PR adds null check for
spirvVectorTypein VectorLoadOpConverter to prevent a crash. Fixes #149956.