Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AMDGPU: Fix crashing on calls to C functions from graphics contexts
If we had one of the shader calling conventions calling a default calling convention callee, this would crash when the caller did not have anything to pass to the workitem ID. This is illegal, but we still need to produce something sensible. llvm-reduce likes to replace calls to intrinsics with calls to null or undef, so this does appear and is helpful to avoid hard erroring. Pass undef in this case, as already happened for the other implicit arguments. It might make sense to define the behavior here and pass null for the pointers, and -1 for the workitem ID. We do have extra bits in the workitem ID, so this wouldn't conflict with a valid value.
- Loading branch information
Showing
5 changed files
with
229 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; RUN: llc -mtriple=amdgcn--amdpal -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck -check-prefix=SDAG -enable-var-scope %s | ||
; RUN: llc -global-isel -mtriple=amdgcn--amdpal -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck -check-prefix=GISEL -enable-var-scope %s | ||
|
||
declare void @extern_c_func() | ||
|
||
define amdgpu_gfx void @gfx_func() { | ||
; SDAG-LABEL: gfx_func: | ||
; SDAG: ; %bb.0: | ||
; SDAG-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) | ||
; SDAG-NEXT: s_or_saveexec_b64 s[34:35], -1 | ||
; SDAG-NEXT: buffer_store_dword v40, off, s[0:3], s32 ; 4-byte Folded Spill | ||
; SDAG-NEXT: s_mov_b64 exec, s[34:35] | ||
; SDAG-NEXT: v_writelane_b32 v40, s33, 26 | ||
; SDAG-NEXT: v_writelane_b32 v40, s4, 0 | ||
; SDAG-NEXT: v_writelane_b32 v40, s5, 1 | ||
; SDAG-NEXT: v_writelane_b32 v40, s6, 2 | ||
; SDAG-NEXT: v_writelane_b32 v40, s7, 3 | ||
; SDAG-NEXT: v_writelane_b32 v40, s8, 4 | ||
; SDAG-NEXT: v_writelane_b32 v40, s9, 5 | ||
; SDAG-NEXT: v_writelane_b32 v40, s10, 6 | ||
; SDAG-NEXT: v_writelane_b32 v40, s11, 7 | ||
; SDAG-NEXT: v_writelane_b32 v40, s12, 8 | ||
; SDAG-NEXT: v_writelane_b32 v40, s13, 9 | ||
; SDAG-NEXT: v_writelane_b32 v40, s14, 10 | ||
; SDAG-NEXT: v_writelane_b32 v40, s15, 11 | ||
; SDAG-NEXT: v_writelane_b32 v40, s16, 12 | ||
; SDAG-NEXT: v_writelane_b32 v40, s17, 13 | ||
; SDAG-NEXT: v_writelane_b32 v40, s18, 14 | ||
; SDAG-NEXT: v_writelane_b32 v40, s19, 15 | ||
; SDAG-NEXT: v_writelane_b32 v40, s20, 16 | ||
; SDAG-NEXT: v_writelane_b32 v40, s21, 17 | ||
; SDAG-NEXT: s_mov_b32 s33, s32 | ||
; SDAG-NEXT: s_addk_i32 s32, 0x400 | ||
; SDAG-NEXT: v_writelane_b32 v40, s22, 18 | ||
; SDAG-NEXT: v_writelane_b32 v40, s23, 19 | ||
; SDAG-NEXT: s_mov_b64 s[36:37], s[30:31] | ||
; SDAG-NEXT: s_getpc_b64 s[30:31] | ||
; SDAG-NEXT: s_add_u32 s30, s30, extern_c_func@gotpcrel32@lo+4 | ||
; SDAG-NEXT: s_addc_u32 s31, s31, extern_c_func@gotpcrel32@hi+12 | ||
; SDAG-NEXT: v_writelane_b32 v40, s24, 20 | ||
; SDAG-NEXT: s_load_dwordx2 s[30:31], s[30:31], 0x0 | ||
; SDAG-NEXT: v_writelane_b32 v40, s25, 21 | ||
; SDAG-NEXT: v_writelane_b32 v40, s26, 22 | ||
; SDAG-NEXT: v_writelane_b32 v40, s27, 23 | ||
; SDAG-NEXT: v_writelane_b32 v40, s28, 24 | ||
; SDAG-NEXT: s_mov_b64 s[8:9], 0 | ||
; SDAG-NEXT: v_writelane_b32 v40, s29, 25 | ||
; SDAG-NEXT: s_waitcnt lgkmcnt(0) | ||
; SDAG-NEXT: s_swappc_b64 s[30:31], s[30:31] | ||
; SDAG-NEXT: v_readlane_b32 s29, v40, 25 | ||
; SDAG-NEXT: v_readlane_b32 s28, v40, 24 | ||
; SDAG-NEXT: v_readlane_b32 s27, v40, 23 | ||
; SDAG-NEXT: v_readlane_b32 s26, v40, 22 | ||
; SDAG-NEXT: v_readlane_b32 s25, v40, 21 | ||
; SDAG-NEXT: v_readlane_b32 s24, v40, 20 | ||
; SDAG-NEXT: v_readlane_b32 s23, v40, 19 | ||
; SDAG-NEXT: v_readlane_b32 s22, v40, 18 | ||
; SDAG-NEXT: v_readlane_b32 s21, v40, 17 | ||
; SDAG-NEXT: v_readlane_b32 s20, v40, 16 | ||
; SDAG-NEXT: v_readlane_b32 s19, v40, 15 | ||
; SDAG-NEXT: v_readlane_b32 s18, v40, 14 | ||
; SDAG-NEXT: v_readlane_b32 s17, v40, 13 | ||
; SDAG-NEXT: v_readlane_b32 s16, v40, 12 | ||
; SDAG-NEXT: v_readlane_b32 s15, v40, 11 | ||
; SDAG-NEXT: v_readlane_b32 s14, v40, 10 | ||
; SDAG-NEXT: v_readlane_b32 s13, v40, 9 | ||
; SDAG-NEXT: v_readlane_b32 s12, v40, 8 | ||
; SDAG-NEXT: v_readlane_b32 s11, v40, 7 | ||
; SDAG-NEXT: v_readlane_b32 s10, v40, 6 | ||
; SDAG-NEXT: v_readlane_b32 s9, v40, 5 | ||
; SDAG-NEXT: v_readlane_b32 s8, v40, 4 | ||
; SDAG-NEXT: v_readlane_b32 s7, v40, 3 | ||
; SDAG-NEXT: v_readlane_b32 s6, v40, 2 | ||
; SDAG-NEXT: v_readlane_b32 s5, v40, 1 | ||
; SDAG-NEXT: v_readlane_b32 s4, v40, 0 | ||
; SDAG-NEXT: s_addk_i32 s32, 0xfc00 | ||
; SDAG-NEXT: v_readlane_b32 s33, v40, 26 | ||
; SDAG-NEXT: s_or_saveexec_b64 s[30:31], -1 | ||
; SDAG-NEXT: buffer_load_dword v40, off, s[0:3], s32 ; 4-byte Folded Reload | ||
; SDAG-NEXT: s_mov_b64 exec, s[30:31] | ||
; SDAG-NEXT: s_waitcnt vmcnt(0) | ||
; SDAG-NEXT: s_setpc_b64 s[36:37] | ||
; | ||
; GISEL-LABEL: gfx_func: | ||
; GISEL: ; %bb.0: | ||
; GISEL-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) | ||
; GISEL-NEXT: s_or_saveexec_b64 s[34:35], -1 | ||
; GISEL-NEXT: buffer_store_dword v40, off, s[0:3], s32 ; 4-byte Folded Spill | ||
; GISEL-NEXT: s_mov_b64 exec, s[34:35] | ||
; GISEL-NEXT: v_writelane_b32 v40, s33, 26 | ||
; GISEL-NEXT: v_writelane_b32 v40, s4, 0 | ||
; GISEL-NEXT: v_writelane_b32 v40, s5, 1 | ||
; GISEL-NEXT: v_writelane_b32 v40, s6, 2 | ||
; GISEL-NEXT: v_writelane_b32 v40, s7, 3 | ||
; GISEL-NEXT: v_writelane_b32 v40, s8, 4 | ||
; GISEL-NEXT: v_writelane_b32 v40, s9, 5 | ||
; GISEL-NEXT: v_writelane_b32 v40, s10, 6 | ||
; GISEL-NEXT: v_writelane_b32 v40, s11, 7 | ||
; GISEL-NEXT: v_writelane_b32 v40, s12, 8 | ||
; GISEL-NEXT: v_writelane_b32 v40, s13, 9 | ||
; GISEL-NEXT: v_writelane_b32 v40, s14, 10 | ||
; GISEL-NEXT: v_writelane_b32 v40, s15, 11 | ||
; GISEL-NEXT: v_writelane_b32 v40, s16, 12 | ||
; GISEL-NEXT: v_writelane_b32 v40, s17, 13 | ||
; GISEL-NEXT: v_writelane_b32 v40, s18, 14 | ||
; GISEL-NEXT: v_writelane_b32 v40, s19, 15 | ||
; GISEL-NEXT: v_writelane_b32 v40, s20, 16 | ||
; GISEL-NEXT: v_writelane_b32 v40, s21, 17 | ||
; GISEL-NEXT: s_mov_b32 s33, s32 | ||
; GISEL-NEXT: s_addk_i32 s32, 0x400 | ||
; GISEL-NEXT: v_writelane_b32 v40, s22, 18 | ||
; GISEL-NEXT: v_writelane_b32 v40, s23, 19 | ||
; GISEL-NEXT: s_mov_b64 s[36:37], s[30:31] | ||
; GISEL-NEXT: s_getpc_b64 s[30:31] | ||
; GISEL-NEXT: s_add_u32 s30, s30, extern_c_func@gotpcrel32@lo+4 | ||
; GISEL-NEXT: s_addc_u32 s31, s31, extern_c_func@gotpcrel32@hi+12 | ||
; GISEL-NEXT: v_writelane_b32 v40, s24, 20 | ||
; GISEL-NEXT: s_load_dwordx2 s[30:31], s[30:31], 0x0 | ||
; GISEL-NEXT: v_writelane_b32 v40, s25, 21 | ||
; GISEL-NEXT: v_writelane_b32 v40, s26, 22 | ||
; GISEL-NEXT: v_writelane_b32 v40, s27, 23 | ||
; GISEL-NEXT: v_writelane_b32 v40, s28, 24 | ||
; GISEL-NEXT: s_mov_b64 s[8:9], s[4:5] | ||
; GISEL-NEXT: v_writelane_b32 v40, s29, 25 | ||
; GISEL-NEXT: s_waitcnt lgkmcnt(0) | ||
; GISEL-NEXT: s_swappc_b64 s[30:31], s[30:31] | ||
; GISEL-NEXT: v_readlane_b32 s29, v40, 25 | ||
; GISEL-NEXT: v_readlane_b32 s28, v40, 24 | ||
; GISEL-NEXT: v_readlane_b32 s27, v40, 23 | ||
; GISEL-NEXT: v_readlane_b32 s26, v40, 22 | ||
; GISEL-NEXT: v_readlane_b32 s25, v40, 21 | ||
; GISEL-NEXT: v_readlane_b32 s24, v40, 20 | ||
; GISEL-NEXT: v_readlane_b32 s23, v40, 19 | ||
; GISEL-NEXT: v_readlane_b32 s22, v40, 18 | ||
; GISEL-NEXT: v_readlane_b32 s21, v40, 17 | ||
; GISEL-NEXT: v_readlane_b32 s20, v40, 16 | ||
; GISEL-NEXT: v_readlane_b32 s19, v40, 15 | ||
; GISEL-NEXT: v_readlane_b32 s18, v40, 14 | ||
; GISEL-NEXT: v_readlane_b32 s17, v40, 13 | ||
; GISEL-NEXT: v_readlane_b32 s16, v40, 12 | ||
; GISEL-NEXT: v_readlane_b32 s15, v40, 11 | ||
; GISEL-NEXT: v_readlane_b32 s14, v40, 10 | ||
; GISEL-NEXT: v_readlane_b32 s13, v40, 9 | ||
; GISEL-NEXT: v_readlane_b32 s12, v40, 8 | ||
; GISEL-NEXT: v_readlane_b32 s11, v40, 7 | ||
; GISEL-NEXT: v_readlane_b32 s10, v40, 6 | ||
; GISEL-NEXT: v_readlane_b32 s9, v40, 5 | ||
; GISEL-NEXT: v_readlane_b32 s8, v40, 4 | ||
; GISEL-NEXT: v_readlane_b32 s7, v40, 3 | ||
; GISEL-NEXT: v_readlane_b32 s6, v40, 2 | ||
; GISEL-NEXT: v_readlane_b32 s5, v40, 1 | ||
; GISEL-NEXT: v_readlane_b32 s4, v40, 0 | ||
; GISEL-NEXT: s_addk_i32 s32, 0xfc00 | ||
; GISEL-NEXT: v_readlane_b32 s33, v40, 26 | ||
; GISEL-NEXT: s_or_saveexec_b64 s[30:31], -1 | ||
; GISEL-NEXT: buffer_load_dword v40, off, s[0:3], s32 ; 4-byte Folded Reload | ||
; GISEL-NEXT: s_mov_b64 exec, s[30:31] | ||
; GISEL-NEXT: s_waitcnt vmcnt(0) | ||
; GISEL-NEXT: s_setpc_b64 s[36:37] | ||
call void @extern_c_func() | ||
ret void | ||
} |