Skip to content

Commit 5aa741d

Browse files
authored
[mlir][SPIRVToLLVM] Erase empty spirv.mlir.loop in LoopPattern (#113527)
This PR erases `spirv.mlir.loop` with an empty region in `LoopPattern`, resolving a crash. Fixes #113404.
1 parent 8f9fc6c commit 5aa741d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,12 @@ class LoopPattern : public SPIRVToLLVMConversion<spirv::LoopOp> {
11481148
if (loopOp.getLoopControl() != spirv::LoopControl::None)
11491149
return failure();
11501150

1151+
// `spirv.mlir.loop` with empty region is redundant and should be erased.
1152+
if (loopOp.getBody().empty()) {
1153+
rewriter.eraseOp(loopOp);
1154+
return success();
1155+
}
1156+
11511157
Location loc = loopOp.getLoc();
11521158

11531159
// Split the current block after `spirv.mlir.loop`. The remaining ops will

mlir/test/Conversion/SPIRVToLLVM/control-flow-ops-to-llvm.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ spirv.module Logical GLSL450 {
8686
//===----------------------------------------------------------------------===//
8787

8888
spirv.module Logical GLSL450 {
89+
// CHECK-LABEL: @empty_loop
90+
spirv.func @empty_loop() "None" {
91+
// CHECK: llvm.return
92+
spirv.mlir.loop {
93+
}
94+
spirv.Return
95+
}
96+
8997
// CHECK-LABEL: @infinite_loop
9098
spirv.func @infinite_loop(%count : i32) -> () "None" {
9199
// CHECK: llvm.br ^[[BB1:.*]]

0 commit comments

Comments
 (0)