[Mlir-commits] [mlir] [mlir][spirv] Handle a missing case when inlining spirv.ReturnValue (PR #80733)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Feb 5 11:25:46 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-spirv

Author: Artem Tyurin (agentcooper)

<details>
<summary>Changes</summary>

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

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


2 Files Affected:

- (modified) mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp (+3-1) 
- (modified) mlir/test/Dialect/SPIRV/Transforms/inlining.mlir (+22) 


``````````diff
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
index db26fa81790d19..e914f46bdef643 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
@@ -95,7 +95,9 @@ struct SPIRVInlinerInterface : public DialectInlinerInterface {
       OpBuilder(op).create<spirv::BranchOp>(op->getLoc(), newDest);
       op->erase();
     } else if (auto retValOp = dyn_cast<spirv::ReturnValueOp>(op)) {
-      llvm_unreachable("unimplemented spirv.ReturnValue in inliner");
+      OpBuilder(op).create<spirv::BranchOp>(retValOp->getLoc(), newDest,
+                                            retValOp->getOperands());
+      op->erase();
     }
   }
 
diff --git a/mlir/test/Dialect/SPIRV/Transforms/inlining.mlir b/mlir/test/Dialect/SPIRV/Transforms/inlining.mlir
index 8d663b4edc4527..3aadb19ec15829 100644
--- a/mlir/test/Dialect/SPIRV/Transforms/inlining.mlir
+++ b/mlir/test/Dialect/SPIRV/Transforms/inlining.mlir
@@ -224,5 +224,27 @@ spirv.module Logical GLSL450 {
   spirv.ExecutionMode @inline_into_selection_region "LocalSize", 32, 1, 1
 }
 
+// -----
+
+spirv.module Logical GLSL450 {
+  // CHECK-LABEL: @foo
+  spirv.func @foo(%arg0: i32) -> i32 "None" {
+    // CHECK-NOT: spirv.FunctionCall
+    // CHECK-NEXT: spirv.Constant 1
+    %res = spirv.FunctionCall @bar(%arg0) : (i32) -> i32
+    spirv.ReturnValue %res : i32
+  }
+
+  spirv.func @bar(%arg1: i32) -> i32 "None" attributes {sym_visibility = "private"} {
+    %cst1_i32 = spirv.Constant 1 : i32
+    %0 = spirv.IEqual %arg1, %cst1_i32 : i32
+    spirv.BranchConditional %0, ^bb1(%cst1_i32 : i32), ^bb2
+  ^bb1(%1: i32):
+    spirv.ReturnValue %1 : i32
+  ^bb2:
+    spirv.ReturnValue %cst1_i32 : i32
+  }
+}
+
 // TODO: Add tests for inlining structured control flow into
 // structured control flow.

``````````

</details>


https://github.com/llvm/llvm-project/pull/80733


More information about the Mlir-commits mailing list