Skip to content

Conversation

@hiraditya
Copy link
Collaborator

Fixes: #131765

@hiraditya hiraditya requested a review from srishti-pm March 27, 2025 21:08
@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Mar 27, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 27, 2025

@llvm/pr-subscribers-mlir-core

@llvm/pr-subscribers-mlir

Author: AdityaK (hiraditya)

Changes

Fixes: #131765


Full diff: https://github.com/llvm/llvm-project/pull/133316.diff

2 Files Affected:

  • (modified) mlir/lib/Transforms/RemoveDeadValues.cpp (+2)
  • (modified) mlir/test/Transforms/remove-dead-values.mlir (+15)
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() -> ()
 

Copy link
Contributor

@srishti-pm srishti-pm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hiraditya hiraditya merged commit f2849fe into llvm:main Mar 27, 2025
14 checks passed
@hiraditya hiraditya deleted the mlir_dead branch March 27, 2025 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mlir:core MLIR Core Infrastructure mlir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MLIR] Function call cranshed when using -remove-dead-values pass: Assertion `Idx < Size && "Out-of-bounds Bit access."' failed.

3 participants