1 ; RUN: llc -march=amdgcn -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN %s
4 ; There is no dependence between the store and the two loads. So we can combine the loads
5 ; and the combined load is at the original place of the second load.
7 ; GCN-LABEL: {{^}}ds_combine_nodep
9 ; GCN: ds_read2_b32 v{{\[[0-9]+:[0-9]+\]}}, v{{[0-9]+}} offset0:7 offset1:8
10 ; GCN-NEXT: ds_write2_b32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}} offset0:26 offset1:27
11 define amdgpu_kernel void @ds_combine_nodep(float addrspace(1)* %out, float addrspace(3)* %inptr) {
13 %base = bitcast float addrspace(3)* %inptr to i8 addrspace(3)*
14 %addr0 = getelementptr i8, i8 addrspace(3)* %base, i32 24
15 %tmp0 = bitcast i8 addrspace(3)* %addr0 to float addrspace(3)*
16 %vaddr0 = bitcast float addrspace(3)* %tmp0 to <3 x float> addrspace(3)*
17 %load0 = load <3 x float>, <3 x float> addrspace(3)* %vaddr0, align 4
18 %v0 = extractelement <3 x float> %load0, i32 2
20 %tmp1 = insertelement <2 x float> undef, float 1.0, i32 0
21 %data = insertelement <2 x float> %tmp1, float 2.0, i32 1
23 %tmp2 = getelementptr float, float addrspace(3)* %inptr, i32 26
24 %vaddrs = bitcast float addrspace(3)* %tmp2 to <2 x float> addrspace(3)*
25 store <2 x float> %data, <2 x float> addrspace(3)* %vaddrs, align 4
27 %vaddr1 = getelementptr float, float addrspace(3)* %inptr, i32 7
28 %v1 = load float, float addrspace(3)* %vaddr1, align 4
30 %sum = fadd float %v0, %v1
31 store float %sum, float addrspace(1)* %out, align 4
36 ; The store depends on the first load, so we could not move the first load down to combine with
37 ; the second load directly. However, we can move the store after the combined load.
39 ; GCN-LABEL: {{^}}ds_combine_WAR
41 ; GCN: ds_read2_b32 v{{\[[0-9]+:[0-9]+\]}}, v{{[0-9]+}} offset0:7 offset1:27
42 ; GCN-NEXT: ds_write2_b32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}} offset0:26 offset1:27
43 define amdgpu_kernel void @ds_combine_WAR(float addrspace(1)* %out, float addrspace(3)* %inptr) {
45 %base = bitcast float addrspace(3)* %inptr to i8 addrspace(3)*
46 %addr0 = getelementptr i8, i8 addrspace(3)* %base, i32 100
47 %tmp0 = bitcast i8 addrspace(3)* %addr0 to float addrspace(3)*
48 %vaddr0 = bitcast float addrspace(3)* %tmp0 to <3 x float> addrspace(3)*
49 %load0 = load <3 x float>, <3 x float> addrspace(3)* %vaddr0, align 4
50 %v0 = extractelement <3 x float> %load0, i32 2
52 %tmp1 = insertelement <2 x float> undef, float 1.0, i32 0
53 %data = insertelement <2 x float> %tmp1, float 2.0, i32 1
55 %tmp2 = getelementptr float, float addrspace(3)* %inptr, i32 26
56 %vaddrs = bitcast float addrspace(3)* %tmp2 to <2 x float> addrspace(3)*
57 store <2 x float> %data, <2 x float> addrspace(3)* %vaddrs, align 4
59 %vaddr1 = getelementptr float, float addrspace(3)* %inptr, i32 7
60 %v1 = load float, float addrspace(3)* %vaddr1, align 4
62 %sum = fadd float %v0, %v1
63 store float %sum, float addrspace(1)* %out, align 4
68 ; The second load depends on the store. We can combine the two loads, and the combined load is
69 ; at the original place of the second load.
71 ; GCN-LABEL: {{^}}ds_combine_RAW
73 ; GCN: ds_write2_b32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}} offset0:26 offset1:27
74 ; GCN-NEXT: ds_read2_b32 v{{\[[0-9]+:[0-9]+\]}}, v{{[0-9]+}} offset0:8 offset1:26
75 define amdgpu_kernel void @ds_combine_RAW(float addrspace(1)* %out, float addrspace(3)* %inptr) {
77 %base = bitcast float addrspace(3)* %inptr to i8 addrspace(3)*
78 %addr0 = getelementptr i8, i8 addrspace(3)* %base, i32 24
79 %tmp0 = bitcast i8 addrspace(3)* %addr0 to float addrspace(3)*
80 %vaddr0 = bitcast float addrspace(3)* %tmp0 to <3 x float> addrspace(3)*
81 %load0 = load <3 x float>, <3 x float> addrspace(3)* %vaddr0, align 4
82 %v0 = extractelement <3 x float> %load0, i32 2
84 %tmp1 = insertelement <2 x float> undef, float 1.0, i32 0
85 %data = insertelement <2 x float> %tmp1, float 2.0, i32 1
87 %tmp2 = getelementptr float, float addrspace(3)* %inptr, i32 26
88 %vaddrs = bitcast float addrspace(3)* %tmp2 to <2 x float> addrspace(3)*
89 store <2 x float> %data, <2 x float> addrspace(3)* %vaddrs, align 4
91 %vaddr1 = getelementptr float, float addrspace(3)* %inptr, i32 26
92 %v1 = load float, float addrspace(3)* %vaddr1, align 4
94 %sum = fadd float %v0, %v1
95 store float %sum, float addrspace(1)* %out, align 4
100 ; The store depends on the first load, also the second load depends on the store.
101 ; So we can not combine the two loads.
103 ; GCN-LABEL: {{^}}ds_combine_WAR_RAW
105 ; GCN: ds_read_b32 v{{[0-9]+}}, v{{[0-9]+}} offset:108
106 ; GCN-NEXT: ds_write2_b32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}} offset0:26 offset1:27
107 ; GCN-NEXT: ds_read_b32 v{{[0-9]+}}, v{{[0-9]+}} offset:104
108 define amdgpu_kernel void @ds_combine_WAR_RAW(float addrspace(1)* %out, float addrspace(3)* %inptr) {
110 %base = bitcast float addrspace(3)* %inptr to i8 addrspace(3)*
111 %addr0 = getelementptr i8, i8 addrspace(3)* %base, i32 100
112 %tmp0 = bitcast i8 addrspace(3)* %addr0 to float addrspace(3)*
113 %vaddr0 = bitcast float addrspace(3)* %tmp0 to <3 x float> addrspace(3)*
114 %load0 = load <3 x float>, <3 x float> addrspace(3)* %vaddr0, align 4
115 %v0 = extractelement <3 x float> %load0, i32 2
117 %tmp1 = insertelement <2 x float> undef, float 1.0, i32 0
118 %data = insertelement <2 x float> %tmp1, float 2.0, i32 1
120 %tmp2 = getelementptr float, float addrspace(3)* %inptr, i32 26
121 %vaddrs = bitcast float addrspace(3)* %tmp2 to <2 x float> addrspace(3)*
122 store <2 x float> %data, <2 x float> addrspace(3)* %vaddrs, align 4
124 %vaddr1 = getelementptr float, float addrspace(3)* %inptr, i32 26
125 %v1 = load float, float addrspace(3)* %vaddr1, align 4
127 %sum = fadd float %v0, %v1
128 store float %sum, float addrspace(1)* %out, align 4