blob: c165e057063060fdf0c98654100802e5c79ddd9a [file] [log] [blame]
Eli Benderskya7b66792014-03-24 16:52:30 +00001; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s
2
3; Checks how NVPTX lowers alloca buffers and their passing to functions.
4;
5; Produced with the following CUDA code:
6; extern "C" __attribute__((device)) void callee(float* f, char* buf);
7;
8; extern "C" __attribute__((global)) void kernel_func(float* a) {
9; char buf[4 * sizeof(float)];
10; *(reinterpret_cast<float*>(&buf[0])) = a[0];
11; *(reinterpret_cast<float*>(&buf[1])) = a[1];
12; *(reinterpret_cast<float*>(&buf[2])) = a[2];
13; *(reinterpret_cast<float*>(&buf[3])) = a[3];
14; callee(a, buf);
15; }
16
17; CHECK: .visible .entry kernel_func
18define void @kernel_func(float* %a) {
19entry:
20 %buf = alloca [16 x i8], align 4
21
22; CHECK: .local .align 4 .b8 __local_depot0[16]
Jingyue Wu9c711502015-06-24 20:20:16 +000023; CHECK: mov.u64 %SPL
Eli Benderskya7b66792014-03-24 16:52:30 +000024
Justin Holewinski3e037d92014-07-16 16:26:58 +000025; CHECK: ld.param.u64 %rd[[A_REG:[0-9]+]], [kernel_func_param_0]
Jingyue Wua2f60272015-06-04 21:28:26 +000026; CHECK: cvta.to.global.u64 %rd[[A1_REG:[0-9]+]], %rd[[A_REG]]
Justin Lebar16da82f2016-07-26 18:28:33 +000027; CHECK: add.u64 %rd[[SP_REG:[0-9]+]], %SP, 0
Jingyue Wua2f60272015-06-04 21:28:26 +000028; CHECK: ld.global.f32 %f[[A0_REG:[0-9]+]], [%rd[[A1_REG]]]
Jingyue Wucd3afea2015-06-17 22:31:02 +000029; CHECK: st.local.f32 [{{%rd[0-9]+}}], %f[[A0_REG]]
Eli Benderskya7b66792014-03-24 16:52:30 +000030
David Blaikiea79ac142015-02-27 21:17:42 +000031 %0 = load float, float* %a, align 4
Eli Benderskya7b66792014-03-24 16:52:30 +000032 %1 = bitcast [16 x i8]* %buf to float*
33 store float %0, float* %1, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000034 %arrayidx2 = getelementptr inbounds float, float* %a, i64 1
David Blaikiea79ac142015-02-27 21:17:42 +000035 %2 = load float, float* %arrayidx2, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000036 %arrayidx3 = getelementptr inbounds [16 x i8], [16 x i8]* %buf, i64 0, i64 1
Eli Benderskya7b66792014-03-24 16:52:30 +000037 %3 = bitcast i8* %arrayidx3 to float*
38 store float %2, float* %3, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000039 %arrayidx4 = getelementptr inbounds float, float* %a, i64 2
David Blaikiea79ac142015-02-27 21:17:42 +000040 %4 = load float, float* %arrayidx4, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000041 %arrayidx5 = getelementptr inbounds [16 x i8], [16 x i8]* %buf, i64 0, i64 2
Eli Benderskya7b66792014-03-24 16:52:30 +000042 %5 = bitcast i8* %arrayidx5 to float*
43 store float %4, float* %5, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000044 %arrayidx6 = getelementptr inbounds float, float* %a, i64 3
David Blaikiea79ac142015-02-27 21:17:42 +000045 %6 = load float, float* %arrayidx6, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000046 %arrayidx7 = getelementptr inbounds [16 x i8], [16 x i8]* %buf, i64 0, i64 3
Eli Benderskya7b66792014-03-24 16:52:30 +000047 %7 = bitcast i8* %arrayidx7 to float*
48 store float %6, float* %7, align 4
49
Eli Benderskya7b66792014-03-24 16:52:30 +000050; CHECK: .param .b64 param0;
Justin Lebar16da82f2016-07-26 18:28:33 +000051; CHECK-NEXT: st.param.b64 [param0+0], %rd[[A_REG]]
Eli Benderskya7b66792014-03-24 16:52:30 +000052; CHECK-NEXT: .param .b64 param1;
Justin Holewinski3e037d92014-07-16 16:26:58 +000053; CHECK-NEXT: st.param.b64 [param1+0], %rd[[SP_REG]]
Eli Benderskya7b66792014-03-24 16:52:30 +000054; CHECK-NEXT: call.uni
55; CHECK-NEXT: callee,
56
David Blaikie79e6c742015-02-27 19:29:02 +000057 %arraydecay = getelementptr inbounds [16 x i8], [16 x i8]* %buf, i64 0, i64 0
Eli Benderskya7b66792014-03-24 16:52:30 +000058 call void @callee(float* %a, i8* %arraydecay) #2
59 ret void
60}
61
62declare void @callee(float*, i8*)
63
64!nvvm.annotations = !{!0}
65
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +000066!0 = !{void (float*)* @kernel_func, !"kernel", i32 1}