[Mlir-commits] [mlir] Fix RemoveDeadValues: Bail out early when there are no terminators (PR #133316)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Mar 27 14:08:12 PDT 2025
https://github.com/hiraditya created https://github.com/llvm/llvm-project/pull/133316
Fixes: #131765
>From 3db58f8caa6d5abcc3c036f858201fc22c521a78 Mon Sep 17 00:00:00 2001
From: AdityaK <hiraditya at msn.com>
Date: Thu, 27 Mar 2025 21:05:38 +0000
Subject: [PATCH] Fix RemoveDeadValues: Bail out early when there are no
terminators
Fixes: #131765
---
mlir/lib/Transforms/RemoveDeadValues.cpp | 2 ++
mlir/test/Transforms/remove-dead-values.mlir | 15 +++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/mlir/lib/Transforms/RemoveDeadValues.cpp b/mlir/lib/Transforms/RemoveDeadValues.cpp
index c20c54551cdf8..92c05d87a002d 100644
--- a/mlir/lib/Transforms/RemoveDeadValues.cpp
+++ b/mlir/lib/Transforms/RemoveDeadValues.cpp
@@ -305,6 +305,8 @@ static void processFuncOp(FunctionOpInterface funcOp, Operation *module,
// since it forwards only to non-live value(s) (%1#1).
Operation *lastReturnOp = funcOp.back().getTerminator();
size_t numReturns = lastReturnOp->getNumOperands();
+ if (numReturns == 0)
+ return;
BitVector nonLiveRets(numReturns, true);
for (SymbolTable::SymbolUse use : uses) {
Operation *callOp = use.getUser();
diff --git a/mlir/test/Transforms/remove-dead-values.mlir b/mlir/test/Transforms/remove-dead-values.mlir
index e549926b90456..21d53b0742e07 100644
--- a/mlir/test/Transforms/remove-dead-values.mlir
+++ b/mlir/test/Transforms/remove-dead-values.mlir
@@ -446,6 +446,21 @@ func.func @kernel(%arg0: memref<18xf32>) {
// -----
+
+// CHECK-LABEL: llvm_unreachable
+// CHECK-LABEL: @fn_with_llvm_unreachable
+// CHECK-LABEL: @main
+// CHECK: llvm.return
+module @llvm_unreachable {
+ func.func private @fn_with_llvm_unreachable(%arg0: tensor<4x4xf32>) -> tensor<4x4xi1> {
+ llvm.unreachable
+ }
+ func.func private @main(%arg0: tensor<4x4xf32>) {
+ %0 = call @fn_with_llvm_unreachable(%arg0) : (tensor<4x4xf32>) -> tensor<4x4xi1>
+ llvm.return
+ }
+}
+
// CHECK: func.func private @no_block_func_declaration()
func.func private @no_block_func_declaration() -> ()
More information about the Mlir-commits
mailing list