1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -force-vector-width=4 -loop-vectorize -mcpu=haswell < %s | FileCheck %s
4 ;; Basic functional tests for uniform loads and stores. These are cases kept
5 ;; deliberately simple (and unoptimized by other passes) to feed the vectorizer
6 ;; with particular input IR.
8 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
9 target triple = "x86_64-unknown-linux-gnu"
11 define i32 @uniform_load(i32* align(4) %addr) {
12 ; CHECK-LABEL: @uniform_load(
14 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
16 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
18 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
19 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
20 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 4
21 ; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[INDEX]], 8
22 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX]], 12
23 ; CHECK-NEXT: [[TMP4:%.*]] = load i32, i32* [[ADDR:%.*]], align 4
24 ; CHECK-NEXT: [[TMP5:%.*]] = load i32, i32* [[ADDR]], align 4
25 ; CHECK-NEXT: [[TMP6:%.*]] = load i32, i32* [[ADDR]], align 4
26 ; CHECK-NEXT: [[TMP7:%.*]] = load i32, i32* [[ADDR]], align 4
27 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 16
28 ; CHECK-NEXT: [[TMP8:%.*]] = icmp eq i64 [[INDEX_NEXT]], 4096
29 ; CHECK-NEXT: br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
30 ; CHECK: middle.block:
31 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 4097, 4096
32 ; CHECK-NEXT: br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
34 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 4096, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
35 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
37 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
38 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[ADDR]], align 4
39 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
40 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV]], 4096
41 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP2:![0-9]+]]
43 ; CHECK-NEXT: [[LOAD_LCSSA:%.*]] = phi i32 [ [[LOAD]], [[FOR_BODY]] ], [ [[TMP7]], [[MIDDLE_BLOCK]] ]
44 ; CHECK-NEXT: ret i32 [[LOAD_LCSSA]]
50 %iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]
51 %load = load i32, i32* %addr
52 %iv.next = add nuw nsw i64 %iv, 1
53 %exitcond = icmp eq i64 %iv, 4096
54 br i1 %exitcond, label %loopexit, label %for.body
60 define i32 @uniform_load2(i32* align(4) %addr) {
61 ; CHECK-LABEL: @uniform_load2(
63 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
65 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
67 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
68 ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP8:%.*]], [[VECTOR_BODY]] ]
69 ; CHECK-NEXT: [[VEC_PHI1:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP9:%.*]], [[VECTOR_BODY]] ]
70 ; CHECK-NEXT: [[VEC_PHI2:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP10:%.*]], [[VECTOR_BODY]] ]
71 ; CHECK-NEXT: [[VEC_PHI3:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP11:%.*]], [[VECTOR_BODY]] ]
72 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
73 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 4
74 ; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[INDEX]], 8
75 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX]], 12
76 ; CHECK-NEXT: [[TMP4:%.*]] = load i32, i32* [[ADDR:%.*]], align 4
77 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[TMP4]], i32 0
78 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
79 ; CHECK-NEXT: [[TMP5:%.*]] = load i32, i32* [[ADDR]], align 4
80 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT4:%.*]] = insertelement <4 x i32> poison, i32 [[TMP5]], i32 0
81 ; CHECK-NEXT: [[BROADCAST_SPLAT5:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT4]], <4 x i32> poison, <4 x i32> zeroinitializer
82 ; CHECK-NEXT: [[TMP6:%.*]] = load i32, i32* [[ADDR]], align 4
83 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT6:%.*]] = insertelement <4 x i32> poison, i32 [[TMP6]], i32 0
84 ; CHECK-NEXT: [[BROADCAST_SPLAT7:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT6]], <4 x i32> poison, <4 x i32> zeroinitializer
85 ; CHECK-NEXT: [[TMP7:%.*]] = load i32, i32* [[ADDR]], align 4
86 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT8:%.*]] = insertelement <4 x i32> poison, i32 [[TMP7]], i32 0
87 ; CHECK-NEXT: [[BROADCAST_SPLAT9:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT8]], <4 x i32> poison, <4 x i32> zeroinitializer
88 ; CHECK-NEXT: [[TMP8]] = add <4 x i32> [[VEC_PHI]], [[BROADCAST_SPLAT]]
89 ; CHECK-NEXT: [[TMP9]] = add <4 x i32> [[VEC_PHI1]], [[BROADCAST_SPLAT5]]
90 ; CHECK-NEXT: [[TMP10]] = add <4 x i32> [[VEC_PHI2]], [[BROADCAST_SPLAT7]]
91 ; CHECK-NEXT: [[TMP11]] = add <4 x i32> [[VEC_PHI3]], [[BROADCAST_SPLAT9]]
92 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 16
93 ; CHECK-NEXT: [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], 4096
94 ; CHECK-NEXT: br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
95 ; CHECK: middle.block:
96 ; CHECK-NEXT: [[BIN_RDX:%.*]] = add <4 x i32> [[TMP9]], [[TMP8]]
97 ; CHECK-NEXT: [[BIN_RDX10:%.*]] = add <4 x i32> [[TMP10]], [[BIN_RDX]]
98 ; CHECK-NEXT: [[BIN_RDX11:%.*]] = add <4 x i32> [[TMP11]], [[BIN_RDX10]]
99 ; CHECK-NEXT: [[TMP13:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[BIN_RDX11]])
100 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 4097, 4096
101 ; CHECK-NEXT: br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
103 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 4096, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
104 ; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[TMP13]], [[MIDDLE_BLOCK]] ]
105 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
107 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
108 ; CHECK-NEXT: [[ACCUM:%.*]] = phi i32 [ [[ACCUM_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]
109 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[ADDR]], align 4
110 ; CHECK-NEXT: [[ACCUM_NEXT]] = add i32 [[ACCUM]], [[LOAD]]
111 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
112 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV]], 4096
113 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
115 ; CHECK-NEXT: [[ACCUM_NEXT_LCSSA:%.*]] = phi i32 [ [[ACCUM_NEXT]], [[FOR_BODY]] ], [ [[TMP13]], [[MIDDLE_BLOCK]] ]
116 ; CHECK-NEXT: ret i32 [[ACCUM_NEXT_LCSSA]]
122 %iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]
123 %accum = phi i32 [%accum.next, %for.body], [0, %entry]
124 %load = load i32, i32* %addr
125 %accum.next = add i32 %accum, %load
126 %iv.next = add nuw nsw i64 %iv, 1
127 %exitcond = icmp eq i64 %iv, 4096
128 br i1 %exitcond, label %loopexit, label %for.body
134 define i32 @uniform_address(i32* align(4) %addr, i32 %byte_offset) {
135 ; CHECK-LABEL: @uniform_address(
137 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
139 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
140 ; CHECK: vector.body:
141 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
142 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
143 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 4
144 ; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[INDEX]], 8
145 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX]], 12
146 ; CHECK-NEXT: [[TMP4:%.*]] = udiv i32 [[BYTE_OFFSET:%.*]], 4
147 ; CHECK-NEXT: [[TMP5:%.*]] = udiv i32 [[BYTE_OFFSET]], 4
148 ; CHECK-NEXT: [[TMP6:%.*]] = udiv i32 [[BYTE_OFFSET]], 4
149 ; CHECK-NEXT: [[TMP7:%.*]] = udiv i32 [[BYTE_OFFSET]], 4
150 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr i32, i32* [[ADDR:%.*]], i32 [[TMP4]]
151 ; CHECK-NEXT: [[TMP9:%.*]] = getelementptr i32, i32* [[ADDR]], i32 [[TMP5]]
152 ; CHECK-NEXT: [[TMP10:%.*]] = getelementptr i32, i32* [[ADDR]], i32 [[TMP6]]
153 ; CHECK-NEXT: [[TMP11:%.*]] = getelementptr i32, i32* [[ADDR]], i32 [[TMP7]]
154 ; CHECK-NEXT: [[TMP12:%.*]] = load i32, i32* [[TMP8]], align 4
155 ; CHECK-NEXT: [[TMP13:%.*]] = load i32, i32* [[TMP9]], align 4
156 ; CHECK-NEXT: [[TMP14:%.*]] = load i32, i32* [[TMP10]], align 4
157 ; CHECK-NEXT: [[TMP15:%.*]] = load i32, i32* [[TMP11]], align 4
158 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 16
159 ; CHECK-NEXT: [[TMP16:%.*]] = icmp eq i64 [[INDEX_NEXT]], 4096
160 ; CHECK-NEXT: br i1 [[TMP16]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
161 ; CHECK: middle.block:
162 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 4097, 4096
163 ; CHECK-NEXT: br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
165 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 4096, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
166 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
168 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
169 ; CHECK-NEXT: [[OFFSET:%.*]] = udiv i32 [[BYTE_OFFSET]], 4
170 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr i32, i32* [[ADDR]], i32 [[OFFSET]]
171 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[GEP]], align 4
172 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
173 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV]], 4096
174 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP7:![0-9]+]]
176 ; CHECK-NEXT: [[LOAD_LCSSA:%.*]] = phi i32 [ [[LOAD]], [[FOR_BODY]] ], [ [[TMP15]], [[MIDDLE_BLOCK]] ]
177 ; CHECK-NEXT: ret i32 [[LOAD_LCSSA]]
183 %iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]
184 %offset = udiv i32 %byte_offset, 4
185 %gep = getelementptr i32, i32* %addr, i32 %offset
186 %load = load i32, i32* %gep
187 %iv.next = add nuw nsw i64 %iv, 1
188 %exitcond = icmp eq i64 %iv, 4096
189 br i1 %exitcond, label %loopexit, label %for.body
197 define void @uniform_store_uniform_value(i32* align(4) %addr) {
198 ; CHECK-LABEL: @uniform_store_uniform_value(
200 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
202 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
203 ; CHECK: vector.body:
204 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
205 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
206 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 4
207 ; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[INDEX]], 8
208 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX]], 12
209 ; CHECK-NEXT: store i32 0, i32* [[ADDR:%.*]], align 4
210 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
211 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
212 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
213 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
214 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
215 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
216 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
217 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
218 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
219 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
220 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
221 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
222 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
223 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
224 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
225 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 16
226 ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], 4096
227 ; CHECK-NEXT: br i1 [[TMP4]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP8:![0-9]+]]
228 ; CHECK: middle.block:
229 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 4097, 4096
230 ; CHECK-NEXT: br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
232 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 4096, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
233 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
235 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
236 ; CHECK-NEXT: store i32 0, i32* [[ADDR]], align 4
237 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
238 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV]], 4096
239 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP9:![0-9]+]]
241 ; CHECK-NEXT: ret void
247 %iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]
248 store i32 0, i32* %addr
249 %iv.next = add nuw nsw i64 %iv, 1
250 %exitcond = icmp eq i64 %iv, 4096
251 br i1 %exitcond, label %loopexit, label %for.body
257 define void @uniform_store_varying_value(i32* align(4) %addr) {
258 ; CHECK-LABEL: @uniform_store_varying_value(
260 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
262 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
263 ; CHECK: vector.body:
264 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
265 ; CHECK-NEXT: [[VEC_IND:%.*]] = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
266 ; CHECK-NEXT: [[VEC_IND4:%.*]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT9:%.*]], [[VECTOR_BODY]] ]
267 ; CHECK-NEXT: [[STEP_ADD:%.*]] = add <4 x i64> [[VEC_IND]], <i64 4, i64 4, i64 4, i64 4>
268 ; CHECK-NEXT: [[STEP_ADD1:%.*]] = add <4 x i64> [[STEP_ADD]], <i64 4, i64 4, i64 4, i64 4>
269 ; CHECK-NEXT: [[STEP_ADD2:%.*]] = add <4 x i64> [[STEP_ADD1]], <i64 4, i64 4, i64 4, i64 4>
270 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
271 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 1
272 ; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[INDEX]], 2
273 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX]], 3
274 ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[INDEX]], 4
275 ; CHECK-NEXT: [[TMP5:%.*]] = add i64 [[INDEX]], 5
276 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 6
277 ; CHECK-NEXT: [[TMP7:%.*]] = add i64 [[INDEX]], 7
278 ; CHECK-NEXT: [[TMP8:%.*]] = add i64 [[INDEX]], 8
279 ; CHECK-NEXT: [[TMP9:%.*]] = add i64 [[INDEX]], 9
280 ; CHECK-NEXT: [[TMP10:%.*]] = add i64 [[INDEX]], 10
281 ; CHECK-NEXT: [[TMP11:%.*]] = add i64 [[INDEX]], 11
282 ; CHECK-NEXT: [[TMP12:%.*]] = add i64 [[INDEX]], 12
283 ; CHECK-NEXT: [[TMP13:%.*]] = add i64 [[INDEX]], 13
284 ; CHECK-NEXT: [[TMP14:%.*]] = add i64 [[INDEX]], 14
285 ; CHECK-NEXT: [[TMP15:%.*]] = add i64 [[INDEX]], 15
286 ; CHECK-NEXT: [[STEP_ADD5:%.*]] = add <4 x i32> [[VEC_IND4]], <i32 4, i32 4, i32 4, i32 4>
287 ; CHECK-NEXT: [[STEP_ADD6:%.*]] = add <4 x i32> [[STEP_ADD5]], <i32 4, i32 4, i32 4, i32 4>
288 ; CHECK-NEXT: [[STEP_ADD7:%.*]] = add <4 x i32> [[STEP_ADD6]], <i32 4, i32 4, i32 4, i32 4>
289 ; CHECK-NEXT: [[TMP16:%.*]] = extractelement <4 x i32> [[VEC_IND4]], i32 0
290 ; CHECK-NEXT: store i32 [[TMP16]], i32* [[ADDR:%.*]], align 4
291 ; CHECK-NEXT: [[TMP17:%.*]] = extractelement <4 x i32> [[VEC_IND4]], i32 1
292 ; CHECK-NEXT: store i32 [[TMP17]], i32* [[ADDR]], align 4
293 ; CHECK-NEXT: [[TMP18:%.*]] = extractelement <4 x i32> [[VEC_IND4]], i32 2
294 ; CHECK-NEXT: store i32 [[TMP18]], i32* [[ADDR]], align 4
295 ; CHECK-NEXT: [[TMP19:%.*]] = extractelement <4 x i32> [[VEC_IND4]], i32 3
296 ; CHECK-NEXT: store i32 [[TMP19]], i32* [[ADDR]], align 4
297 ; CHECK-NEXT: [[TMP20:%.*]] = extractelement <4 x i32> [[STEP_ADD5]], i32 0
298 ; CHECK-NEXT: store i32 [[TMP20]], i32* [[ADDR]], align 4
299 ; CHECK-NEXT: [[TMP21:%.*]] = extractelement <4 x i32> [[STEP_ADD5]], i32 1
300 ; CHECK-NEXT: store i32 [[TMP21]], i32* [[ADDR]], align 4
301 ; CHECK-NEXT: [[TMP22:%.*]] = extractelement <4 x i32> [[STEP_ADD5]], i32 2
302 ; CHECK-NEXT: store i32 [[TMP22]], i32* [[ADDR]], align 4
303 ; CHECK-NEXT: [[TMP23:%.*]] = extractelement <4 x i32> [[STEP_ADD5]], i32 3
304 ; CHECK-NEXT: store i32 [[TMP23]], i32* [[ADDR]], align 4
305 ; CHECK-NEXT: [[TMP24:%.*]] = extractelement <4 x i32> [[STEP_ADD6]], i32 0
306 ; CHECK-NEXT: store i32 [[TMP24]], i32* [[ADDR]], align 4
307 ; CHECK-NEXT: [[TMP25:%.*]] = extractelement <4 x i32> [[STEP_ADD6]], i32 1
308 ; CHECK-NEXT: store i32 [[TMP25]], i32* [[ADDR]], align 4
309 ; CHECK-NEXT: [[TMP26:%.*]] = extractelement <4 x i32> [[STEP_ADD6]], i32 2
310 ; CHECK-NEXT: store i32 [[TMP26]], i32* [[ADDR]], align 4
311 ; CHECK-NEXT: [[TMP27:%.*]] = extractelement <4 x i32> [[STEP_ADD6]], i32 3
312 ; CHECK-NEXT: store i32 [[TMP27]], i32* [[ADDR]], align 4
313 ; CHECK-NEXT: [[TMP28:%.*]] = extractelement <4 x i32> [[STEP_ADD7]], i32 0
314 ; CHECK-NEXT: store i32 [[TMP28]], i32* [[ADDR]], align 4
315 ; CHECK-NEXT: [[TMP29:%.*]] = extractelement <4 x i32> [[STEP_ADD7]], i32 1
316 ; CHECK-NEXT: store i32 [[TMP29]], i32* [[ADDR]], align 4
317 ; CHECK-NEXT: [[TMP30:%.*]] = extractelement <4 x i32> [[STEP_ADD7]], i32 2
318 ; CHECK-NEXT: store i32 [[TMP30]], i32* [[ADDR]], align 4
319 ; CHECK-NEXT: [[TMP31:%.*]] = extractelement <4 x i32> [[STEP_ADD7]], i32 3
320 ; CHECK-NEXT: store i32 [[TMP31]], i32* [[ADDR]], align 4
321 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 16
322 ; CHECK-NEXT: [[VEC_IND_NEXT]] = add <4 x i64> [[STEP_ADD2]], <i64 4, i64 4, i64 4, i64 4>
323 ; CHECK-NEXT: [[VEC_IND_NEXT9]] = add <4 x i32> [[STEP_ADD7]], <i32 4, i32 4, i32 4, i32 4>
324 ; CHECK-NEXT: [[TMP32:%.*]] = icmp eq i64 [[INDEX_NEXT]], 4096
325 ; CHECK-NEXT: br i1 [[TMP32]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP10:![0-9]+]]
326 ; CHECK: middle.block:
327 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 4097, 4096
328 ; CHECK-NEXT: br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
330 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 4096, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
331 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
333 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
334 ; CHECK-NEXT: [[IV_I32:%.*]] = trunc i64 [[IV]] to i32
335 ; CHECK-NEXT: store i32 [[IV_I32]], i32* [[ADDR]], align 4
336 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
337 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV]], 4096
338 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP11:![0-9]+]]
340 ; CHECK-NEXT: ret void
346 %iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]
347 %iv.i32 = trunc i64 %iv to i32
348 store i32 %iv.i32, i32* %addr
349 %iv.next = add nuw nsw i64 %iv, 1
350 %exitcond = icmp eq i64 %iv, 4096
351 br i1 %exitcond, label %loopexit, label %for.body
357 define void @uniform_rw(i32* align(4) %addr) {
358 ; CHECK-LABEL: @uniform_rw(
360 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
362 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY:%.*]] ]
363 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[ADDR:%.*]], align 4
364 ; CHECK-NEXT: [[INC:%.*]] = add i32 [[LOAD]], 1
365 ; CHECK-NEXT: store i32 [[INC]], i32* [[ADDR]], align 4
366 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
367 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV]], 4096
368 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOPEXIT:%.*]], label [[FOR_BODY]]
370 ; CHECK-NEXT: ret void
376 %iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]
377 %load = load i32, i32* %addr
378 %inc = add i32 %load, 1
379 store i32 %inc, i32* %addr
380 %iv.next = add nuw nsw i64 %iv, 1
381 %exitcond = icmp eq i64 %iv, 4096
382 br i1 %exitcond, label %loopexit, label %for.body
388 define void @uniform_copy(i32* %A, i32* %B) {
389 ; CHECK-LABEL: @uniform_copy(
391 ; CHECK-NEXT: [[B1:%.*]] = bitcast i32* [[B:%.*]] to i8*
392 ; CHECK-NEXT: [[A3:%.*]] = bitcast i32* [[A:%.*]] to i8*
393 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
394 ; CHECK: vector.memcheck:
395 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i32, i32* [[B]], i64 1
396 ; CHECK-NEXT: [[SCEVGEP2:%.*]] = bitcast i32* [[SCEVGEP]] to i8*
397 ; CHECK-NEXT: [[SCEVGEP4:%.*]] = getelementptr i32, i32* [[A]], i64 1
398 ; CHECK-NEXT: [[SCEVGEP45:%.*]] = bitcast i32* [[SCEVGEP4]] to i8*
399 ; CHECK-NEXT: [[BOUND0:%.*]] = icmp ult i8* [[B1]], [[SCEVGEP45]]
400 ; CHECK-NEXT: [[BOUND1:%.*]] = icmp ult i8* [[A3]], [[SCEVGEP2]]
401 ; CHECK-NEXT: [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
402 ; CHECK-NEXT: [[MEMCHECK_CONFLICT:%.*]] = and i1 [[FOUND_CONFLICT]], true
403 ; CHECK-NEXT: br i1 [[MEMCHECK_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
405 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
406 ; CHECK: vector.body:
407 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
408 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
409 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 4
410 ; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[INDEX]], 8
411 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX]], 12
412 ; CHECK-NEXT: [[TMP4:%.*]] = load i32, i32* [[A]], align 4, !alias.scope !12
413 ; CHECK-NEXT: [[TMP5:%.*]] = load i32, i32* [[A]], align 4, !alias.scope !12
414 ; CHECK-NEXT: [[TMP6:%.*]] = load i32, i32* [[A]], align 4, !alias.scope !12
415 ; CHECK-NEXT: [[TMP7:%.*]] = load i32, i32* [[A]], align 4, !alias.scope !12
416 ; CHECK-NEXT: store i32 [[TMP4]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
417 ; CHECK-NEXT: store i32 [[TMP4]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
418 ; CHECK-NEXT: store i32 [[TMP4]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
419 ; CHECK-NEXT: store i32 [[TMP4]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
420 ; CHECK-NEXT: store i32 [[TMP5]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
421 ; CHECK-NEXT: store i32 [[TMP5]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
422 ; CHECK-NEXT: store i32 [[TMP5]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
423 ; CHECK-NEXT: store i32 [[TMP5]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
424 ; CHECK-NEXT: store i32 [[TMP6]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
425 ; CHECK-NEXT: store i32 [[TMP6]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
426 ; CHECK-NEXT: store i32 [[TMP6]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
427 ; CHECK-NEXT: store i32 [[TMP6]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
428 ; CHECK-NEXT: store i32 [[TMP7]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
429 ; CHECK-NEXT: store i32 [[TMP7]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
430 ; CHECK-NEXT: store i32 [[TMP7]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
431 ; CHECK-NEXT: store i32 [[TMP7]], i32* [[B]], align 4, !alias.scope !15, !noalias !12
432 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 16
433 ; CHECK-NEXT: [[TMP8:%.*]] = icmp eq i64 [[INDEX_NEXT]], 4096
434 ; CHECK-NEXT: br i1 [[TMP8]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP17:![0-9]+]]
435 ; CHECK: middle.block:
436 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 4097, 4096
437 ; CHECK-NEXT: br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
439 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 4096, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
440 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
442 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
443 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[A]], align 4
444 ; CHECK-NEXT: store i32 [[LOAD]], i32* [[B]], align 4
445 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
446 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV]], 4096
447 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP18:![0-9]+]]
449 ; CHECK-NEXT: ret void
455 %iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]
456 %load = load i32, i32* %A
457 store i32 %load, i32* %B
458 %iv.next = add nuw nsw i64 %iv, 1
459 %exitcond = icmp eq i64 %iv, 4096
460 br i1 %exitcond, label %loopexit, label %for.body
467 declare void @init(i32*)
469 ;; Count the number of bits set in a bit vector -- key point of relevance is
470 ;; that the byte load is uniform across 8 iterations at a time.
471 define i32 @test_count_bits(i8* %test_base) {
472 ; CHECK-LABEL: @test_count_bits(
474 ; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [4096 x i32], align 4
475 ; CHECK-NEXT: [[BASE:%.*]] = bitcast [4096 x i32]* [[ALLOCA]] to i32*
476 ; CHECK-NEXT: call void @init(i32* [[BASE]])
477 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
479 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
480 ; CHECK: vector.body:
481 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
482 ; CHECK-NEXT: [[VEC_IND:%.*]] = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
483 ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP52:%.*]], [[VECTOR_BODY]] ]
484 ; CHECK-NEXT: [[VEC_PHI2:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP53:%.*]], [[VECTOR_BODY]] ]
485 ; CHECK-NEXT: [[STEP_ADD:%.*]] = add <4 x i64> [[VEC_IND]], <i64 4, i64 4, i64 4, i64 4>
486 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
487 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 1
488 ; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[INDEX]], 2
489 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX]], 3
490 ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[INDEX]], 4
491 ; CHECK-NEXT: [[TMP5:%.*]] = add i64 [[INDEX]], 5
492 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 6
493 ; CHECK-NEXT: [[TMP7:%.*]] = add i64 [[INDEX]], 7
494 ; CHECK-NEXT: [[TMP8:%.*]] = udiv <4 x i64> [[VEC_IND]], <i64 8, i64 8, i64 8, i64 8>
495 ; CHECK-NEXT: [[TMP9:%.*]] = udiv <4 x i64> [[STEP_ADD]], <i64 8, i64 8, i64 8, i64 8>
496 ; CHECK-NEXT: [[TMP10:%.*]] = extractelement <4 x i64> [[TMP8]], i32 0
497 ; CHECK-NEXT: [[TMP11:%.*]] = getelementptr inbounds i8, i8* [[TEST_BASE:%.*]], i64 [[TMP10]]
498 ; CHECK-NEXT: [[TMP12:%.*]] = extractelement <4 x i64> [[TMP8]], i32 1
499 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr inbounds i8, i8* [[TEST_BASE]], i64 [[TMP12]]
500 ; CHECK-NEXT: [[TMP14:%.*]] = extractelement <4 x i64> [[TMP8]], i32 2
501 ; CHECK-NEXT: [[TMP15:%.*]] = getelementptr inbounds i8, i8* [[TEST_BASE]], i64 [[TMP14]]
502 ; CHECK-NEXT: [[TMP16:%.*]] = extractelement <4 x i64> [[TMP8]], i32 3
503 ; CHECK-NEXT: [[TMP17:%.*]] = getelementptr inbounds i8, i8* [[TEST_BASE]], i64 [[TMP16]]
504 ; CHECK-NEXT: [[TMP18:%.*]] = extractelement <4 x i64> [[TMP9]], i32 0
505 ; CHECK-NEXT: [[TMP19:%.*]] = getelementptr inbounds i8, i8* [[TEST_BASE]], i64 [[TMP18]]
506 ; CHECK-NEXT: [[TMP20:%.*]] = extractelement <4 x i64> [[TMP9]], i32 1
507 ; CHECK-NEXT: [[TMP21:%.*]] = getelementptr inbounds i8, i8* [[TEST_BASE]], i64 [[TMP20]]
508 ; CHECK-NEXT: [[TMP22:%.*]] = extractelement <4 x i64> [[TMP9]], i32 2
509 ; CHECK-NEXT: [[TMP23:%.*]] = getelementptr inbounds i8, i8* [[TEST_BASE]], i64 [[TMP22]]
510 ; CHECK-NEXT: [[TMP24:%.*]] = extractelement <4 x i64> [[TMP9]], i32 3
511 ; CHECK-NEXT: [[TMP25:%.*]] = getelementptr inbounds i8, i8* [[TEST_BASE]], i64 [[TMP24]]
512 ; CHECK-NEXT: [[TMP26:%.*]] = load i8, i8* [[TMP11]], align 1
513 ; CHECK-NEXT: [[TMP27:%.*]] = load i8, i8* [[TMP13]], align 1
514 ; CHECK-NEXT: [[TMP28:%.*]] = load i8, i8* [[TMP15]], align 1
515 ; CHECK-NEXT: [[TMP29:%.*]] = load i8, i8* [[TMP17]], align 1
516 ; CHECK-NEXT: [[TMP30:%.*]] = insertelement <4 x i8> poison, i8 [[TMP26]], i32 0
517 ; CHECK-NEXT: [[TMP31:%.*]] = insertelement <4 x i8> [[TMP30]], i8 [[TMP27]], i32 1
518 ; CHECK-NEXT: [[TMP32:%.*]] = insertelement <4 x i8> [[TMP31]], i8 [[TMP28]], i32 2
519 ; CHECK-NEXT: [[TMP33:%.*]] = insertelement <4 x i8> [[TMP32]], i8 [[TMP29]], i32 3
520 ; CHECK-NEXT: [[TMP34:%.*]] = load i8, i8* [[TMP19]], align 1
521 ; CHECK-NEXT: [[TMP35:%.*]] = load i8, i8* [[TMP21]], align 1
522 ; CHECK-NEXT: [[TMP36:%.*]] = load i8, i8* [[TMP23]], align 1
523 ; CHECK-NEXT: [[TMP37:%.*]] = load i8, i8* [[TMP25]], align 1
524 ; CHECK-NEXT: [[TMP38:%.*]] = insertelement <4 x i8> poison, i8 [[TMP34]], i32 0
525 ; CHECK-NEXT: [[TMP39:%.*]] = insertelement <4 x i8> [[TMP38]], i8 [[TMP35]], i32 1
526 ; CHECK-NEXT: [[TMP40:%.*]] = insertelement <4 x i8> [[TMP39]], i8 [[TMP36]], i32 2
527 ; CHECK-NEXT: [[TMP41:%.*]] = insertelement <4 x i8> [[TMP40]], i8 [[TMP37]], i32 3
528 ; CHECK-NEXT: [[TMP42:%.*]] = urem <4 x i64> [[VEC_IND]], <i64 8, i64 8, i64 8, i64 8>
529 ; CHECK-NEXT: [[TMP43:%.*]] = urem <4 x i64> [[STEP_ADD]], <i64 8, i64 8, i64 8, i64 8>
530 ; CHECK-NEXT: [[TMP44:%.*]] = trunc <4 x i64> [[TMP42]] to <4 x i8>
531 ; CHECK-NEXT: [[TMP45:%.*]] = trunc <4 x i64> [[TMP43]] to <4 x i8>
532 ; CHECK-NEXT: [[TMP46:%.*]] = lshr <4 x i8> [[TMP33]], [[TMP44]]
533 ; CHECK-NEXT: [[TMP47:%.*]] = lshr <4 x i8> [[TMP41]], [[TMP45]]
534 ; CHECK-NEXT: [[TMP48:%.*]] = and <4 x i8> [[TMP46]], <i8 1, i8 1, i8 1, i8 1>
535 ; CHECK-NEXT: [[TMP49:%.*]] = and <4 x i8> [[TMP47]], <i8 1, i8 1, i8 1, i8 1>
536 ; CHECK-NEXT: [[TMP50:%.*]] = zext <4 x i8> [[TMP48]] to <4 x i32>
537 ; CHECK-NEXT: [[TMP51:%.*]] = zext <4 x i8> [[TMP49]] to <4 x i32>
538 ; CHECK-NEXT: [[TMP52]] = add <4 x i32> [[VEC_PHI]], [[TMP50]]
539 ; CHECK-NEXT: [[TMP53]] = add <4 x i32> [[VEC_PHI2]], [[TMP51]]
540 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 8
541 ; CHECK-NEXT: [[VEC_IND_NEXT]] = add <4 x i64> [[STEP_ADD]], <i64 4, i64 4, i64 4, i64 4>
542 ; CHECK-NEXT: [[TMP54:%.*]] = icmp eq i64 [[INDEX_NEXT]], 4096
543 ; CHECK-NEXT: br i1 [[TMP54]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP19:![0-9]+]]
544 ; CHECK: middle.block:
545 ; CHECK-NEXT: [[BIN_RDX:%.*]] = add <4 x i32> [[TMP53]], [[TMP52]]
546 ; CHECK-NEXT: [[TMP55:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[BIN_RDX]])
547 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 4096, 4096
548 ; CHECK-NEXT: br i1 [[CMP_N]], label [[LOOP_EXIT:%.*]], label [[SCALAR_PH]]
550 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 4096, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
551 ; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[TMP55]], [[MIDDLE_BLOCK]] ]
552 ; CHECK-NEXT: br label [[LOOP:%.*]]
554 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
555 ; CHECK-NEXT: [[ACCUM:%.*]] = phi i32 [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ], [ [[ACCUM_NEXT:%.*]], [[LOOP]] ]
556 ; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV]], 1
557 ; CHECK-NEXT: [[BYTE:%.*]] = udiv i64 [[IV]], 8
558 ; CHECK-NEXT: [[TEST_ADDR:%.*]] = getelementptr inbounds i8, i8* [[TEST_BASE]], i64 [[BYTE]]
559 ; CHECK-NEXT: [[EARLYCND:%.*]] = load i8, i8* [[TEST_ADDR]], align 1
560 ; CHECK-NEXT: [[BIT:%.*]] = urem i64 [[IV]], 8
561 ; CHECK-NEXT: [[BIT_TRUNC:%.*]] = trunc i64 [[BIT]] to i8
562 ; CHECK-NEXT: [[MASK:%.*]] = lshr i8 [[EARLYCND]], [[BIT_TRUNC]]
563 ; CHECK-NEXT: [[TEST:%.*]] = and i8 [[MASK]], 1
564 ; CHECK-NEXT: [[VAL:%.*]] = zext i8 [[TEST]] to i32
565 ; CHECK-NEXT: [[ACCUM_NEXT]] = add i32 [[ACCUM]], [[VAL]]
566 ; CHECK-NEXT: [[EXIT:%.*]] = icmp ugt i64 [[IV]], 4094
567 ; CHECK-NEXT: br i1 [[EXIT]], label [[LOOP_EXIT]], label [[LOOP]], !llvm.loop [[LOOP20:![0-9]+]]
569 ; CHECK-NEXT: [[ACCUM_NEXT_LCSSA:%.*]] = phi i32 [ [[ACCUM_NEXT]], [[LOOP]] ], [ [[TMP55]], [[MIDDLE_BLOCK]] ]
570 ; CHECK-NEXT: ret i32 [[ACCUM_NEXT_LCSSA]]
573 %alloca = alloca [4096 x i32]
574 %base = bitcast [4096 x i32]* %alloca to i32*
575 call void @init(i32* %base)
578 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
579 %accum = phi i32 [ 0, %entry ], [ %accum.next, %loop ]
580 %iv.next = add i64 %iv, 1
581 %byte = udiv i64 %iv, 8
582 %test_addr = getelementptr inbounds i8, i8* %test_base, i64 %byte
583 %earlycnd = load i8, i8* %test_addr
584 %bit = urem i64 %iv, 8
585 %bit.trunc = trunc i64 %bit to i8
586 %mask = lshr i8 %earlycnd, %bit.trunc
587 %test = and i8 %mask, 1
588 %val = zext i8 %test to i32
589 %accum.next = add i32 %accum, %val
590 %exit = icmp ugt i64 %iv, 4094
591 br i1 %exit, label %loop_exit, label %loop
597 ;; Same as uniform_load, but show that the uniformity analysis can handle
598 ;; pointer operands which are not local to the function.
599 @GAddr = external global i32 align 4
600 define i32 @uniform_load_global() {
601 ; CHECK-LABEL: @uniform_load_global(
603 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
605 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
606 ; CHECK: vector.body:
607 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
608 ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP8:%.*]], [[VECTOR_BODY]] ]
609 ; CHECK-NEXT: [[VEC_PHI1:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP9:%.*]], [[VECTOR_BODY]] ]
610 ; CHECK-NEXT: [[VEC_PHI2:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP10:%.*]], [[VECTOR_BODY]] ]
611 ; CHECK-NEXT: [[VEC_PHI3:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP11:%.*]], [[VECTOR_BODY]] ]
612 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
613 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 4
614 ; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[INDEX]], 8
615 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX]], 12
616 ; CHECK-NEXT: [[TMP4:%.*]] = load i32, i32* @GAddr, align 4
617 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[TMP4]], i32 0
618 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
619 ; CHECK-NEXT: [[TMP5:%.*]] = load i32, i32* @GAddr, align 4
620 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT4:%.*]] = insertelement <4 x i32> poison, i32 [[TMP5]], i32 0
621 ; CHECK-NEXT: [[BROADCAST_SPLAT5:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT4]], <4 x i32> poison, <4 x i32> zeroinitializer
622 ; CHECK-NEXT: [[TMP6:%.*]] = load i32, i32* @GAddr, align 4
623 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT6:%.*]] = insertelement <4 x i32> poison, i32 [[TMP6]], i32 0
624 ; CHECK-NEXT: [[BROADCAST_SPLAT7:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT6]], <4 x i32> poison, <4 x i32> zeroinitializer
625 ; CHECK-NEXT: [[TMP7:%.*]] = load i32, i32* @GAddr, align 4
626 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT8:%.*]] = insertelement <4 x i32> poison, i32 [[TMP7]], i32 0
627 ; CHECK-NEXT: [[BROADCAST_SPLAT9:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT8]], <4 x i32> poison, <4 x i32> zeroinitializer
628 ; CHECK-NEXT: [[TMP8]] = add <4 x i32> [[VEC_PHI]], [[BROADCAST_SPLAT]]
629 ; CHECK-NEXT: [[TMP9]] = add <4 x i32> [[VEC_PHI1]], [[BROADCAST_SPLAT5]]
630 ; CHECK-NEXT: [[TMP10]] = add <4 x i32> [[VEC_PHI2]], [[BROADCAST_SPLAT7]]
631 ; CHECK-NEXT: [[TMP11]] = add <4 x i32> [[VEC_PHI3]], [[BROADCAST_SPLAT9]]
632 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 16
633 ; CHECK-NEXT: [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], 4096
634 ; CHECK-NEXT: br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP21:![0-9]+]]
635 ; CHECK: middle.block:
636 ; CHECK-NEXT: [[BIN_RDX:%.*]] = add <4 x i32> [[TMP9]], [[TMP8]]
637 ; CHECK-NEXT: [[BIN_RDX10:%.*]] = add <4 x i32> [[TMP10]], [[BIN_RDX]]
638 ; CHECK-NEXT: [[BIN_RDX11:%.*]] = add <4 x i32> [[TMP11]], [[BIN_RDX10]]
639 ; CHECK-NEXT: [[TMP13:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[BIN_RDX11]])
640 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 4097, 4096
641 ; CHECK-NEXT: br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
643 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 4096, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
644 ; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[TMP13]], [[MIDDLE_BLOCK]] ]
645 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
647 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
648 ; CHECK-NEXT: [[ACCUM:%.*]] = phi i32 [ [[ACCUM_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]
649 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* @GAddr, align 4
650 ; CHECK-NEXT: [[ACCUM_NEXT]] = add i32 [[ACCUM]], [[LOAD]]
651 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
652 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV]], 4096
653 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP22:![0-9]+]]
655 ; CHECK-NEXT: [[ACCUM_NEXT_LCSSA:%.*]] = phi i32 [ [[ACCUM_NEXT]], [[FOR_BODY]] ], [ [[TMP13]], [[MIDDLE_BLOCK]] ]
656 ; CHECK-NEXT: ret i32 [[ACCUM_NEXT_LCSSA]]
662 %iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]
663 %accum = phi i32 [%accum.next, %for.body], [0, %entry]
664 %load = load i32, i32* @GAddr
665 %accum.next = add i32 %accum, %load
666 %iv.next = add nuw nsw i64 %iv, 1
667 %exitcond = icmp eq i64 %iv, 4096
668 br i1 %exitcond, label %loopexit, label %for.body
674 ;; Same as the global case, but using a constexpr
675 define i32 @uniform_load_constexpr() {
676 ; CHECK-LABEL: @uniform_load_constexpr(
678 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
680 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
681 ; CHECK: vector.body:
682 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
683 ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP8:%.*]], [[VECTOR_BODY]] ]
684 ; CHECK-NEXT: [[VEC_PHI1:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP9:%.*]], [[VECTOR_BODY]] ]
685 ; CHECK-NEXT: [[VEC_PHI2:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP10:%.*]], [[VECTOR_BODY]] ]
686 ; CHECK-NEXT: [[VEC_PHI3:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP11:%.*]], [[VECTOR_BODY]] ]
687 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
688 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 4
689 ; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[INDEX]], 8
690 ; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[INDEX]], 12
691 ; CHECK-NEXT: [[TMP4:%.*]] = load i32, i32* getelementptr (i32, i32* @GAddr, i64 5), align 4
692 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[TMP4]], i32 0
693 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer
694 ; CHECK-NEXT: [[TMP5:%.*]] = load i32, i32* getelementptr (i32, i32* @GAddr, i64 5), align 4
695 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT4:%.*]] = insertelement <4 x i32> poison, i32 [[TMP5]], i32 0
696 ; CHECK-NEXT: [[BROADCAST_SPLAT5:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT4]], <4 x i32> poison, <4 x i32> zeroinitializer
697 ; CHECK-NEXT: [[TMP6:%.*]] = load i32, i32* getelementptr (i32, i32* @GAddr, i64 5), align 4
698 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT6:%.*]] = insertelement <4 x i32> poison, i32 [[TMP6]], i32 0
699 ; CHECK-NEXT: [[BROADCAST_SPLAT7:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT6]], <4 x i32> poison, <4 x i32> zeroinitializer
700 ; CHECK-NEXT: [[TMP7:%.*]] = load i32, i32* getelementptr (i32, i32* @GAddr, i64 5), align 4
701 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT8:%.*]] = insertelement <4 x i32> poison, i32 [[TMP7]], i32 0
702 ; CHECK-NEXT: [[BROADCAST_SPLAT9:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT8]], <4 x i32> poison, <4 x i32> zeroinitializer
703 ; CHECK-NEXT: [[TMP8]] = add <4 x i32> [[VEC_PHI]], [[BROADCAST_SPLAT]]
704 ; CHECK-NEXT: [[TMP9]] = add <4 x i32> [[VEC_PHI1]], [[BROADCAST_SPLAT5]]
705 ; CHECK-NEXT: [[TMP10]] = add <4 x i32> [[VEC_PHI2]], [[BROADCAST_SPLAT7]]
706 ; CHECK-NEXT: [[TMP11]] = add <4 x i32> [[VEC_PHI3]], [[BROADCAST_SPLAT9]]
707 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 16
708 ; CHECK-NEXT: [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], 4096
709 ; CHECK-NEXT: br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP23:![0-9]+]]
710 ; CHECK: middle.block:
711 ; CHECK-NEXT: [[BIN_RDX:%.*]] = add <4 x i32> [[TMP9]], [[TMP8]]
712 ; CHECK-NEXT: [[BIN_RDX10:%.*]] = add <4 x i32> [[TMP10]], [[BIN_RDX]]
713 ; CHECK-NEXT: [[BIN_RDX11:%.*]] = add <4 x i32> [[TMP11]], [[BIN_RDX10]]
714 ; CHECK-NEXT: [[TMP13:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[BIN_RDX11]])
715 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 4097, 4096
716 ; CHECK-NEXT: br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
718 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 4096, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
719 ; CHECK-NEXT: [[BC_MERGE_RDX:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[TMP13]], [[MIDDLE_BLOCK]] ]
720 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
722 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
723 ; CHECK-NEXT: [[ACCUM:%.*]] = phi i32 [ [[ACCUM_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_MERGE_RDX]], [[SCALAR_PH]] ]
724 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* getelementptr (i32, i32* @GAddr, i64 5), align 4
725 ; CHECK-NEXT: [[ACCUM_NEXT]] = add i32 [[ACCUM]], [[LOAD]]
726 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
727 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV]], 4096
728 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP24:![0-9]+]]
730 ; CHECK-NEXT: [[ACCUM_NEXT_LCSSA:%.*]] = phi i32 [ [[ACCUM_NEXT]], [[FOR_BODY]] ], [ [[TMP13]], [[MIDDLE_BLOCK]] ]
731 ; CHECK-NEXT: ret i32 [[ACCUM_NEXT_LCSSA]]
736 for.body: ; preds = %for.body, %entry
737 %iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]
738 %accum = phi i32 [ %accum.next, %for.body ], [ 0, %entry ]
739 %load = load i32, i32* getelementptr (i32, i32* @GAddr, i64 5), align 4
740 %accum.next = add i32 %accum, %load
741 %iv.next = add nuw nsw i64 %iv, 1
742 %exitcond = icmp eq i64 %iv, 4096
743 br i1 %exitcond, label %loopexit, label %for.body
745 loopexit: ; preds = %for.body