Skip to content

Commit 9a5fb74

Browse files
authored
[mlir][spirv] Handle a missing case when inlining spirv.ReturnValue (#80733)
Fixes #73285.
1 parent c1ac2cf commit 9a5fb74

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ struct SPIRVInlinerInterface : public DialectInlinerInterface {
9595
OpBuilder(op).create<spirv::BranchOp>(op->getLoc(), newDest);
9696
op->erase();
9797
} else if (auto retValOp = dyn_cast<spirv::ReturnValueOp>(op)) {
98-
llvm_unreachable("unimplemented spirv.ReturnValue in inliner");
98+
OpBuilder(op).create<spirv::BranchOp>(retValOp->getLoc(), newDest,
99+
retValOp->getOperands());
100+
op->erase();
99101
}
100102
}
101103

mlir/test/Dialect/SPIRV/Transforms/inlining.mlir

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,5 +224,27 @@ spirv.module Logical GLSL450 {
224224
spirv.ExecutionMode @inline_into_selection_region "LocalSize", 32, 1, 1
225225
}
226226

227+
// -----
228+
229+
spirv.module Logical GLSL450 {
230+
// CHECK-LABEL: @foo
231+
spirv.func @foo(%arg0: i32) -> i32 "None" {
232+
// CHECK-NOT: spirv.FunctionCall
233+
// CHECK-NEXT: spirv.Constant 1
234+
%res = spirv.FunctionCall @bar(%arg0) : (i32) -> i32
235+
spirv.ReturnValue %res : i32
236+
}
237+
238+
spirv.func @bar(%arg1: i32) -> i32 "None" attributes {sym_visibility = "private"} {
239+
%cst1_i32 = spirv.Constant 1 : i32
240+
%0 = spirv.IEqual %arg1, %cst1_i32 : i32
241+
spirv.BranchConditional %0, ^bb1(%cst1_i32 : i32), ^bb2
242+
^bb1(%1: i32):
243+
spirv.ReturnValue %1 : i32
244+
^bb2:
245+
spirv.ReturnValue %cst1_i32 : i32
246+
}
247+
}
248+
227249
// TODO: Add tests for inlining structured control flow into
228250
// structured control flow.

0 commit comments

Comments
 (0)