Skip to content

[mlir][spirv] Handle a missing case when inlining spirv.ReturnValue #80733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
22 changes: 22 additions & 0 deletions mlir/test/Dialect/SPIRV/Transforms/inlining.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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.