Skip to content

[AMDGPU] Change handling of unsupported non-compute shaders with HSA #126798

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 4 commits into from
Feb 13, 2025
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
5 changes: 3 additions & 2 deletions llvm/lib/Target/AMDGPU/SIISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2822,12 +2822,13 @@ SDValue SITargetLowering::LowerFormalArguments(
const Function &Fn = MF.getFunction();
FunctionType *FType = MF.getFunction().getFunctionType();
SIMachineFunctionInfo *Info = MF.getInfo<SIMachineFunctionInfo>();
bool IsError = false;

if (Subtarget->isAmdHsaOS() && AMDGPU::isGraphics(CallConv)) {
DiagnosticInfoUnsupported NoGraphicsHSA(
Fn, "unsupported non-compute shaders with HSA", DL.getDebugLoc());
DAG.getContext()->diagnose(NoGraphicsHSA);
return DAG.getEntryNode();
IsError = true;
}

SmallVector<ISD::InputArg, 16> Splits;
Expand Down Expand Up @@ -2936,7 +2937,7 @@ SDValue SITargetLowering::LowerFormalArguments(

for (unsigned i = 0, e = Ins.size(), ArgIdx = 0; i != e; ++i) {
const ISD::InputArg &Arg = Ins[i];
if (Arg.isOrigArg() && Skipped[Arg.getOrigArgIndex()]) {
if ((Arg.isOrigArg() && Skipped[Arg.getOrigArgIndex()]) || IsError) {
InVals.push_back(DAG.getUNDEF(Arg.VT));
continue;
}
Expand Down
64 changes: 55 additions & 9 deletions llvm/test/CodeGen/AMDGPU/no-hsa-graphics-shaders.ll
Original file line number Diff line number Diff line change
@@ -1,19 +1,65 @@
; RUN: not llc -mtriple=amdgcn-unknown-amdhsa < %s 2>&1 | FileCheck %s
; RUN: not llc -mtriple=amdgcn-unknown-amdhsa -O0 -filetype=null < %s 2>&1 | FileCheck %s

; CHECK: in function pixel_s{{.*}}: unsupported non-compute shaders with HSA
Copy link
Contributor

Choose a reason for hiding this comment

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

We must maintain test coverage for error cases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to adapt the test, but FileCheck didn't seem to be able to check for the LLVM ERROR ... line (first line of output/stderr). So I assumed that it may not be possible to check for fatal errors. But now the situation is different anyway :)

Copy link
Member

Choose a reason for hiding this comment

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

Did you try not --crash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, in the meantime, I found this by searching through similar tests (basically grep -rl "LLVM ERROR" ^^). However, it still somehow skipped the first line, even though stderr was redirected to stdout. But this is no longer an issue since I removed the fatal error again, based on the feedback I received here.

define amdgpu_ps void @pixel_shader() #0 {
@I = global i32 42
@P = global ptr @I

; CHECK: error: <unknown>:0:0: in function pixel_shader_zero_args void (): unsupported non-compute shaders with HSA
; CHECK: error: <unknown>:0:0: in function pixel_shader_one_arg void (ptr): unsupported non-compute shaders with HSA
; CHECK: error: <unknown>:0:0: in function pixel_shader_two_args void (ptr, i32): unsupported non-compute shaders with HSA
; CHECK: error: <unknown>:0:0: in function vertex_shader_zero_args void (): unsupported non-compute shaders with HSA
; CHECK: error: <unknown>:0:0: in function vertex_shader_one_arg void (ptr): unsupported non-compute shaders with HSA
; CHECK: error: <unknown>:0:0: in function vertex_shader_two_args void (ptr, i32): unsupported non-compute shaders with HSA
; CHECK: error: <unknown>:0:0: in function geometry_shader_zero_args void (): unsupported non-compute shaders with HSA
; CHECK: error: <unknown>:0:0: in function geometry_shader_one_arg void (ptr): unsupported non-compute shaders with HSA
; CHECK: error: <unknown>:0:0: in function geometry_shader_two_args void (ptr, i32): unsupported non-compute shaders with HSA

define amdgpu_ps void @pixel_shader_zero_args() {
%i = load i32, ptr @I
store i32 %i, ptr @P
ret void
}

define amdgpu_ps void @pixel_shader_one_arg(ptr %p) {
%i = load i32, ptr @I
store i32 %i, ptr %p
ret void
}

; CHECK: in function vertex_s{{.*}}: unsupported non-compute shaders with HSA
define amdgpu_vs void @vertex_shader() #0 {
define amdgpu_ps void @pixel_shader_two_args(ptr %p, i32 %i) {
store i32 %i, ptr %p
ret void
}

; CHECK: in function geometry_s{{.*}}: unsupported non-compute shaders with HSA
define amdgpu_gs void @geometry_shader() #0 {
define amdgpu_vs void @vertex_shader_zero_args() {
%i = load i32, ptr @I
store i32 %i, ptr @P
ret void
}

!llvm.module.flags = !{!0}
!0 = !{i32 1, !"amdhsa_code_object_version", i32 400}
define amdgpu_vs void @vertex_shader_one_arg(ptr %p) {
%i = load i32, ptr @I
store i32 %i, ptr %p
ret void
}

define amdgpu_vs void @vertex_shader_two_args(ptr %p, i32 %i) {
store i32 %i, ptr %p
ret void
}

define amdgpu_gs void @geometry_shader_zero_args() {
%i = load i32, ptr @I
store i32 %i, ptr @P
ret void
}

define amdgpu_gs void @geometry_shader_one_arg(ptr %p) {
%i = load i32, ptr @I
store i32 %i, ptr %p
ret void
}

define amdgpu_gs void @geometry_shader_two_args(ptr %p, i32 %i) {
store i32 %i, ptr %p
ret void
}