1 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -verify-machineinstrs < %s | FileCheck -check-prefix=GCN %s
2 ; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -amdgpu-fix-function-bitcasts < %s | FileCheck -check-prefix=OPT %s
4 ; GCN-LABEL: {{^}}test_bitcast_return_type_noinline:
6 ; GCN: s_add_u32 s{{[0-9]+}}, s{{[0-9]+}}, ret_i32_noinline@rel32@lo+4
7 ; GCN: s_addc_u32 s{{[0-9]+}}, s{{[0-9]+}}, ret_i32_noinline@rel32@hi+4
9 ; OPT-LABEL: @test_bitcast_return_type_noinline(
10 ; OPT: %val = call i32 @ret_i32_noinline()
11 ; OPT: bitcast i32 %val to float
12 define amdgpu_kernel void @test_bitcast_return_type_noinline() #0 {
13 %val = call float bitcast (i32()* @ret_i32_noinline to float()*)()
14 %op = fadd float %val, 1.0
15 store volatile float %op, float addrspace(1)* undef
19 ; GCN-LABEL: {{^}}test_bitcast_return_type_alwaysinline:
20 ; GCN-NOT: s_getpc_b64
21 ; GCN-NOT: s_add_u32 s{{[0-9]+}}, s{{[0-9]+}}, ret_i32_alwaysinline@rel32@lo+4
22 ; GCN-NOT: s_addc_u32 s{{[0-9]+}}, s{{[0-9]+}}, ret_i32_alwaysinline@rel32@hi+4
23 ; GCN-NOT: s_swappc_b64
24 ; OPT-LABEL: @test_bitcast_return_type_alwaysinline(
25 ; OPT: %val = call i32 @ret_i32_alwaysinline()
26 ; OPT: bitcast i32 %val to float
27 define amdgpu_kernel void @test_bitcast_return_type_alwaysinline() #0 {
28 %val = call float bitcast (i32()* @ret_i32_alwaysinline to float()*)()
29 %op = fadd float %val, 1.0
30 store volatile float %op, float addrspace(1)* undef
34 ; GCN-LABEL: {{^}}test_bitcast_argument_type:
36 ; GCN: s_add_u32 s{{[0-9]+}}, s{{[0-9]+}}, ident_i32@rel32@lo+4
37 ; GCN: s_addc_u32 s{{[0-9]+}}, s{{[0-9]+}}, ident_i32@rel32@hi+4
39 ; OPT-LABEL: @test_bitcast_argument_type(
40 ; OPT: %1 = bitcast float 2.000000e+00 to i32
41 ; OPT: %val = call i32 @ident_i32(i32 %1)
42 ; OPT-NOT: bitcast i32 %val to float
43 define amdgpu_kernel void @test_bitcast_argument_type() #0 {
44 %val = call i32 bitcast (i32(i32)* @ident_i32 to i32(float)*)(float 2.0)
46 store volatile i32 %op, i32 addrspace(1)* undef
50 ; GCN-LABEL: {{^}}test_bitcast_argument_and_return_types:
52 ; GCN: s_add_u32 s{{[0-9]+}}, s{{[0-9]+}}, ident_i32@rel32@lo+4
53 ; GCN: s_addc_u32 s{{[0-9]+}}, s{{[0-9]+}}, ident_i32@rel32@hi+4
55 ; OPT-LABEL: @test_bitcast_argument_and_return_types(
56 ; OPT: %1 = bitcast float 2.000000e+00 to i32
57 ; OPT: %val = call i32 @ident_i32(i32 %1)
58 ; OPT: bitcast i32 %val to float
59 define amdgpu_kernel void @test_bitcast_argument_and_return_types() #0 {
60 %val = call float bitcast (i32(i32)* @ident_i32 to float(float)*)(float 2.0)
61 %op = fadd float %val, 1.0
62 store volatile float %op, float addrspace(1)* undef
66 ; GCN-LABEL: {{^}}use_workitem_id_x:
68 ; GCN-NEXT: v_add_i32_e32 v0, vcc, v1, v0
69 ; GCN-NEXT: s_setpc_b64
70 define hidden i32 @use_workitem_id_x(i32 %arg0) #0 {
71 %id = call i32 @llvm.amdgcn.workitem.id.x()
72 %op = add i32 %id, %arg0
76 ; GCN-LABEL: {{^}}test_bitcast_use_workitem_id_x:
77 ; GCN: v_mov_b32_e32 v1, v0
79 ; GCN: s_add_u32 s{{[0-9]+}}, s{{[0-9]+}}, use_workitem_id_x@rel32@lo+4
80 ; GCN: s_addc_u32 s{{[0-9]+}}, s{{[0-9]+}}, use_workitem_id_x@rel32@hi+4
81 ; GCN: v_mov_b32_e32 v0, 9
84 ; OPT-LABEL: @use_workitem_id_x(
85 ; OPT: %val = call i32 @use_workitem_id_x(i32 9)
86 ; OPT: bitcast i32 %val to float
87 define amdgpu_kernel void @test_bitcast_use_workitem_id_x() #0 {
88 %val = call float bitcast (i32(i32)* @use_workitem_id_x to float(i32)*)(i32 9)
89 %op = fadd float %val, 1.0
90 store volatile float %op, float addrspace(1)* undef
94 ; GCN-LABEL: {{^}}test_invoke:
96 ; GCN: s_add_u32 s{{[0-9]+}}, s{{[0-9]+}}, ident_i32@rel32@lo+4
97 ; GCN: s_addc_u32 s{{[0-9]+}}, s{{[0-9]+}}, ident_i32@rel32@hi+4
99 ; OPT-LABEL: @test_invoke(
100 ; OPT: %1 = bitcast float 2.000000e+00 to i32
101 ; OPT: %val = invoke i32 @ident_i32(i32 %1)
102 ; OPT-NEXT: to label %continue unwind label %broken
103 ; OPT-LABEL: continue.split:
104 ; OPT: bitcast i32 %val to float
105 @_ZTIi = external global i8*
106 declare i32 @__gxx_personality_v0(...)
107 define amdgpu_kernel void @test_invoke() #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
108 %val = invoke float bitcast (i32(i32)* @ident_i32 to float(float)*)(float 2.0)
109 to label %continue unwind label %broken
112 landingpad { i8*, i32 } catch i8** @_ZTIi
116 %op = fadd float %val, 1.0
117 store volatile float %op, float addrspace(1)* undef
121 ; Callees appears last in source file to test that we still lower their
122 ; arguments before we lower any calls to them.
124 define hidden i32 @ret_i32_noinline() #0 {
128 define hidden i32 @ret_i32_alwaysinline() #1 {
132 define hidden i32 @ident_i32(i32 %i) #0 {
136 declare i32 @llvm.amdgcn.workitem.id.x() #2
138 attributes #0 = { nounwind noinline }
139 attributes #1 = { alwaysinline nounwind }
140 attributes #2 = { nounwind readnone speculatable }