Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 1 | ; RUN: opt -S -codegenprepare -mtriple=amdgcn-unknown-unknown -mcpu=tahiti < %s | FileCheck -check-prefix=OPT -check-prefix=OPT-SI %s |
Tom Stellard | 70580f8 | 2015-07-20 14:28:41 +0000 | [diff] [blame] | 2 | ; RUN: opt -S -codegenprepare -mtriple=amdgcn-unknown-unknown -mcpu=bonaire < %s | FileCheck -check-prefix=OPT -check-prefix=OPT-CI %s |
Matt Arsenault | 7aad8fd | 2017-01-24 22:02:15 +0000 | [diff] [blame] | 3 | ; RUN: opt -S -codegenprepare -mtriple=amdgcn-unknown-unknown -mcpu=tonga -mattr=-flat-for-global < %s | FileCheck -check-prefix=OPT -check-prefix=OPT-VI %s |
Matt Arsenault | 03d8584 | 2016-06-27 20:32:13 +0000 | [diff] [blame] | 4 | ; RUN: llc -march=amdgcn -mcpu=tahiti -mattr=-promote-alloca -amdgpu-sroa=0 < %s | FileCheck -check-prefix=GCN -check-prefix=SI %s |
| 5 | ; RUN: llc -march=amdgcn -mcpu=bonaire -mattr=-promote-alloca -amdgpu-sroa=0 < %s | FileCheck -check-prefix=GCN -check-prefix=CI %s |
Matt Arsenault | 7aad8fd | 2017-01-24 22:02:15 +0000 | [diff] [blame] | 6 | ; RUN: llc -march=amdgcn -mcpu=tonga -mattr=-flat-for-global -mattr=-promote-alloca -amdgpu-sroa=0 < %s | FileCheck -check-prefix=GCN -check-prefix=VI %s |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 7 | |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 8 | ; OPT-LABEL: @test_sink_global_small_offset_i32( |
Tom Stellard | 70580f8 | 2015-07-20 14:28:41 +0000 | [diff] [blame] | 9 | ; OPT-CI-NOT: getelementptr i32, i32 addrspace(1)* %in |
| 10 | ; OPT-VI: getelementptr i32, i32 addrspace(1)* %in |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 11 | ; OPT: br i1 |
Tom Stellard | 70580f8 | 2015-07-20 14:28:41 +0000 | [diff] [blame] | 12 | ; OPT-CI: ptrtoint |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 13 | |
| 14 | ; GCN-LABEL: {{^}}test_sink_global_small_offset_i32: |
| 15 | ; GCN: {{^}}BB0_2: |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 16 | define void @test_sink_global_small_offset_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in) { |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 17 | entry: |
| 18 | %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999 |
| 19 | %in.gep = getelementptr i32, i32 addrspace(1)* %in, i64 7 |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 20 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 21 | %tmp0 = icmp eq i32 %tid, 0 |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 22 | br i1 %tmp0, label %endif, label %if |
| 23 | |
| 24 | if: |
| 25 | %tmp1 = load i32, i32 addrspace(1)* %in.gep |
| 26 | br label %endif |
| 27 | |
| 28 | endif: |
| 29 | %x = phi i32 [ %tmp1, %if ], [ 0, %entry ] |
| 30 | store i32 %x, i32 addrspace(1)* %out.gep |
| 31 | br label %done |
| 32 | |
| 33 | done: |
| 34 | ret void |
| 35 | } |
| 36 | |
| 37 | ; OPT-LABEL: @test_sink_global_small_max_i32_ds_offset( |
| 38 | ; OPT: %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 65535 |
| 39 | ; OPT: br i1 |
| 40 | |
| 41 | ; GCN-LABEL: {{^}}test_sink_global_small_max_i32_ds_offset: |
| 42 | ; GCN: s_and_saveexec_b64 |
Nikolay Haustov | 4f672a3 | 2016-04-29 09:02:30 +0000 | [diff] [blame] | 43 | ; GCN: buffer_load_sbyte {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, s{{[0-9]+$}} |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 44 | ; GCN: {{^}}BB1_2: |
| 45 | ; GCN: s_or_b64 exec |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 46 | define void @test_sink_global_small_max_i32_ds_offset(i32 addrspace(1)* %out, i8 addrspace(1)* %in) { |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 47 | entry: |
| 48 | %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 99999 |
| 49 | %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 65535 |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 50 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 51 | %tmp0 = icmp eq i32 %tid, 0 |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 52 | br i1 %tmp0, label %endif, label %if |
| 53 | |
| 54 | if: |
| 55 | %tmp1 = load i8, i8 addrspace(1)* %in.gep |
| 56 | %tmp2 = sext i8 %tmp1 to i32 |
| 57 | br label %endif |
| 58 | |
| 59 | endif: |
| 60 | %x = phi i32 [ %tmp2, %if ], [ 0, %entry ] |
| 61 | store i32 %x, i32 addrspace(1)* %out.gep |
| 62 | br label %done |
| 63 | |
| 64 | done: |
| 65 | ret void |
| 66 | } |
| 67 | |
| 68 | ; GCN-LABEL: {{^}}test_sink_global_small_max_mubuf_offset: |
| 69 | ; GCN: s_and_saveexec_b64 |
Nikolay Haustov | 4f672a3 | 2016-04-29 09:02:30 +0000 | [diff] [blame] | 70 | ; GCN: buffer_load_sbyte {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, 0 offset:4095{{$}} |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 71 | ; GCN: {{^}}BB2_2: |
| 72 | ; GCN: s_or_b64 exec |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 73 | define void @test_sink_global_small_max_mubuf_offset(i32 addrspace(1)* %out, i8 addrspace(1)* %in) { |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 74 | entry: |
| 75 | %out.gep = getelementptr i32, i32 addrspace(1)* %out, i32 1024 |
| 76 | %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 4095 |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 77 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 78 | %tmp0 = icmp eq i32 %tid, 0 |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 79 | br i1 %tmp0, label %endif, label %if |
| 80 | |
| 81 | if: |
| 82 | %tmp1 = load i8, i8 addrspace(1)* %in.gep |
| 83 | %tmp2 = sext i8 %tmp1 to i32 |
| 84 | br label %endif |
| 85 | |
| 86 | endif: |
| 87 | %x = phi i32 [ %tmp2, %if ], [ 0, %entry ] |
| 88 | store i32 %x, i32 addrspace(1)* %out.gep |
| 89 | br label %done |
| 90 | |
| 91 | done: |
| 92 | ret void |
| 93 | } |
| 94 | |
| 95 | ; GCN-LABEL: {{^}}test_sink_global_small_max_plus_1_mubuf_offset: |
| 96 | ; GCN: s_and_saveexec_b64 |
Nikolay Haustov | 4f672a3 | 2016-04-29 09:02:30 +0000 | [diff] [blame] | 97 | ; GCN: buffer_load_sbyte {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, s{{[0-9]+$}} |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 98 | ; GCN: {{^}}BB3_2: |
| 99 | ; GCN: s_or_b64 exec |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 100 | define void @test_sink_global_small_max_plus_1_mubuf_offset(i32 addrspace(1)* %out, i8 addrspace(1)* %in) { |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 101 | entry: |
| 102 | %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 99999 |
| 103 | %in.gep = getelementptr i8, i8 addrspace(1)* %in, i64 4096 |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 104 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 105 | %tmp0 = icmp eq i32 %tid, 0 |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 106 | br i1 %tmp0, label %endif, label %if |
| 107 | |
| 108 | if: |
| 109 | %tmp1 = load i8, i8 addrspace(1)* %in.gep |
| 110 | %tmp2 = sext i8 %tmp1 to i32 |
| 111 | br label %endif |
| 112 | |
| 113 | endif: |
| 114 | %x = phi i32 [ %tmp2, %if ], [ 0, %entry ] |
| 115 | store i32 %x, i32 addrspace(1)* %out.gep |
| 116 | br label %done |
| 117 | |
| 118 | done: |
| 119 | ret void |
| 120 | } |
| 121 | |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 122 | ; OPT-LABEL: @test_sink_scratch_small_offset_i32( |
| 123 | ; OPT-NOT: getelementptr [512 x i32] |
| 124 | ; OPT: br i1 |
| 125 | ; OPT: ptrtoint |
| 126 | |
| 127 | ; GCN-LABEL: {{^}}test_sink_scratch_small_offset_i32: |
| 128 | ; GCN: s_and_saveexec_b64 |
Matt Arsenault | 39787bd | 2016-10-26 15:08:16 +0000 | [diff] [blame] | 129 | ; GCN: buffer_store_dword {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offset:4092{{$}} |
| 130 | ; GCN: buffer_load_dword {{v[0-9]+}}, off, {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offset:4092{{$}} |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 131 | ; GCN: {{^}}BB4_2: |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 132 | define void @test_sink_scratch_small_offset_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in, i32 %arg) { |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 133 | entry: |
| 134 | %alloca = alloca [512 x i32], align 4 |
| 135 | %out.gep.0 = getelementptr i32, i32 addrspace(1)* %out, i64 999998 |
| 136 | %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i64 999999 |
| 137 | %add.arg = add i32 %arg, 8 |
Matt Arsenault | 707780b | 2017-02-22 21:05:25 +0000 | [diff] [blame] | 138 | %alloca.gep = getelementptr [512 x i32], [512 x i32]* %alloca, i32 0, i32 1022 |
| 139 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 140 | %tmp0 = icmp eq i32 %tid, 0 |
| 141 | br i1 %tmp0, label %endif, label %if |
| 142 | |
| 143 | if: |
| 144 | store volatile i32 123, i32* %alloca.gep |
| 145 | %tmp1 = load volatile i32, i32* %alloca.gep |
| 146 | br label %endif |
| 147 | |
| 148 | endif: |
| 149 | %x = phi i32 [ %tmp1, %if ], [ 0, %entry ] |
| 150 | store i32 %x, i32 addrspace(1)* %out.gep.0 |
| 151 | %load = load volatile i32, i32* %alloca.gep |
| 152 | store i32 %load, i32 addrspace(1)* %out.gep.1 |
| 153 | br label %done |
| 154 | |
| 155 | done: |
| 156 | ret void |
| 157 | } |
| 158 | |
| 159 | ; This ends up not fitting due to the reserved 4 bytes at offset 0 |
| 160 | ; OPT-LABEL: @test_sink_scratch_small_offset_i32_reserved( |
| 161 | ; OPT-NOT: getelementptr [512 x i32] |
| 162 | ; OPT: br i1 |
| 163 | ; OPT: ptrtoint |
| 164 | |
| 165 | ; GCN-LABEL: {{^}}test_sink_scratch_small_offset_i32_reserved: |
| 166 | ; GCN: s_and_saveexec_b64 |
| 167 | ; GCN: v_mov_b32_e32 [[BASE_FI0:v[0-9]+]], 4 |
| 168 | ; GCN: buffer_store_dword {{v[0-9]+}}, [[BASE_FI0]], {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offen offset:4092{{$}} |
| 169 | ; GCN: v_mov_b32_e32 [[BASE_FI1:v[0-9]+]], 4 |
| 170 | ; GCN: buffer_load_dword {{v[0-9]+}}, [[BASE_FI1]], {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offen offset:4092{{$}} |
| 171 | ; GCN: {{^BB[0-9]+}}_2: |
| 172 | |
| 173 | define void @test_sink_scratch_small_offset_i32_reserved(i32 addrspace(1)* %out, i32 addrspace(1)* %in, i32 %arg) { |
| 174 | entry: |
| 175 | %alloca = alloca [512 x i32], align 4 |
| 176 | %out.gep.0 = getelementptr i32, i32 addrspace(1)* %out, i64 999998 |
| 177 | %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i64 999999 |
| 178 | %add.arg = add i32 %arg, 8 |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 179 | %alloca.gep = getelementptr [512 x i32], [512 x i32]* %alloca, i32 0, i32 1023 |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 180 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 181 | %tmp0 = icmp eq i32 %tid, 0 |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 182 | br i1 %tmp0, label %endif, label %if |
| 183 | |
| 184 | if: |
| 185 | store volatile i32 123, i32* %alloca.gep |
| 186 | %tmp1 = load volatile i32, i32* %alloca.gep |
| 187 | br label %endif |
| 188 | |
| 189 | endif: |
| 190 | %x = phi i32 [ %tmp1, %if ], [ 0, %entry ] |
| 191 | store i32 %x, i32 addrspace(1)* %out.gep.0 |
| 192 | %load = load volatile i32, i32* %alloca.gep |
| 193 | store i32 %load, i32 addrspace(1)* %out.gep.1 |
| 194 | br label %done |
| 195 | |
| 196 | done: |
| 197 | ret void |
| 198 | } |
| 199 | |
| 200 | ; OPT-LABEL: @test_no_sink_scratch_large_offset_i32( |
| 201 | ; OPT: %alloca.gep = getelementptr [512 x i32], [512 x i32]* %alloca, i32 0, i32 1024 |
| 202 | ; OPT: br i1 |
| 203 | ; OPT-NOT: ptrtoint |
| 204 | |
| 205 | ; GCN-LABEL: {{^}}test_no_sink_scratch_large_offset_i32: |
| 206 | ; GCN: s_and_saveexec_b64 |
| 207 | ; GCN: buffer_store_dword {{v[0-9]+}}, {{v[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offen{{$}} |
| 208 | ; GCN: buffer_load_dword {{v[0-9]+}}, {{v[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, {{s[0-9]+}} offen{{$}} |
Matt Arsenault | 707780b | 2017-02-22 21:05:25 +0000 | [diff] [blame] | 209 | ; GCN: {{^BB[0-9]+}}_2: |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 210 | define void @test_no_sink_scratch_large_offset_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in, i32 %arg) { |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 211 | entry: |
| 212 | %alloca = alloca [512 x i32], align 4 |
| 213 | %out.gep.0 = getelementptr i32, i32 addrspace(1)* %out, i64 999998 |
| 214 | %out.gep.1 = getelementptr i32, i32 addrspace(1)* %out, i64 999999 |
| 215 | %add.arg = add i32 %arg, 8 |
| 216 | %alloca.gep = getelementptr [512 x i32], [512 x i32]* %alloca, i32 0, i32 1024 |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 217 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 218 | %tmp0 = icmp eq i32 %tid, 0 |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 219 | br i1 %tmp0, label %endif, label %if |
| 220 | |
| 221 | if: |
| 222 | store volatile i32 123, i32* %alloca.gep |
| 223 | %tmp1 = load volatile i32, i32* %alloca.gep |
| 224 | br label %endif |
| 225 | |
| 226 | endif: |
| 227 | %x = phi i32 [ %tmp1, %if ], [ 0, %entry ] |
| 228 | store i32 %x, i32 addrspace(1)* %out.gep.0 |
| 229 | %load = load volatile i32, i32* %alloca.gep |
| 230 | store i32 %load, i32 addrspace(1)* %out.gep.1 |
| 231 | br label %done |
| 232 | |
| 233 | done: |
| 234 | ret void |
| 235 | } |
| 236 | |
| 237 | ; GCN-LABEL: {{^}}test_sink_global_vreg_sreg_i32: |
| 238 | ; GCN: s_and_saveexec_b64 |
Tom Stellard | 70580f8 | 2015-07-20 14:28:41 +0000 | [diff] [blame] | 239 | ; CI: buffer_load_dword {{v[0-9]+}}, {{v\[[0-9]+:[0-9]+\]}}, {{s\[[0-9]+:[0-9]+\]}}, 0 addr64{{$}} |
| 240 | ; VI: flat_load_dword v{{[0-9]+}}, v[{{[0-9]+:[0-9]+}}] |
Matt Arsenault | 707780b | 2017-02-22 21:05:25 +0000 | [diff] [blame] | 241 | ; GCN: {{^BB[0-9]+}}_2: |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 242 | define void @test_sink_global_vreg_sreg_i32(i32 addrspace(1)* %out, i32 addrspace(1)* %in, i32 %offset) { |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 243 | entry: |
| 244 | %offset.ext = zext i32 %offset to i64 |
| 245 | %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999 |
| 246 | %in.gep = getelementptr i32, i32 addrspace(1)* %in, i64 %offset.ext |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 247 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 248 | %tmp0 = icmp eq i32 %tid, 0 |
Matt Arsenault | 73e06fa | 2015-06-04 16:17:42 +0000 | [diff] [blame] | 249 | br i1 %tmp0, label %endif, label %if |
| 250 | |
| 251 | if: |
| 252 | %tmp1 = load i32, i32 addrspace(1)* %in.gep |
| 253 | br label %endif |
| 254 | |
| 255 | endif: |
| 256 | %x = phi i32 [ %tmp1, %if ], [ 0, %entry ] |
| 257 | store i32 %x, i32 addrspace(1)* %out.gep |
| 258 | br label %done |
| 259 | |
| 260 | done: |
| 261 | ret void |
| 262 | } |
| 263 | |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 264 | ; OPT-LABEL: @test_sink_constant_small_offset_i32 |
| 265 | ; OPT-NOT: getelementptr i32, i32 addrspace(2)* |
| 266 | ; OPT: br i1 |
| 267 | |
| 268 | ; GCN-LABEL: {{^}}test_sink_constant_small_offset_i32: |
| 269 | ; GCN: s_and_saveexec_b64 |
| 270 | ; SI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, 0x7{{$}} |
| 271 | ; GCN: s_or_b64 exec, exec |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 272 | define void @test_sink_constant_small_offset_i32(i32 addrspace(1)* %out, i32 addrspace(2)* %in) { |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 273 | entry: |
| 274 | %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999 |
| 275 | %in.gep = getelementptr i32, i32 addrspace(2)* %in, i64 7 |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 276 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 277 | %tmp0 = icmp eq i32 %tid, 0 |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 278 | br i1 %tmp0, label %endif, label %if |
| 279 | |
| 280 | if: |
| 281 | %tmp1 = load i32, i32 addrspace(2)* %in.gep |
| 282 | br label %endif |
| 283 | |
| 284 | endif: |
| 285 | %x = phi i32 [ %tmp1, %if ], [ 0, %entry ] |
| 286 | store i32 %x, i32 addrspace(1)* %out.gep |
| 287 | br label %done |
| 288 | |
| 289 | done: |
| 290 | ret void |
| 291 | } |
| 292 | |
| 293 | ; OPT-LABEL: @test_sink_constant_max_8_bit_offset_i32 |
| 294 | ; OPT-NOT: getelementptr i32, i32 addrspace(2)* |
| 295 | ; OPT: br i1 |
| 296 | |
| 297 | ; GCN-LABEL: {{^}}test_sink_constant_max_8_bit_offset_i32: |
| 298 | ; GCN: s_and_saveexec_b64 |
| 299 | ; SI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, 0xff{{$}} |
| 300 | ; GCN: s_or_b64 exec, exec |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 301 | define void @test_sink_constant_max_8_bit_offset_i32(i32 addrspace(1)* %out, i32 addrspace(2)* %in) { |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 302 | entry: |
| 303 | %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999 |
| 304 | %in.gep = getelementptr i32, i32 addrspace(2)* %in, i64 255 |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 305 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 306 | %tmp0 = icmp eq i32 %tid, 0 |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 307 | br i1 %tmp0, label %endif, label %if |
| 308 | |
| 309 | if: |
| 310 | %tmp1 = load i32, i32 addrspace(2)* %in.gep |
| 311 | br label %endif |
| 312 | |
| 313 | endif: |
| 314 | %x = phi i32 [ %tmp1, %if ], [ 0, %entry ] |
| 315 | store i32 %x, i32 addrspace(1)* %out.gep |
| 316 | br label %done |
| 317 | |
| 318 | done: |
| 319 | ret void |
| 320 | } |
| 321 | |
| 322 | ; OPT-LABEL: @test_sink_constant_max_8_bit_offset_p1_i32 |
| 323 | ; OPT-SI: getelementptr i32, i32 addrspace(2)* |
| 324 | ; OPT-CI-NOT: getelementptr i32, i32 addrspace(2)* |
| 325 | ; OPT-VI-NOT: getelementptr i32, i32 addrspace(2)* |
| 326 | ; OPT: br i1 |
| 327 | |
| 328 | ; GCN-LABEL: {{^}}test_sink_constant_max_8_bit_offset_p1_i32: |
| 329 | ; GCN: s_and_saveexec_b64 |
| 330 | ; SI: s_movk_i32 [[OFFSET:s[0-9]+]], 0x400 |
| 331 | |
| 332 | ; SI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, [[OFFSET]]{{$}} |
| 333 | ; GCN: s_or_b64 exec, exec |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 334 | define void @test_sink_constant_max_8_bit_offset_p1_i32(i32 addrspace(1)* %out, i32 addrspace(2)* %in) { |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 335 | entry: |
| 336 | %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999 |
| 337 | %in.gep = getelementptr i32, i32 addrspace(2)* %in, i64 256 |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 338 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 339 | %tmp0 = icmp eq i32 %tid, 0 |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 340 | br i1 %tmp0, label %endif, label %if |
| 341 | |
| 342 | if: |
| 343 | %tmp1 = load i32, i32 addrspace(2)* %in.gep |
| 344 | br label %endif |
| 345 | |
| 346 | endif: |
| 347 | %x = phi i32 [ %tmp1, %if ], [ 0, %entry ] |
| 348 | store i32 %x, i32 addrspace(1)* %out.gep |
| 349 | br label %done |
| 350 | |
| 351 | done: |
| 352 | ret void |
| 353 | } |
| 354 | |
| 355 | ; OPT-LABEL: @test_sink_constant_max_32_bit_offset_i32 |
| 356 | ; OPT-SI: getelementptr i32, i32 addrspace(2)* |
| 357 | ; OPT-CI-NOT: getelementptr i32, i32 addrspace(2)* |
| 358 | ; OPT: br i1 |
| 359 | |
| 360 | ; GCN-LABEL: {{^}}test_sink_constant_max_32_bit_offset_i32: |
| 361 | ; GCN: s_and_saveexec_b64 |
Tom Stellard | 9a19767 | 2015-09-09 15:43:26 +0000 | [diff] [blame] | 362 | ; GCN: s_add_u32 s{{[0-9]+}}, s{{[0-9]+}}, -4{{$}} |
| 363 | ; GCN: s_addc_u32 s{{[0-9]+}}, s{{[0-9]+}}, 3{{$}} |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 364 | ; SI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, 0x0{{$}} |
| 365 | ; GCN: s_or_b64 exec, exec |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 366 | define void @test_sink_constant_max_32_bit_offset_i32(i32 addrspace(1)* %out, i32 addrspace(2)* %in) { |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 367 | entry: |
| 368 | %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999 |
| 369 | %in.gep = getelementptr i32, i32 addrspace(2)* %in, i64 4294967295 |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 370 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 371 | %tmp0 = icmp eq i32 %tid, 0 |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 372 | br i1 %tmp0, label %endif, label %if |
| 373 | |
| 374 | if: |
| 375 | %tmp1 = load i32, i32 addrspace(2)* %in.gep |
| 376 | br label %endif |
| 377 | |
| 378 | endif: |
| 379 | %x = phi i32 [ %tmp1, %if ], [ 0, %entry ] |
| 380 | store i32 %x, i32 addrspace(1)* %out.gep |
| 381 | br label %done |
| 382 | |
| 383 | done: |
| 384 | ret void |
| 385 | } |
| 386 | |
| 387 | ; OPT-LABEL: @test_sink_constant_max_32_bit_offset_p1_i32 |
| 388 | ; OPT: getelementptr i32, i32 addrspace(2)* |
| 389 | ; OPT: br i1 |
| 390 | |
| 391 | ; GCN-LABEL: {{^}}test_sink_constant_max_32_bit_offset_p1_i32: |
| 392 | ; GCN: s_and_saveexec_b64 |
| 393 | ; GCN: s_add_u32 |
| 394 | ; GCN: s_addc_u32 |
| 395 | ; SI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, 0x0{{$}} |
| 396 | ; GCN: s_or_b64 exec, exec |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 397 | define void @test_sink_constant_max_32_bit_offset_p1_i32(i32 addrspace(1)* %out, i32 addrspace(2)* %in) { |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 398 | entry: |
| 399 | %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999 |
| 400 | %in.gep = getelementptr i32, i32 addrspace(2)* %in, i64 17179869181 |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 401 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 402 | %tmp0 = icmp eq i32 %tid, 0 |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 403 | br i1 %tmp0, label %endif, label %if |
| 404 | |
| 405 | if: |
| 406 | %tmp1 = load i32, i32 addrspace(2)* %in.gep |
| 407 | br label %endif |
| 408 | |
| 409 | endif: |
| 410 | %x = phi i32 [ %tmp1, %if ], [ 0, %entry ] |
| 411 | store i32 %x, i32 addrspace(1)* %out.gep |
| 412 | br label %done |
| 413 | |
| 414 | done: |
| 415 | ret void |
| 416 | } |
| 417 | |
| 418 | ; GCN-LABEL: {{^}}test_sink_constant_max_20_bit_byte_offset_i32: |
| 419 | ; GCN: s_and_saveexec_b64 |
| 420 | ; SI: s_mov_b32 [[OFFSET:s[0-9]+]], 0xffffc{{$}} |
| 421 | ; SI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, [[OFFSET]]{{$}} |
| 422 | |
| 423 | ; CI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, 0x3ffff{{$}} |
| 424 | ; VI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, 0xffffc{{$}} |
| 425 | |
| 426 | ; GCN: s_or_b64 exec, exec |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 427 | define void @test_sink_constant_max_20_bit_byte_offset_i32(i32 addrspace(1)* %out, i32 addrspace(2)* %in) { |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 428 | entry: |
| 429 | %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999 |
| 430 | %in.gep = getelementptr i32, i32 addrspace(2)* %in, i64 262143 |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 431 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 432 | %tmp0 = icmp eq i32 %tid, 0 |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 433 | br i1 %tmp0, label %endif, label %if |
| 434 | |
| 435 | if: |
| 436 | %tmp1 = load i32, i32 addrspace(2)* %in.gep |
| 437 | br label %endif |
| 438 | |
| 439 | endif: |
| 440 | %x = phi i32 [ %tmp1, %if ], [ 0, %entry ] |
| 441 | store i32 %x, i32 addrspace(1)* %out.gep |
| 442 | br label %done |
| 443 | |
| 444 | done: |
| 445 | ret void |
| 446 | } |
| 447 | |
| 448 | ; OPT-LABEL: @test_sink_constant_max_20_bit_byte_offset_p1_i32 |
| 449 | ; OPT-SI: getelementptr i32, i32 addrspace(2)* |
| 450 | ; OPT-CI-NOT: getelementptr i32, i32 addrspace(2)* |
| 451 | ; OPT-VI: getelementptr i32, i32 addrspace(2)* |
| 452 | ; OPT: br i1 |
| 453 | |
| 454 | ; GCN-LABEL: {{^}}test_sink_constant_max_20_bit_byte_offset_p1_i32: |
| 455 | ; GCN: s_and_saveexec_b64 |
| 456 | ; SI: s_mov_b32 [[OFFSET:s[0-9]+]], 0x100000{{$}} |
| 457 | ; SI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, [[OFFSET]]{{$}} |
| 458 | |
| 459 | ; CI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, 0x40000{{$}} |
| 460 | |
| 461 | ; VI: s_mov_b32 [[OFFSET:s[0-9]+]], 0x100000{{$}} |
| 462 | ; VI: s_load_dword s{{[0-9]+}}, {{s\[[0-9]+:[0-9]+\]}}, [[OFFSET]]{{$}} |
| 463 | |
| 464 | ; GCN: s_or_b64 exec, exec |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 465 | define void @test_sink_constant_max_20_bit_byte_offset_p1_i32(i32 addrspace(1)* %out, i32 addrspace(2)* %in) { |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 466 | entry: |
| 467 | %out.gep = getelementptr i32, i32 addrspace(1)* %out, i64 999999 |
| 468 | %in.gep = getelementptr i32, i32 addrspace(2)* %in, i64 262144 |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 469 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 470 | %tmp0 = icmp eq i32 %tid, 0 |
Matt Arsenault | 711b390 | 2015-08-07 20:18:34 +0000 | [diff] [blame] | 471 | br i1 %tmp0, label %endif, label %if |
| 472 | |
| 473 | if: |
| 474 | %tmp1 = load i32, i32 addrspace(2)* %in.gep |
| 475 | br label %endif |
| 476 | |
| 477 | endif: |
| 478 | %x = phi i32 [ %tmp1, %if ], [ 0, %entry ] |
| 479 | store i32 %x, i32 addrspace(1)* %out.gep |
| 480 | br label %done |
| 481 | |
| 482 | done: |
| 483 | ret void |
| 484 | } |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 485 | |
Matt Arsenault | c1e6a45 | 2016-07-09 08:02:28 +0000 | [diff] [blame] | 486 | %struct.foo = type { [3 x float], [3 x float] } |
| 487 | |
| 488 | ; OPT-LABEL: @sink_ds_address( |
| 489 | ; OPT: ptrtoint %struct.foo addrspace(3)* %ptr to i64 |
| 490 | |
| 491 | ; GCN-LABEL: {{^}}sink_ds_address: |
| 492 | ; GCN: s_load_dword [[SREG1:s[0-9]+]], |
| 493 | ; GCN: v_mov_b32_e32 [[VREG1:v[0-9]+]], [[SREG1]] |
| 494 | ; GCN-DAG: ds_read2_b32 v[{{[0-9+:[0-9]+}}], [[VREG1]] offset0:3 offset1:5 |
| 495 | define void @sink_ds_address(%struct.foo addrspace(3)* nocapture %ptr) nounwind { |
| 496 | entry: |
| 497 | %x = getelementptr inbounds %struct.foo, %struct.foo addrspace(3)* %ptr, i32 0, i32 1, i32 0 |
| 498 | %y = getelementptr inbounds %struct.foo, %struct.foo addrspace(3)* %ptr, i32 0, i32 1, i32 2 |
| 499 | br label %bb32 |
| 500 | |
| 501 | bb32: |
| 502 | %a = load float, float addrspace(3)* %x, align 4 |
| 503 | %b = load float, float addrspace(3)* %y, align 4 |
| 504 | %cmp = fcmp one float %a, %b |
| 505 | br i1 %cmp, label %bb34, label %bb33 |
| 506 | |
| 507 | bb33: |
| 508 | unreachable |
| 509 | |
| 510 | bb34: |
| 511 | unreachable |
| 512 | } |
| 513 | |
Matt Arsenault | 3cc1e00 | 2016-08-13 01:43:51 +0000 | [diff] [blame] | 514 | ; Address offset is not a multiple of 4. This is a valid mubuf offset, |
| 515 | ; but not smrd. |
| 516 | |
| 517 | ; OPT-LABEL: @test_sink_constant_small_max_mubuf_offset_load_i32_align_1( |
| 518 | ; OPT: br i1 %tmp0, |
| 519 | ; OPT: if: |
| 520 | ; OPT: %sunkaddr = ptrtoint i8 addrspace(2)* %in to i64 |
| 521 | ; OPT: %sunkaddr1 = add i64 %sunkaddr, 4095 |
| 522 | define void @test_sink_constant_small_max_mubuf_offset_load_i32_align_1(i32 addrspace(1)* %out, i8 addrspace(2)* %in) { |
| 523 | entry: |
| 524 | %out.gep = getelementptr i32, i32 addrspace(1)* %out, i32 1024 |
| 525 | %in.gep = getelementptr i8, i8 addrspace(2)* %in, i64 4095 |
| 526 | %tid = call i32 @llvm.amdgcn.mbcnt.lo(i32 -1, i32 0) #0 |
| 527 | %tmp0 = icmp eq i32 %tid, 0 |
| 528 | br i1 %tmp0, label %endif, label %if |
| 529 | |
| 530 | if: |
| 531 | %bitcast = bitcast i8 addrspace(2)* %in.gep to i32 addrspace(2)* |
| 532 | %tmp1 = load i32, i32 addrspace(2)* %bitcast, align 1 |
| 533 | br label %endif |
| 534 | |
| 535 | endif: |
| 536 | %x = phi i32 [ %tmp1, %if ], [ 0, %entry ] |
| 537 | store i32 %x, i32 addrspace(1)* %out.gep |
| 538 | br label %done |
| 539 | |
| 540 | done: |
| 541 | ret void |
| 542 | } |
| 543 | |
Tom Stellard | bc4497b | 2016-02-12 23:45:29 +0000 | [diff] [blame] | 544 | declare i32 @llvm.amdgcn.mbcnt.lo(i32, i32) #0 |
| 545 | |
| 546 | attributes #0 = { nounwind readnone } |
Matt Arsenault | 3cc1e00 | 2016-08-13 01:43:51 +0000 | [diff] [blame] | 547 | attributes #1 = { nounwind } |