Skip to content

Commit 4cb1430

Browse files
authored
[mlir][spirv] Fix a crash in spirv::ISubOp::fold (#131570)
This PR fixes a crash if `spirv.ISub` is not integer type. Fixes #131283.
1 parent 745e167 commit 4cb1430

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ OpFoldResult spirv::IMulOp::fold(FoldAdaptor adaptor) {
476476
OpFoldResult spirv::ISubOp::fold(FoldAdaptor adaptor) {
477477
// x - x = 0
478478
if (getOperand1() == getOperand2())
479-
return Builder(getContext()).getIntegerAttr(getType(), 0);
479+
return Builder(getContext()).getZeroAttr(getType());
480480

481481
// According to the SPIR-V spec:
482482
//

mlir/test/Dialect/SPIRV/Transforms/canonicalize.mlir

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,13 @@ func.func @isub_x_x(%arg0: i32) -> i32 {
593593
return %0: i32
594594
}
595595

596+
// CHECK-LABEL: @isub_vector_x_x
597+
func.func @isub_vector_x_x(%arg0: vector<3xi32>) -> vector<3xi32> {
598+
// CHECK: spirv.Constant dense<0>
599+
%0 = spirv.ISub %arg0, %arg0: vector<3xi32>
600+
return %0: vector<3xi32>
601+
}
602+
596603
// CHECK-LABEL: @const_fold_scalar_isub_normal
597604
func.func @const_fold_scalar_isub_normal() -> (i32, i32, i32) {
598605
%c5 = spirv.Constant 5 : i32

0 commit comments

Comments
 (0)