xref: /aosp_15_r20/external/llvm/test/CodeGen/NVPTX/lower-aggr-copies.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -march=nvptx64 -mcpu=sm_35 | FileCheck %s --check-prefix PTX
2*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -S -nvptx-lower-aggr-copies | FileCheck %s --check-prefix IR
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Worker; Verify that the NVPTXLowerAggrCopies pass works as expected - calls to
5*9880d681SAndroid Build Coastguard Worker; llvm.mem* intrinsics get lowered to loops.
6*9880d681SAndroid Build Coastguard Worker
7*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
8*9880d681SAndroid Build Coastguard Workertarget triple = "nvptx64-unknown-unknown"
9*9880d681SAndroid Build Coastguard Worker
10*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1) #1
11*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.memmove.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1) #1
12*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) #1
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Workerdefine i8* @memcpy_caller(i8* %dst, i8* %src, i64 %n) #0 {
15*9880d681SAndroid Build Coastguard Workerentry:
16*9880d681SAndroid Build Coastguard Worker  tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %n, i32 1, i1 false)
17*9880d681SAndroid Build Coastguard Worker  ret i8* %dst
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Worker; IR-LABEL:   @memcpy_caller
20*9880d681SAndroid Build Coastguard Worker; IR:         loadstoreloop:
21*9880d681SAndroid Build Coastguard Worker; IR:         [[LOADPTR:%[0-9]+]] = getelementptr inbounds i8, i8* %src, i64
22*9880d681SAndroid Build Coastguard Worker; IR-NEXT:    [[VAL:%[0-9]+]] = load i8, i8* [[LOADPTR]]
23*9880d681SAndroid Build Coastguard Worker; IR-NEXT:    [[STOREPTR:%[0-9]+]] = getelementptr inbounds i8, i8* %dst, i64
24*9880d681SAndroid Build Coastguard Worker; IR-NEXT:    store i8 [[VAL]], i8* [[STOREPTR]]
25*9880d681SAndroid Build Coastguard Worker
26*9880d681SAndroid Build Coastguard Worker; PTX-LABEL:  .visible .func (.param .b64 func_retval0) memcpy_caller
27*9880d681SAndroid Build Coastguard Worker; PTX:        LBB[[LABEL:[_0-9]+]]:
28*9880d681SAndroid Build Coastguard Worker; PTX:        ld.u8 %rs[[REG:[0-9]+]]
29*9880d681SAndroid Build Coastguard Worker; PTX:        st.u8 [%rd{{[0-9]+}}], %rs[[REG]]
30*9880d681SAndroid Build Coastguard Worker; PTX:        add.s64 %rd[[COUNTER:[0-9]+]], %rd[[COUNTER]], 1
31*9880d681SAndroid Build Coastguard Worker; PTX-NEXT:   setp.lt.u64 %p[[PRED:[0-9]+]], %rd[[COUNTER]], %rd
32*9880d681SAndroid Build Coastguard Worker; PTX-NEXT:   @%p[[PRED]] bra LBB[[LABEL]]
33*9880d681SAndroid Build Coastguard Worker}
34*9880d681SAndroid Build Coastguard Worker
35*9880d681SAndroid Build Coastguard Workerdefine i8* @memcpy_volatile_caller(i8* %dst, i8* %src, i64 %n) #0 {
36*9880d681SAndroid Build Coastguard Workerentry:
37*9880d681SAndroid Build Coastguard Worker  tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %n, i32 1, i1 true)
38*9880d681SAndroid Build Coastguard Worker  ret i8* %dst
39*9880d681SAndroid Build Coastguard Worker
40*9880d681SAndroid Build Coastguard Worker; IR-LABEL:   @memcpy_volatile_caller
41*9880d681SAndroid Build Coastguard Worker; IR:         load volatile
42*9880d681SAndroid Build Coastguard Worker; IR:         store volatile
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker; PTX-LABEL:  .visible .func (.param .b64 func_retval0) memcpy_volatile_caller
45*9880d681SAndroid Build Coastguard Worker; PTX:        LBB[[LABEL:[_0-9]+]]:
46*9880d681SAndroid Build Coastguard Worker; PTX:        ld.volatile.u8 %rs[[REG:[0-9]+]]
47*9880d681SAndroid Build Coastguard Worker; PTX:        st.volatile.u8 [%rd{{[0-9]+}}], %rs[[REG]]
48*9880d681SAndroid Build Coastguard Worker; PTX:        add.s64 %rd[[COUNTER:[0-9]+]], %rd[[COUNTER]], 1
49*9880d681SAndroid Build Coastguard Worker; PTX-NEXT:   setp.lt.u64 %p[[PRED:[0-9]+]], %rd[[COUNTER]], %rd
50*9880d681SAndroid Build Coastguard Worker; PTX-NEXT:   @%p[[PRED]] bra LBB[[LABEL]]
51*9880d681SAndroid Build Coastguard Worker}
52*9880d681SAndroid Build Coastguard Worker
53*9880d681SAndroid Build Coastguard Workerdefine i8* @memcpy_casting_caller(i32* %dst, i32* %src, i64 %n) #0 {
54*9880d681SAndroid Build Coastguard Workerentry:
55*9880d681SAndroid Build Coastguard Worker  %0 = bitcast i32* %dst to i8*
56*9880d681SAndroid Build Coastguard Worker  %1 = bitcast i32* %src to i8*
57*9880d681SAndroid Build Coastguard Worker  tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* %1, i64 %n, i32 1, i1 false)
58*9880d681SAndroid Build Coastguard Worker  ret i8* %0
59*9880d681SAndroid Build Coastguard Worker
60*9880d681SAndroid Build Coastguard Worker; Check that casts in calls to memcpy are handled properly
61*9880d681SAndroid Build Coastguard Worker; IR-LABEL:   @memcpy_casting_caller
62*9880d681SAndroid Build Coastguard Worker; IR:         [[DSTCAST:%[0-9]+]] = bitcast i32* %dst to i8*
63*9880d681SAndroid Build Coastguard Worker; IR:         [[SRCCAST:%[0-9]+]] = bitcast i32* %src to i8*
64*9880d681SAndroid Build Coastguard Worker; IR:         getelementptr inbounds i8, i8* [[SRCCAST]]
65*9880d681SAndroid Build Coastguard Worker; IR:         getelementptr inbounds i8, i8* [[DSTCAST]]
66*9880d681SAndroid Build Coastguard Worker}
67*9880d681SAndroid Build Coastguard Worker
68*9880d681SAndroid Build Coastguard Workerdefine i8* @memset_caller(i8* %dst, i32 %c, i64 %n) #0 {
69*9880d681SAndroid Build Coastguard Workerentry:
70*9880d681SAndroid Build Coastguard Worker  %0 = trunc i32 %c to i8
71*9880d681SAndroid Build Coastguard Worker  tail call void @llvm.memset.p0i8.i64(i8* %dst, i8 %0, i64 %n, i32 1, i1 false)
72*9880d681SAndroid Build Coastguard Worker  ret i8* %dst
73*9880d681SAndroid Build Coastguard Worker
74*9880d681SAndroid Build Coastguard Worker; IR-LABEL:   @memset_caller
75*9880d681SAndroid Build Coastguard Worker; IR:         [[VAL:%[0-9]+]] = trunc i32 %c to i8
76*9880d681SAndroid Build Coastguard Worker; IR:         loadstoreloop:
77*9880d681SAndroid Build Coastguard Worker; IR:         [[STOREPTR:%[0-9]+]] = getelementptr inbounds i8, i8* %dst, i64
78*9880d681SAndroid Build Coastguard Worker; IR-NEXT:    store i8 [[VAL]], i8* [[STOREPTR]]
79*9880d681SAndroid Build Coastguard Worker
80*9880d681SAndroid Build Coastguard Worker; PTX-LABEL:  .visible .func (.param .b64 func_retval0) memset_caller(
81*9880d681SAndroid Build Coastguard Worker; PTX:        ld.param.u8 %rs[[REG:[0-9]+]]
82*9880d681SAndroid Build Coastguard Worker; PTX:        LBB[[LABEL:[_0-9]+]]:
83*9880d681SAndroid Build Coastguard Worker; PTX:        st.u8 [%rd{{[0-9]+}}], %rs[[REG]]
84*9880d681SAndroid Build Coastguard Worker; PTX:        add.s64 %rd[[COUNTER:[0-9]+]], %rd[[COUNTER]], 1
85*9880d681SAndroid Build Coastguard Worker; PTX-NEXT:   setp.lt.u64 %p[[PRED:[0-9]+]], %rd[[COUNTER]], %rd
86*9880d681SAndroid Build Coastguard Worker; PTX-NEXT:   @%p[[PRED]] bra LBB[[LABEL]]
87*9880d681SAndroid Build Coastguard Worker}
88*9880d681SAndroid Build Coastguard Worker
89*9880d681SAndroid Build Coastguard Workerdefine i8* @memmove_caller(i8* %dst, i8* %src, i64 %n) #0 {
90*9880d681SAndroid Build Coastguard Workerentry:
91*9880d681SAndroid Build Coastguard Worker  tail call void @llvm.memmove.p0i8.p0i8.i64(i8* %dst, i8* %src, i64 %n, i32 1, i1 false)
92*9880d681SAndroid Build Coastguard Worker  ret i8* %dst
93*9880d681SAndroid Build Coastguard Worker
94*9880d681SAndroid Build Coastguard Worker; IR-LABEL:   @memmove_caller
95*9880d681SAndroid Build Coastguard Worker; IR:         icmp ult i8* %src, %dst
96*9880d681SAndroid Build Coastguard Worker; IR:         [[PHIVAL:%[0-9a-zA-Z_]+]] = phi i64
97*9880d681SAndroid Build Coastguard Worker; IR-NEXT:    %index_ptr = sub i64 [[PHIVAL]], 1
98*9880d681SAndroid Build Coastguard Worker; IR:         [[FWDPHIVAL:%[0-9a-zA-Z_]+]] = phi i64
99*9880d681SAndroid Build Coastguard Worker; IR:         {{%[0-9a-zA-Z_]+}} = add i64 [[FWDPHIVAL]], 1
100*9880d681SAndroid Build Coastguard Worker
101*9880d681SAndroid Build Coastguard Worker; PTX-LABEL:  .visible .func (.param .b64 func_retval0) memmove_caller(
102*9880d681SAndroid Build Coastguard Worker; PTX:        ld.param.u64 %rd[[N:[0-9]+]]
103*9880d681SAndroid Build Coastguard Worker; PTX:        setp.eq.s64 %p[[NEQ0:[0-9]+]], %rd[[N]], 0
104*9880d681SAndroid Build Coastguard Worker; PTX:        setp.ge.u64 %p[[SRC_GT_THAN_DST:[0-9]+]], %rd{{[0-9]+}}, %rd{{[0-9]+}}
105*9880d681SAndroid Build Coastguard Worker; PTX-NEXT:   @%p[[SRC_GT_THAN_DST]] bra LBB[[FORWARD_BB:[0-9_]+]]
106*9880d681SAndroid Build Coastguard Worker; -- this is the backwards copying BB
107*9880d681SAndroid Build Coastguard Worker; PTX:        @%p[[NEQ0]] bra LBB[[EXIT:[0-9_]+]]
108*9880d681SAndroid Build Coastguard Worker; PTX:        add.s64 %rd[[N]], %rd[[N]], -1
109*9880d681SAndroid Build Coastguard Worker; PTX:        ld.u8 %rs[[ELEMENT:[0-9]+]]
110*9880d681SAndroid Build Coastguard Worker; PTX:        st.u8 [%rd{{[0-9]+}}], %rs[[ELEMENT]]
111*9880d681SAndroid Build Coastguard Worker; -- this is the forwards copying BB
112*9880d681SAndroid Build Coastguard Worker; PTX:        LBB[[FORWARD_BB]]:
113*9880d681SAndroid Build Coastguard Worker; PTX:        @%p[[NEQ0]] bra LBB[[EXIT]]
114*9880d681SAndroid Build Coastguard Worker; PTX:        ld.u8 %rs[[ELEMENT2:[0-9]+]]
115*9880d681SAndroid Build Coastguard Worker; PTX:        st.u8 [%rd{{[0-9]+}}], %rs[[ELEMENT2]]
116*9880d681SAndroid Build Coastguard Worker; PTX:        add.s64 %rd[[INDEX:[0-9]+]], %rd[[INDEX]], 1
117*9880d681SAndroid Build Coastguard Worker; -- exit block
118*9880d681SAndroid Build Coastguard Worker; PTX:        LBB[[EXIT]]:
119*9880d681SAndroid Build Coastguard Worker; PTX-NEXT:   st.param.b64 [func_retval0
120*9880d681SAndroid Build Coastguard Worker; PTX-NEXT:   ret
121*9880d681SAndroid Build Coastguard Worker}
122