[Mlir-commits] [mlir] [mlir][spirv] Mark `spirv.ReturnValue` as `ReturnLike` (PR #174114)

Jakub Kuderski llvmlistbot at llvm.org
Wed Dec 31 13:28:31 PST 2025


https://github.com/kuhar created https://github.com/llvm/llvm-project/pull/174114

This makes the dead value analysis consider it live.

Fixes: https://github.com/llvm/llvm-project/issues/173563

>From c896e9cc75c943b25dc4df8f05cd468ecda003e9 Mon Sep 17 00:00:00 2001
From: Jakub Kuderski <jakub at nod-labs.com>
Date: Wed, 31 Dec 2025 16:26:17 -0500
Subject: [PATCH] [mlir][spirv] Mark `spirv.ReturnValue` as `ReturnLike`

This makes the dead value analysis consider it live.

Fixes: https://github.com/llvm/llvm-project/issues/173563
---
 .../Dialect/SPIRV/IR/SPIRVControlFlowOps.td     |  4 ++--
 mlir/test/Dialect/SPIRV/IR/return-ops.mlir      | 17 +++++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
 create mode 100644 mlir/test/Dialect/SPIRV/IR/return-ops.mlir

diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td
index 27c9add7d43af..072d210afbfb9 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVControlFlowOps.td
@@ -507,7 +507,7 @@ def SPIRV_MergeOp : SPIRV_Op<"mlir.merge", [
 // -----
 
 def SPIRV_ReturnOp : SPIRV_Op<"Return", [InFunctionScope, Pure,
-                                     Terminator]> {
+                                         ReturnLike, Terminator]> {
   let summary = "Return with no value from a function with void return type.";
 
   let description = [{
@@ -546,7 +546,7 @@ def SPIRV_UnreachableOp : SPIRV_Op<"Unreachable", [InFunctionScope, Terminator]>
 // -----
 
 def SPIRV_ReturnValueOp : SPIRV_Op<"ReturnValue", [InFunctionScope, Pure,
-                                               Terminator]> {
+                                                   ReturnLike, Terminator]> {
   let summary = "Return a value from a function.";
 
   let description = [{
diff --git a/mlir/test/Dialect/SPIRV/IR/return-ops.mlir b/mlir/test/Dialect/SPIRV/IR/return-ops.mlir
new file mode 100644
index 0000000000000..2f945b24d24fd
--- /dev/null
+++ b/mlir/test/Dialect/SPIRV/IR/return-ops.mlir
@@ -0,0 +1,17 @@
+// RUN: mlir-opt %s --remove-dead-values | FileCheck %s
+
+// Make sure that the return value op is considered as a return-like op and
+// remains live.
+
+// CHECK-LABEL: @preserve_return_value
+// CHECK-SAME:    (%[[ARG0:.*]]: vector<2xi32>, %[[ARG1:.*]]: vector<2xi32>) -> vector<2xi32>
+// CHECK-NEXT:    %[[BITCAST0:.*]] = spirv.Bitcast %[[ARG1]] : vector<2xi32> to vector<2xf32>
+// CHECK-NEXT:    %[[BITCAST1:.*]] = spirv.Bitcast %[[BITCAST0]] : vector<2xf32> to vector<2xi32>
+// CHECK-NEXT:    spirv.ReturnValue %[[BITCAST1]] : vector<2xi32>
+
+spirv.func @preserve_return_value(%arg0: vector<2xi32>, %arg1: vector<2xi32>) -> vector<2xi32> "None" {
+  %0 = spirv.Bitcast %arg0 : vector<2xi32> to vector<2xf32>
+  %1 = spirv.Bitcast %arg1 : vector<2xi32> to vector<2xf32>
+  %2 = spirv.Bitcast %1 : vector<2xf32> to vector<2xi32>
+  spirv.ReturnValue %2 : vector<2xi32>
+}



More information about the Mlir-commits mailing list