1 ; RUN: llc -march=amdgcn -mcpu=gfx900 -O3 < %s | FileCheck -check-prefix=GCN %s
2 ; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-module-lds < %s | FileCheck %s
3 ; RUN: opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds < %s | FileCheck %s
5 @a = internal unnamed_addr addrspace(3) global [64 x i32] undef, align 4
6 @b = internal unnamed_addr addrspace(3) global [64 x i32] undef, align 4
7 @c = internal unnamed_addr addrspace(3) global [64 x i32] undef, align 4
9 ; FIXME: Should combine the DS instructions into ds_write2 and ds_read2. This
10 ; does not happen because when SILoadStoreOptimizer is run, the reads and writes
11 ; are not adjacent. They are only moved later by MachineScheduler.
13 ; GCN-LABEL: {{^}}no_clobber_ds_load_stores_x2:
19 ; CHECK-LABEL: @no_clobber_ds_load_stores_x2
20 ; CHECK: store i32 1, i32 addrspace(3)* %0, align 16, !alias.scope !0, !noalias !3
21 ; CHECK: %val.a = load i32, i32 addrspace(3)* %gep.a, align 4, !alias.scope !0, !noalias !3
22 ; CHECK: store i32 2, i32 addrspace(3)* %1, align 16, !alias.scope !3, !noalias !0
23 ; CHECK: %val.b = load i32, i32 addrspace(3)* %gep.b, align 4, !alias.scope !3, !noalias !0
25 define amdgpu_kernel void @no_clobber_ds_load_stores_x2(i32 addrspace(1)* %arg, i32 %i) {
27 store i32 1, i32 addrspace(3)* getelementptr inbounds ([64 x i32], [64 x i32] addrspace(3)* @a, i32 0, i32 0), align 4
28 %gep.a = getelementptr inbounds [64 x i32], [64 x i32] addrspace(3)* @a, i32 0, i32 %i
29 %val.a = load i32, i32 addrspace(3)* %gep.a, align 4
30 store i32 2, i32 addrspace(3)* getelementptr inbounds ([64 x i32], [64 x i32] addrspace(3)* @b, i32 0, i32 0), align 4
31 %gep.b = getelementptr inbounds [64 x i32], [64 x i32] addrspace(3)* @b, i32 0, i32 %i
32 %val.b = load i32, i32 addrspace(3)* %gep.b, align 4
33 %val = add i32 %val.a, %val.b
34 store i32 %val, i32 addrspace(1)* %arg, align 4
38 ; GCN-LABEL: {{^}}no_clobber_ds_load_stores_x3:
39 ; GCN-DAG: ds_write_b32
40 ; GCN-DAG: ds_write_b32
41 ; GCN-DAG: ds_write_b32
42 ; GCN-DAG: ds_read_b32
43 ; GCN-DAG: ds_read_b32
44 ; GCN-DAG: ds_read_b32
46 ; CHECK-LABEL: @no_clobber_ds_load_stores_x3
47 ; CHECK: store i32 1, i32 addrspace(3)* %0, align 16, !alias.scope !5, !noalias !8
48 ; CHECK: %val.a = load i32, i32 addrspace(3)* %gep.a, align 4, !alias.scope !5, !noalias !8
49 ; CHECK: store i32 2, i32 addrspace(3)* %1, align 16, !alias.scope !11, !noalias !12
50 ; CHECK: %val.b = load i32, i32 addrspace(3)* %gep.b, align 4, !alias.scope !11, !noalias !12
51 ; CHECK: store i32 3, i32 addrspace(3)* %2, align 16, !alias.scope !13, !noalias !14
52 ; CHECK: %val.c = load i32, i32 addrspace(3)* %gep.c, align 4, !alias.scope !13, !noalias !14
54 define amdgpu_kernel void @no_clobber_ds_load_stores_x3(i32 addrspace(1)* %arg, i32 %i) {
56 store i32 1, i32 addrspace(3)* getelementptr inbounds ([64 x i32], [64 x i32] addrspace(3)* @a, i32 0, i32 0), align 4
57 %gep.a = getelementptr inbounds [64 x i32], [64 x i32] addrspace(3)* @a, i32 0, i32 %i
58 %val.a = load i32, i32 addrspace(3)* %gep.a, align 4
59 store i32 2, i32 addrspace(3)* getelementptr inbounds ([64 x i32], [64 x i32] addrspace(3)* @b, i32 0, i32 0), align 4
60 %gep.b = getelementptr inbounds [64 x i32], [64 x i32] addrspace(3)* @b, i32 0, i32 %i
61 %val.b = load i32, i32 addrspace(3)* %gep.b, align 4
62 store i32 3, i32 addrspace(3)* getelementptr inbounds ([64 x i32], [64 x i32] addrspace(3)* @c, i32 0, i32 0), align 4
63 %gep.c = getelementptr inbounds [64 x i32], [64 x i32] addrspace(3)* @c, i32 0, i32 %i
64 %val.c = load i32, i32 addrspace(3)* %gep.c, align 4
65 %val.1 = add i32 %val.a, %val.b
66 %val = add i32 %val.1, %val.c
67 store i32 %val, i32 addrspace(1)* %arg, align 4
72 ; CHECK: !1 = distinct !{!1, !2}
73 ; CHECK: !2 = distinct !{!2}
75 ; CHECK: !4 = distinct !{!4, !2}
77 ; CHECK: !6 = distinct !{!6, !7}
78 ; CHECK: !7 = distinct !{!7}
79 ; CHECK: !8 = !{!9, !10}
80 ; CHECK: !9 = distinct !{!9, !7}
81 ; CHECK: !10 = distinct !{!10, !7}
83 ; CHECK: !12 = !{!6, !10}
85 ; CHECK: !14 = !{!6, !9}