xref: /aosp_15_r20/external/llvm/test/CodeGen/NVPTX/call-with-alloca-buffer.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker; Checks how NVPTX lowers alloca buffers and their passing to functions.
4*9880d681SAndroid Build Coastguard Worker;
5*9880d681SAndroid Build Coastguard Worker; Produced with the following CUDA code:
6*9880d681SAndroid Build Coastguard Worker;  extern "C" __attribute__((device)) void callee(float* f, char* buf);
7*9880d681SAndroid Build Coastguard Worker;
8*9880d681SAndroid Build Coastguard Worker;  extern "C" __attribute__((global)) void kernel_func(float* a) {
9*9880d681SAndroid Build Coastguard Worker;    char buf[4 * sizeof(float)];
10*9880d681SAndroid Build Coastguard Worker;    *(reinterpret_cast<float*>(&buf[0])) = a[0];
11*9880d681SAndroid Build Coastguard Worker;    *(reinterpret_cast<float*>(&buf[1])) = a[1];
12*9880d681SAndroid Build Coastguard Worker;    *(reinterpret_cast<float*>(&buf[2])) = a[2];
13*9880d681SAndroid Build Coastguard Worker;    *(reinterpret_cast<float*>(&buf[3])) = a[3];
14*9880d681SAndroid Build Coastguard Worker;    callee(a, buf);
15*9880d681SAndroid Build Coastguard Worker;  }
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Worker; CHECK: .visible .entry kernel_func
18*9880d681SAndroid Build Coastguard Workerdefine void @kernel_func(float* %a) {
19*9880d681SAndroid Build Coastguard Workerentry:
20*9880d681SAndroid Build Coastguard Worker  %buf = alloca [16 x i8], align 4
21*9880d681SAndroid Build Coastguard Worker
22*9880d681SAndroid Build Coastguard Worker; CHECK: .local .align 4 .b8 	__local_depot0[16]
23*9880d681SAndroid Build Coastguard Worker; CHECK: mov.u64 %SPL
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker; CHECK: ld.param.u64 %rd[[A_REG:[0-9]+]], [kernel_func_param_0]
26*9880d681SAndroid Build Coastguard Worker; CHECK: cvta.to.global.u64 %rd[[A1_REG:[0-9]+]], %rd[[A_REG]]
27*9880d681SAndroid Build Coastguard Worker; FIXME: casting A1_REG to A2_REG is unnecessary; A2_REG is essentially A_REG
28*9880d681SAndroid Build Coastguard Worker; CHECK: cvta.global.u64 %rd[[A2_REG:[0-9]+]], %rd[[A1_REG]]
29*9880d681SAndroid Build Coastguard Worker; CHECK: cvta.local.u64 %rd[[SP_REG:[0-9]+]]
30*9880d681SAndroid Build Coastguard Worker; CHECK: ld.global.f32 %f[[A0_REG:[0-9]+]], [%rd[[A1_REG]]]
31*9880d681SAndroid Build Coastguard Worker; CHECK: st.local.f32 [{{%rd[0-9]+}}], %f[[A0_REG]]
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard Worker  %0 = load float, float* %a, align 4
34*9880d681SAndroid Build Coastguard Worker  %1 = bitcast [16 x i8]* %buf to float*
35*9880d681SAndroid Build Coastguard Worker  store float %0, float* %1, align 4
36*9880d681SAndroid Build Coastguard Worker  %arrayidx2 = getelementptr inbounds float, float* %a, i64 1
37*9880d681SAndroid Build Coastguard Worker  %2 = load float, float* %arrayidx2, align 4
38*9880d681SAndroid Build Coastguard Worker  %arrayidx3 = getelementptr inbounds [16 x i8], [16 x i8]* %buf, i64 0, i64 1
39*9880d681SAndroid Build Coastguard Worker  %3 = bitcast i8* %arrayidx3 to float*
40*9880d681SAndroid Build Coastguard Worker  store float %2, float* %3, align 4
41*9880d681SAndroid Build Coastguard Worker  %arrayidx4 = getelementptr inbounds float, float* %a, i64 2
42*9880d681SAndroid Build Coastguard Worker  %4 = load float, float* %arrayidx4, align 4
43*9880d681SAndroid Build Coastguard Worker  %arrayidx5 = getelementptr inbounds [16 x i8], [16 x i8]* %buf, i64 0, i64 2
44*9880d681SAndroid Build Coastguard Worker  %5 = bitcast i8* %arrayidx5 to float*
45*9880d681SAndroid Build Coastguard Worker  store float %4, float* %5, align 4
46*9880d681SAndroid Build Coastguard Worker  %arrayidx6 = getelementptr inbounds float, float* %a, i64 3
47*9880d681SAndroid Build Coastguard Worker  %6 = load float, float* %arrayidx6, align 4
48*9880d681SAndroid Build Coastguard Worker  %arrayidx7 = getelementptr inbounds [16 x i8], [16 x i8]* %buf, i64 0, i64 3
49*9880d681SAndroid Build Coastguard Worker  %7 = bitcast i8* %arrayidx7 to float*
50*9880d681SAndroid Build Coastguard Worker  store float %6, float* %7, align 4
51*9880d681SAndroid Build Coastguard Worker
52*9880d681SAndroid Build Coastguard Worker; CHECK:        .param .b64 param0;
53*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   st.param.b64  [param0+0], %rd[[A2_REG]]
54*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   .param .b64 param1;
55*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   st.param.b64  [param1+0], %rd[[SP_REG]]
56*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   call.uni
57*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   callee,
58*9880d681SAndroid Build Coastguard Worker
59*9880d681SAndroid Build Coastguard Worker  %arraydecay = getelementptr inbounds [16 x i8], [16 x i8]* %buf, i64 0, i64 0
60*9880d681SAndroid Build Coastguard Worker  call void @callee(float* %a, i8* %arraydecay) #2
61*9880d681SAndroid Build Coastguard Worker  ret void
62*9880d681SAndroid Build Coastguard Worker}
63*9880d681SAndroid Build Coastguard Worker
64*9880d681SAndroid Build Coastguard Workerdeclare void @callee(float*, i8*)
65*9880d681SAndroid Build Coastguard Worker
66*9880d681SAndroid Build Coastguard Worker!nvvm.annotations = !{!0}
67*9880d681SAndroid Build Coastguard Worker
68*9880d681SAndroid Build Coastguard Worker!0 = !{void (float*)* @kernel_func, !"kernel", i32 1}
69