Skip to content

Commit f2849fe

Browse files
authored
Fix RemoveDeadValues: Bail out early when there are no terminators (llvm#133316)
Fixes: llvm#131765
1 parent 1d9d465 commit f2849fe

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

mlir/lib/Transforms/RemoveDeadValues.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ static void processFuncOp(FunctionOpInterface funcOp, Operation *module,
305305
// since it forwards only to non-live value(s) (%1#1).
306306
Operation *lastReturnOp = funcOp.back().getTerminator();
307307
size_t numReturns = lastReturnOp->getNumOperands();
308+
if (numReturns == 0)
309+
return;
308310
BitVector nonLiveRets(numReturns, true);
309311
for (SymbolTable::SymbolUse use : uses) {
310312
Operation *callOp = use.getUser();

mlir/test/Transforms/remove-dead-values.mlir

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,21 @@ func.func @kernel(%arg0: memref<18xf32>) {
446446

447447
// -----
448448

449+
450+
// CHECK-LABEL: llvm_unreachable
451+
// CHECK-LABEL: @fn_with_llvm_unreachable
452+
// CHECK-LABEL: @main
453+
// CHECK: llvm.return
454+
module @llvm_unreachable {
455+
func.func private @fn_with_llvm_unreachable(%arg0: tensor<4x4xf32>) -> tensor<4x4xi1> {
456+
llvm.unreachable
457+
}
458+
func.func private @main(%arg0: tensor<4x4xf32>) {
459+
%0 = call @fn_with_llvm_unreachable(%arg0) : (tensor<4x4xf32>) -> tensor<4x4xi1>
460+
llvm.return
461+
}
462+
}
463+
449464
// CHECK: func.func private @no_block_func_declaration()
450465
func.func private @no_block_func_declaration() -> ()
451466

0 commit comments

Comments
 (0)