1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=aggressive-instcombine -S -mtriple aarch64 -data-layout="e-n64" | FileCheck %s --check-prefixes=ALL,LE
3 ; RUN: opt < %s -passes=aggressive-instcombine -S -mtriple aarch64 -data-layout="E-n64" | FileCheck %s --check-prefixes=ALL,BE
5 define i16 @loadCombine_2consecutive(ptr %p) {
7 ; ALL-LABEL: @loadCombine_2consecutive(
8 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
9 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
10 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
11 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i16
12 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i16
13 ; ALL-NEXT: [[S2:%.*]] = shl i16 [[E2]], 8
14 ; ALL-NEXT: [[O1:%.*]] = or i16 [[E1]], [[S2]]
15 ; ALL-NEXT: ret i16 [[O1]]
17 %p1 = getelementptr i8, ptr %p, i32 1
19 %l2 = load i8, ptr %p1
20 %e1 = zext i8 %l1 to i16
21 %e2 = zext i8 %l2 to i16
27 define i16 @loadCombine_2consecutive_BE(ptr %p) {
28 ; ALL-LABEL: @loadCombine_2consecutive_BE(
29 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
30 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
31 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
32 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i16
33 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i16
34 ; ALL-NEXT: [[S1:%.*]] = shl i16 [[E1]], 8
35 ; ALL-NEXT: [[O1:%.*]] = or i16 [[S1]], [[E2]]
36 ; ALL-NEXT: ret i16 [[O1]]
38 %p1 = getelementptr i8, ptr %p, i32 1
40 %l2 = load i8, ptr %p1
41 %e1 = zext i8 %l1 to i16
42 %e2 = zext i8 %l2 to i16
48 define i32 @loadCombine_4consecutive(ptr %p) {
49 ; LE-LABEL: @loadCombine_4consecutive(
50 ; LE-NEXT: [[L1:%.*]] = load i32, ptr [[P:%.*]], align 1
51 ; LE-NEXT: ret i32 [[L1]]
53 ; BE-LABEL: @loadCombine_4consecutive(
54 ; BE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
55 ; BE-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
56 ; BE-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
57 ; BE-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
58 ; BE-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
59 ; BE-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
60 ; BE-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
61 ; BE-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
62 ; BE-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
63 ; BE-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
64 ; BE-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
65 ; BE-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
66 ; BE-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
67 ; BE-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
68 ; BE-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
69 ; BE-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
70 ; BE-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
71 ; BE-NEXT: ret i32 [[O3]]
73 %p1 = getelementptr i8, ptr %p, i32 1
74 %p2 = getelementptr i8, ptr %p, i32 2
75 %p3 = getelementptr i8, ptr %p, i32 3
77 %l2 = load i8, ptr %p1
78 %l3 = load i8, ptr %p2
79 %l4 = load i8, ptr %p3
81 %e1 = zext i8 %l1 to i32
82 %e2 = zext i8 %l2 to i32
83 %e3 = zext i8 %l3 to i32
84 %e4 = zext i8 %l4 to i32
96 define i32 @loadCombine_4consecutive_BE(ptr %p) {
97 ; LE-LABEL: @loadCombine_4consecutive_BE(
98 ; LE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
99 ; LE-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
100 ; LE-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
101 ; LE-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
102 ; LE-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
103 ; LE-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
104 ; LE-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
105 ; LE-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
106 ; LE-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
107 ; LE-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
108 ; LE-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
109 ; LE-NEXT: [[S1:%.*]] = shl i32 [[E1]], 24
110 ; LE-NEXT: [[S2:%.*]] = shl i32 [[E2]], 16
111 ; LE-NEXT: [[S3:%.*]] = shl i32 [[E3]], 8
112 ; LE-NEXT: [[O1:%.*]] = or i32 [[S1]], [[S2]]
113 ; LE-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
114 ; LE-NEXT: [[O3:%.*]] = or i32 [[O2]], [[E4]]
115 ; LE-NEXT: ret i32 [[O3]]
117 ; BE-LABEL: @loadCombine_4consecutive_BE(
118 ; BE-NEXT: [[L1:%.*]] = load i32, ptr [[P:%.*]], align 1
119 ; BE-NEXT: ret i32 [[L1]]
121 %p1 = getelementptr i8, ptr %p, i32 1
122 %p2 = getelementptr i8, ptr %p, i32 2
123 %p3 = getelementptr i8, ptr %p, i32 3
124 %l1 = load i8, ptr %p
125 %l2 = load i8, ptr %p1
126 %l3 = load i8, ptr %p2
127 %l4 = load i8, ptr %p3
129 %e1 = zext i8 %l1 to i32
130 %e2 = zext i8 %l2 to i32
131 %e3 = zext i8 %l3 to i32
132 %e4 = zext i8 %l4 to i32
134 %s1 = shl i32 %e1, 24
135 %s2 = shl i32 %e2, 16
138 %o1 = or i32 %s1, %s2
139 %o2 = or i32 %o1, %s3
140 %o3 = or i32 %o2, %e4
144 define i32 @loadCombine_4consecutive_alias(ptr %p) {
145 ; LE-LABEL: @loadCombine_4consecutive_alias(
146 ; LE-NEXT: [[L1:%.*]] = load i32, ptr [[P:%.*]], align 1
147 ; LE-NEXT: store i8 10, ptr [[P]], align 1
148 ; LE-NEXT: ret i32 [[L1]]
150 ; BE-LABEL: @loadCombine_4consecutive_alias(
151 ; BE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
152 ; BE-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
153 ; BE-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
154 ; BE-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
155 ; BE-NEXT: store i8 10, ptr [[P]], align 1
156 ; BE-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
157 ; BE-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
158 ; BE-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
159 ; BE-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
160 ; BE-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
161 ; BE-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
162 ; BE-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
163 ; BE-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
164 ; BE-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
165 ; BE-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
166 ; BE-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
167 ; BE-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
168 ; BE-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
169 ; BE-NEXT: ret i32 [[O3]]
171 %p1 = getelementptr i8, ptr %p, i32 1
172 %p2 = getelementptr i8, ptr %p, i32 2
173 %p3 = getelementptr i8, ptr %p, i32 3
174 %l1 = load i8, ptr %p
176 %l2 = load i8, ptr %p1
177 %l3 = load i8, ptr %p2
178 %l4 = load i8, ptr %p3
180 %e1 = zext i8 %l1 to i32
181 %e2 = zext i8 %l2 to i32
182 %e3 = zext i8 %l3 to i32
183 %e4 = zext i8 %l4 to i32
186 %s3 = shl i32 %e3, 16
187 %s4 = shl i32 %e4, 24
189 %o1 = or i32 %e1, %s2
190 %o2 = or i32 %o1, %s3
191 %o3 = or i32 %o2, %s4
195 define i32 @loadCombine_4consecutive_alias_BE(ptr %p) {
196 ; LE-LABEL: @loadCombine_4consecutive_alias_BE(
197 ; LE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
198 ; LE-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
199 ; LE-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
200 ; LE-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
201 ; LE-NEXT: store i8 10, ptr [[P]], align 1
202 ; LE-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
203 ; LE-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
204 ; LE-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
205 ; LE-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
206 ; LE-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
207 ; LE-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
208 ; LE-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
209 ; LE-NEXT: [[S1:%.*]] = shl i32 [[E1]], 24
210 ; LE-NEXT: [[S2:%.*]] = shl i32 [[E2]], 16
211 ; LE-NEXT: [[S3:%.*]] = shl i32 [[E3]], 8
212 ; LE-NEXT: [[O1:%.*]] = or i32 [[S1]], [[S2]]
213 ; LE-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
214 ; LE-NEXT: [[O3:%.*]] = or i32 [[O2]], [[E4]]
215 ; LE-NEXT: ret i32 [[O3]]
217 ; BE-LABEL: @loadCombine_4consecutive_alias_BE(
218 ; BE-NEXT: [[L1:%.*]] = load i32, ptr [[P:%.*]], align 1
219 ; BE-NEXT: store i8 10, ptr [[P]], align 1
220 ; BE-NEXT: ret i32 [[L1]]
222 %p1 = getelementptr i8, ptr %p, i32 1
223 %p2 = getelementptr i8, ptr %p, i32 2
224 %p3 = getelementptr i8, ptr %p, i32 3
225 %l1 = load i8, ptr %p
227 %l2 = load i8, ptr %p1
228 %l3 = load i8, ptr %p2
229 %l4 = load i8, ptr %p3
231 %e1 = zext i8 %l1 to i32
232 %e2 = zext i8 %l2 to i32
233 %e3 = zext i8 %l3 to i32
234 %e4 = zext i8 %l4 to i32
236 %s1 = shl i32 %e1, 24
237 %s2 = shl i32 %e2, 16
240 %o1 = or i32 %s1, %s2
241 %o2 = or i32 %o1, %s3
242 %o3 = or i32 %o2, %e4
246 define i32 @loadCombine_4consecutive_alias2(ptr %p, ptr %pstr) {
247 ; ALL-LABEL: @loadCombine_4consecutive_alias2(
248 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
249 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
250 ; ALL-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
251 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
252 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
253 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
254 ; ALL-NEXT: store i8 10, ptr [[PSTR:%.*]], align 1
255 ; ALL-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
256 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
257 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
258 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
259 ; ALL-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
260 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
261 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
262 ; ALL-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
263 ; ALL-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
264 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
265 ; ALL-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
266 ; ALL-NEXT: ret i32 [[O3]]
268 %p1 = getelementptr i8, ptr %p, i32 1
269 %p2 = getelementptr i8, ptr %p, i32 2
270 %p3 = getelementptr i8, ptr %p, i32 3
271 %l1 = load i8, ptr %p
272 %l2 = load i8, ptr %p1
273 %l3 = load i8, ptr %p2
274 store i8 10, ptr %pstr
275 %l4 = load i8, ptr %p3
277 %e1 = zext i8 %l1 to i32
278 %e2 = zext i8 %l2 to i32
279 %e3 = zext i8 %l3 to i32
280 %e4 = zext i8 %l4 to i32
283 %s3 = shl i32 %e3, 16
284 %s4 = shl i32 %e4, 24
286 %o1 = or i32 %e1, %s2
287 %o2 = or i32 %o1, %s3
288 %o3 = or i32 %o2, %s4
292 define i32 @loadCombine_4consecutive_alias2_BE(ptr %p, ptr %pstr) {
293 ; ALL-LABEL: @loadCombine_4consecutive_alias2_BE(
294 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
295 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
296 ; ALL-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
297 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
298 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
299 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
300 ; ALL-NEXT: store i8 10, ptr [[PSTR:%.*]], align 1
301 ; ALL-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
302 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
303 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
304 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
305 ; ALL-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
306 ; ALL-NEXT: [[S1:%.*]] = shl i32 [[E1]], 24
307 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 16
308 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 8
309 ; ALL-NEXT: [[O1:%.*]] = or i32 [[S1]], [[S2]]
310 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
311 ; ALL-NEXT: [[O3:%.*]] = or i32 [[O2]], [[E4]]
312 ; ALL-NEXT: ret i32 [[O3]]
314 %p1 = getelementptr i8, ptr %p, i32 1
315 %p2 = getelementptr i8, ptr %p, i32 2
316 %p3 = getelementptr i8, ptr %p, i32 3
317 %l1 = load i8, ptr %p
318 %l2 = load i8, ptr %p1
319 %l3 = load i8, ptr %p2
320 store i8 10, ptr %pstr
321 %l4 = load i8, ptr %p3
323 %e1 = zext i8 %l1 to i32
324 %e2 = zext i8 %l2 to i32
325 %e3 = zext i8 %l3 to i32
326 %e4 = zext i8 %l4 to i32
328 %s1 = shl i32 %e1, 24
329 %s2 = shl i32 %e2, 16
332 %o1 = or i32 %s1, %s2
333 %o2 = or i32 %o1, %s3
334 %o3 = or i32 %o2, %e4
338 define i32 @loadCombine_4consecutive_alias3(ptr %p) {
339 ; ALL-LABEL: @loadCombine_4consecutive_alias3(
340 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
341 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
342 ; ALL-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
343 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
344 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
345 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
346 ; ALL-NEXT: store i8 10, ptr [[P3]], align 1
347 ; ALL-NEXT: store i8 5, ptr [[P]], align 1
348 ; ALL-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
349 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
350 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
351 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
352 ; ALL-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
353 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
354 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
355 ; ALL-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
356 ; ALL-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
357 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
358 ; ALL-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
359 ; ALL-NEXT: ret i32 [[O3]]
361 %p1 = getelementptr i8, ptr %p, i32 1
362 %p2 = getelementptr i8, ptr %p, i32 2
363 %p3 = getelementptr i8, ptr %p, i32 3
364 %l1 = load i8, ptr %p
365 %l2 = load i8, ptr %p1
366 %l3 = load i8, ptr %p2
369 %l4 = load i8, ptr %p3
371 %e1 = zext i8 %l1 to i32
372 %e2 = zext i8 %l2 to i32
373 %e3 = zext i8 %l3 to i32
374 %e4 = zext i8 %l4 to i32
377 %s3 = shl i32 %e3, 16
378 %s4 = shl i32 %e4, 24
380 %o1 = or i32 %e1, %s2
381 %o2 = or i32 %o1, %s3
382 %o3 = or i32 %o2, %s4
386 define i32 @loadCombine_4consecutive_alias3_BE(ptr %p) {
387 ; ALL-LABEL: @loadCombine_4consecutive_alias3_BE(
388 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
389 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
390 ; ALL-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
391 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
392 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
393 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
394 ; ALL-NEXT: store i8 10, ptr [[P3]], align 1
395 ; ALL-NEXT: store i8 5, ptr [[P]], align 1
396 ; ALL-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
397 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
398 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
399 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
400 ; ALL-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
401 ; ALL-NEXT: [[S1:%.*]] = shl i32 [[E1]], 24
402 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 16
403 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 8
404 ; ALL-NEXT: [[O1:%.*]] = or i32 [[S1]], [[S2]]
405 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
406 ; ALL-NEXT: [[O3:%.*]] = or i32 [[O2]], [[E4]]
407 ; ALL-NEXT: ret i32 [[O3]]
409 %p1 = getelementptr i8, ptr %p, i32 1
410 %p2 = getelementptr i8, ptr %p, i32 2
411 %p3 = getelementptr i8, ptr %p, i32 3
412 %l1 = load i8, ptr %p
413 %l2 = load i8, ptr %p1
414 %l3 = load i8, ptr %p2
417 %l4 = load i8, ptr %p3
419 %e1 = zext i8 %l1 to i32
420 %e2 = zext i8 %l2 to i32
421 %e3 = zext i8 %l3 to i32
422 %e4 = zext i8 %l4 to i32
424 %s1 = shl i32 %e1, 24
425 %s2 = shl i32 %e2, 16
428 %o1 = or i32 %s1, %s2
429 %o2 = or i32 %o1, %s3
430 %o3 = or i32 %o2, %e4
434 define i32 @loadCombine_4consecutive_with_alias4(ptr %p, ptr %ps) {
435 ; ALL-LABEL: @loadCombine_4consecutive_with_alias4(
436 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
437 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
438 ; ALL-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
439 ; ALL-NEXT: [[PS1:%.*]] = getelementptr i8, ptr [[PS:%.*]], i32 1
440 ; ALL-NEXT: [[PS2:%.*]] = getelementptr i8, ptr [[PS]], i32 2
441 ; ALL-NEXT: [[PS3:%.*]] = getelementptr i8, ptr [[PS]], i32 3
442 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
443 ; ALL-NEXT: store i8 10, ptr [[PS]], align 1
444 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
445 ; ALL-NEXT: store i8 10, ptr [[PS1]], align 1
446 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
447 ; ALL-NEXT: store i8 10, ptr [[PS2]], align 1
448 ; ALL-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
449 ; ALL-NEXT: store i8 10, ptr [[PS3]], align 1
450 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
451 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
452 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
453 ; ALL-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
454 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
455 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
456 ; ALL-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
457 ; ALL-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
458 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
459 ; ALL-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
460 ; ALL-NEXT: ret i32 [[O3]]
462 %p1 = getelementptr i8, ptr %p, i32 1
463 %p2 = getelementptr i8, ptr %p, i32 2
464 %p3 = getelementptr i8, ptr %p, i32 3
465 %ps1 = getelementptr i8, ptr %ps, i32 1
466 %ps2 = getelementptr i8, ptr %ps, i32 2
467 %ps3 = getelementptr i8, ptr %ps, i32 3
468 %l1 = load i8, ptr %p
470 %l2 = load i8, ptr %p1
471 store i8 10, ptr %ps1
472 %l3 = load i8, ptr %p2
473 store i8 10, ptr %ps2
474 %l4 = load i8, ptr %p3
475 store i8 10, ptr %ps3
477 %e1 = zext i8 %l1 to i32
478 %e2 = zext i8 %l2 to i32
479 %e3 = zext i8 %l3 to i32
480 %e4 = zext i8 %l4 to i32
483 %s3 = shl i32 %e3, 16
484 %s4 = shl i32 %e4, 24
486 %o1 = or i32 %e1, %s2
487 %o2 = or i32 %o1, %s3
488 %o3 = or i32 %o2, %s4
492 declare void @use(i8)
493 declare void @use2(i32)
495 define i32 @loadCombine_4consecutive_hasOneUse1(ptr %p) {
496 ; ALL-LABEL: @loadCombine_4consecutive_hasOneUse1(
497 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
498 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
499 ; ALL-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
500 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
501 ; ALL-NEXT: call void @use(i8 [[L1]])
502 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
503 ; ALL-NEXT: call void @use(i8 [[L2]])
504 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
505 ; ALL-NEXT: call void @use(i8 [[L3]])
506 ; ALL-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
507 ; ALL-NEXT: call void @use(i8 [[L4]])
508 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
509 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
510 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
511 ; ALL-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
512 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
513 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
514 ; ALL-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
515 ; ALL-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
516 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
517 ; ALL-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
518 ; ALL-NEXT: ret i32 [[O3]]
520 %p1 = getelementptr i8, ptr %p, i32 1
521 %p2 = getelementptr i8, ptr %p, i32 2
522 %p3 = getelementptr i8, ptr %p, i32 3
523 %l1 = load i8, ptr %p
524 call void @use(i8 %l1)
525 %l2 = load i8, ptr %p1
526 call void @use(i8 %l2)
527 %l3 = load i8, ptr %p2
528 call void @use(i8 %l3)
529 %l4 = load i8, ptr %p3
530 call void @use(i8 %l4)
532 %e1 = zext i8 %l1 to i32
533 %e2 = zext i8 %l2 to i32
534 %e3 = zext i8 %l3 to i32
535 %e4 = zext i8 %l4 to i32
538 %s3 = shl i32 %e3, 16
539 %s4 = shl i32 %e4, 24
541 %o1 = or i32 %e1, %s2
542 %o2 = or i32 %o1, %s3
543 %o3 = or i32 %o2, %s4
547 define i32 @loadCombine_4consecutive_hasOneUse2(ptr %p) {
548 ; ALL-LABEL: @loadCombine_4consecutive_hasOneUse2(
549 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
550 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
551 ; ALL-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
552 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
553 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
554 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
555 ; ALL-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
556 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
557 ; ALL-NEXT: call void @use(i32 [[E1]])
558 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
559 ; ALL-NEXT: call void @use(i32 [[E2]])
560 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
561 ; ALL-NEXT: call void @use(i32 [[E3]])
562 ; ALL-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
563 ; ALL-NEXT: call void @use(i32 [[E4]])
564 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
565 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
566 ; ALL-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
567 ; ALL-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
568 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
569 ; ALL-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
570 ; ALL-NEXT: ret i32 [[O3]]
572 %p1 = getelementptr i8, ptr %p, i32 1
573 %p2 = getelementptr i8, ptr %p, i32 2
574 %p3 = getelementptr i8, ptr %p, i32 3
575 %l1 = load i8, ptr %p
576 %l2 = load i8, ptr %p1
577 %l3 = load i8, ptr %p2
578 %l4 = load i8, ptr %p3
580 %e1 = zext i8 %l1 to i32
581 call void @use(i32 %e1)
582 %e2 = zext i8 %l2 to i32
583 call void @use(i32 %e2)
584 %e3 = zext i8 %l3 to i32
585 call void @use(i32 %e3)
586 %e4 = zext i8 %l4 to i32
587 call void @use(i32 %e4)
590 %s3 = shl i32 %e3, 16
591 %s4 = shl i32 %e4, 24
593 %o1 = or i32 %e1, %s2
594 %o2 = or i32 %o1, %s3
595 %o3 = or i32 %o2, %s4
599 define i32 @loadCombine_4consecutive_hasOneUse3(ptr %p) {
600 ; ALL-LABEL: @loadCombine_4consecutive_hasOneUse3(
601 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
602 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
603 ; ALL-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
604 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
605 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
606 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
607 ; ALL-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
608 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
609 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
610 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
611 ; ALL-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
612 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
613 ; ALL-NEXT: call void @use(i32 [[S2]])
614 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
615 ; ALL-NEXT: call void @use(i32 [[S3]])
616 ; ALL-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
617 ; ALL-NEXT: call void @use(i32 [[S4]])
618 ; ALL-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
619 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
620 ; ALL-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
621 ; ALL-NEXT: ret i32 [[O3]]
623 %p1 = getelementptr i8, ptr %p, i32 1
624 %p2 = getelementptr i8, ptr %p, i32 2
625 %p3 = getelementptr i8, ptr %p, i32 3
626 %l1 = load i8, ptr %p
627 %l2 = load i8, ptr %p1
628 %l3 = load i8, ptr %p2
629 %l4 = load i8, ptr %p3
631 %e1 = zext i8 %l1 to i32
632 %e2 = zext i8 %l2 to i32
633 %e3 = zext i8 %l3 to i32
634 %e4 = zext i8 %l4 to i32
637 call void @use(i32 %s2)
638 %s3 = shl i32 %e3, 16
639 call void @use(i32 %s3)
640 %s4 = shl i32 %e4, 24
641 call void @use(i32 %s4)
643 %o1 = or i32 %e1, %s2
644 %o2 = or i32 %o1, %s3
645 %o3 = or i32 %o2, %s4
649 define i32 @loadCombine_4consecutive_hasOneUse4(ptr %p) {
650 ; ALL-LABEL: @loadCombine_4consecutive_hasOneUse4(
651 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
652 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
653 ; ALL-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
654 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
655 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
656 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
657 ; ALL-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
658 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
659 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
660 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
661 ; ALL-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
662 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
663 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
664 ; ALL-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
665 ; ALL-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
666 ; ALL-NEXT: call void @use(i32 [[O1]])
667 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
668 ; ALL-NEXT: call void @use(i32 [[O2]])
669 ; ALL-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
670 ; ALL-NEXT: ret i32 [[O3]]
672 %p1 = getelementptr i8, ptr %p, i32 1
673 %p2 = getelementptr i8, ptr %p, i32 2
674 %p3 = getelementptr i8, ptr %p, i32 3
675 %l1 = load i8, ptr %p
676 %l2 = load i8, ptr %p1
677 %l3 = load i8, ptr %p2
678 %l4 = load i8, ptr %p3
680 %e1 = zext i8 %l1 to i32
681 %e2 = zext i8 %l2 to i32
682 %e3 = zext i8 %l3 to i32
683 %e4 = zext i8 %l4 to i32
686 %s3 = shl i32 %e3, 16
687 %s4 = shl i32 %e4, 24
689 %o1 = or i32 %e1, %s2
690 call void @use(i32 %o1)
691 %o2 = or i32 %o1, %s3
692 call void @use(i32 %o2)
693 %o3 = or i32 %o2, %s4
697 define i32 @loadCombine_parLoad1(ptr %p) {
698 ; ALL-LABEL: @loadCombine_parLoad1(
699 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
700 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
701 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
702 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
703 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
704 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
705 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
706 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
707 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
708 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
709 ; ALL-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
710 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
711 ; ALL-NEXT: ret i32 [[O2]]
713 %p1 = getelementptr i8, ptr %p, i32 1
714 %p2 = getelementptr i8, ptr %p, i32 2
715 %l1 = load i8, ptr %p
716 %l2 = load i8, ptr %p1
717 %l3 = load i8, ptr %p2
719 %e1 = zext i8 %l1 to i32
720 %e2 = zext i8 %l2 to i32
721 %e3 = zext i8 %l3 to i32
724 %s3 = shl i32 %e3, 16
726 %o1 = or i32 %e1, %s2
727 %o2 = or i32 %o1, %s3
731 define i128 @loadCombine_i128(ptr %p) {
732 ; LE-LABEL: @loadCombine_i128(
733 ; LE-NEXT: [[P2:%.*]] = getelementptr i32, ptr [[P:%.*]], i32 2
734 ; LE-NEXT: [[P3:%.*]] = getelementptr i32, ptr [[P]], i32 3
735 ; LE-NEXT: [[L1:%.*]] = load i64, ptr [[P]], align 4
736 ; LE-NEXT: [[TMP1:%.*]] = zext i64 [[L1]] to i128
737 ; LE-NEXT: [[L3:%.*]] = load i32, ptr [[P2]], align 4
738 ; LE-NEXT: [[L4:%.*]] = load i32, ptr [[P3]], align 4
739 ; LE-NEXT: [[E3:%.*]] = zext i32 [[L3]] to i128
740 ; LE-NEXT: [[E4:%.*]] = zext i32 [[L4]] to i128
741 ; LE-NEXT: [[S3:%.*]] = shl i128 [[E3]], 64
742 ; LE-NEXT: [[S4:%.*]] = shl i128 [[E4]], 96
743 ; LE-NEXT: [[O2:%.*]] = or i128 [[TMP1]], [[S3]]
744 ; LE-NEXT: [[O3:%.*]] = or i128 [[O2]], [[S4]]
745 ; LE-NEXT: ret i128 [[O3]]
747 ; BE-LABEL: @loadCombine_i128(
748 ; BE-NEXT: [[P1:%.*]] = getelementptr i32, ptr [[P:%.*]], i32 1
749 ; BE-NEXT: [[P2:%.*]] = getelementptr i32, ptr [[P]], i32 2
750 ; BE-NEXT: [[P3:%.*]] = getelementptr i32, ptr [[P]], i32 3
751 ; BE-NEXT: [[L1:%.*]] = load i32, ptr [[P]], align 4
752 ; BE-NEXT: [[L2:%.*]] = load i32, ptr [[P1]], align 4
753 ; BE-NEXT: [[L3:%.*]] = load i32, ptr [[P2]], align 4
754 ; BE-NEXT: [[L4:%.*]] = load i32, ptr [[P3]], align 4
755 ; BE-NEXT: [[E1:%.*]] = zext i32 [[L1]] to i128
756 ; BE-NEXT: [[E2:%.*]] = zext i32 [[L2]] to i128
757 ; BE-NEXT: [[E3:%.*]] = zext i32 [[L3]] to i128
758 ; BE-NEXT: [[E4:%.*]] = zext i32 [[L4]] to i128
759 ; BE-NEXT: [[S2:%.*]] = shl i128 [[E2]], 32
760 ; BE-NEXT: [[S3:%.*]] = shl i128 [[E3]], 64
761 ; BE-NEXT: [[S4:%.*]] = shl i128 [[E4]], 96
762 ; BE-NEXT: [[O1:%.*]] = or i128 [[E1]], [[S2]]
763 ; BE-NEXT: [[O2:%.*]] = or i128 [[O1]], [[S3]]
764 ; BE-NEXT: [[O3:%.*]] = or i128 [[O2]], [[S4]]
765 ; BE-NEXT: ret i128 [[O3]]
767 %p1 = getelementptr i32, ptr %p, i32 1
768 %p2 = getelementptr i32, ptr %p, i32 2
769 %p3 = getelementptr i32, ptr %p, i32 3
770 %l1 = load i32, ptr %p
771 %l2 = load i32, ptr %p1
772 %l3 = load i32, ptr %p2
773 %l4 = load i32, ptr %p3
775 %e1 = zext i32 %l1 to i128
776 %e2 = zext i32 %l2 to i128
777 %e3 = zext i32 %l3 to i128
778 %e4 = zext i32 %l4 to i128
780 %s2 = shl i128 %e2, 32
781 %s3 = shl i128 %e3, 64
782 %s4 = shl i128 %e4, 96
784 %o1 = or i128 %e1, %s2
785 %o2 = or i128 %o1, %s3
786 %o3 = or i128 %o2, %s4
790 define i128 @loadCombine_i128_BE(ptr %p) {
791 ; LE-LABEL: @loadCombine_i128_BE(
792 ; LE-NEXT: [[P1:%.*]] = getelementptr i32, ptr [[P:%.*]], i32 1
793 ; LE-NEXT: [[P2:%.*]] = getelementptr i32, ptr [[P]], i32 2
794 ; LE-NEXT: [[P3:%.*]] = getelementptr i32, ptr [[P]], i32 3
795 ; LE-NEXT: [[L1:%.*]] = load i32, ptr [[P]], align 4
796 ; LE-NEXT: [[L2:%.*]] = load i32, ptr [[P1]], align 4
797 ; LE-NEXT: [[L3:%.*]] = load i32, ptr [[P2]], align 4
798 ; LE-NEXT: [[L4:%.*]] = load i32, ptr [[P3]], align 4
799 ; LE-NEXT: [[E1:%.*]] = zext i32 [[L1]] to i128
800 ; LE-NEXT: [[E2:%.*]] = zext i32 [[L2]] to i128
801 ; LE-NEXT: [[E3:%.*]] = zext i32 [[L3]] to i128
802 ; LE-NEXT: [[E4:%.*]] = zext i32 [[L4]] to i128
803 ; LE-NEXT: [[S1:%.*]] = shl i128 [[E1]], 96
804 ; LE-NEXT: [[S2:%.*]] = shl i128 [[E2]], 64
805 ; LE-NEXT: [[S3:%.*]] = shl i128 [[E3]], 32
806 ; LE-NEXT: [[O1:%.*]] = or i128 [[S1]], [[S2]]
807 ; LE-NEXT: [[O2:%.*]] = or i128 [[O1]], [[S3]]
808 ; LE-NEXT: [[O3:%.*]] = or i128 [[O2]], [[E4]]
809 ; LE-NEXT: ret i128 [[O3]]
811 ; BE-LABEL: @loadCombine_i128_BE(
812 ; BE-NEXT: [[P2:%.*]] = getelementptr i32, ptr [[P:%.*]], i32 2
813 ; BE-NEXT: [[P3:%.*]] = getelementptr i32, ptr [[P]], i32 3
814 ; BE-NEXT: [[L1:%.*]] = load i64, ptr [[P]], align 4
815 ; BE-NEXT: [[TMP1:%.*]] = zext i64 [[L1]] to i128
816 ; BE-NEXT: [[TMP2:%.*]] = shl i128 [[TMP1]], 64
817 ; BE-NEXT: [[L3:%.*]] = load i32, ptr [[P2]], align 4
818 ; BE-NEXT: [[L4:%.*]] = load i32, ptr [[P3]], align 4
819 ; BE-NEXT: [[E3:%.*]] = zext i32 [[L3]] to i128
820 ; BE-NEXT: [[E4:%.*]] = zext i32 [[L4]] to i128
821 ; BE-NEXT: [[S3:%.*]] = shl i128 [[E3]], 32
822 ; BE-NEXT: [[O2:%.*]] = or i128 [[TMP2]], [[S3]]
823 ; BE-NEXT: [[O3:%.*]] = or i128 [[O2]], [[E4]]
824 ; BE-NEXT: ret i128 [[O3]]
826 %p1 = getelementptr i32, ptr %p, i32 1
827 %p2 = getelementptr i32, ptr %p, i32 2
828 %p3 = getelementptr i32, ptr %p, i32 3
829 %l1 = load i32, ptr %p
830 %l2 = load i32, ptr %p1
831 %l3 = load i32, ptr %p2
832 %l4 = load i32, ptr %p3
834 %e1 = zext i32 %l1 to i128
835 %e2 = zext i32 %l2 to i128
836 %e3 = zext i32 %l3 to i128
837 %e4 = zext i32 %l4 to i128
839 %s1 = shl i128 %e1, 96
840 %s2 = shl i128 %e2, 64
841 %s3 = shl i128 %e3, 32
843 %o1 = or i128 %s1, %s2
844 %o2 = or i128 %o1, %s3
845 %o3 = or i128 %o2, %e4
849 define i64 @loadCombine_i64(ptr %p) {
850 ; LE-LABEL: @loadCombine_i64(
851 ; LE-NEXT: [[L1:%.*]] = load i64, ptr [[P:%.*]], align 2
852 ; LE-NEXT: ret i64 [[L1]]
854 ; BE-LABEL: @loadCombine_i64(
855 ; BE-NEXT: [[P1:%.*]] = getelementptr i16, ptr [[P:%.*]], i32 1
856 ; BE-NEXT: [[P2:%.*]] = getelementptr i16, ptr [[P]], i32 2
857 ; BE-NEXT: [[P3:%.*]] = getelementptr i16, ptr [[P]], i32 3
858 ; BE-NEXT: [[L1:%.*]] = load i16, ptr [[P]], align 2
859 ; BE-NEXT: [[L2:%.*]] = load i16, ptr [[P1]], align 2
860 ; BE-NEXT: [[L3:%.*]] = load i16, ptr [[P2]], align 2
861 ; BE-NEXT: [[L4:%.*]] = load i16, ptr [[P3]], align 2
862 ; BE-NEXT: [[E1:%.*]] = zext i16 [[L1]] to i64
863 ; BE-NEXT: [[E2:%.*]] = zext i16 [[L2]] to i64
864 ; BE-NEXT: [[E3:%.*]] = zext i16 [[L3]] to i64
865 ; BE-NEXT: [[E4:%.*]] = zext i16 [[L4]] to i64
866 ; BE-NEXT: [[S2:%.*]] = shl i64 [[E2]], 16
867 ; BE-NEXT: [[S3:%.*]] = shl i64 [[E3]], 32
868 ; BE-NEXT: [[S4:%.*]] = shl i64 [[E4]], 48
869 ; BE-NEXT: [[O1:%.*]] = or i64 [[E1]], [[S2]]
870 ; BE-NEXT: [[O2:%.*]] = or i64 [[O1]], [[S3]]
871 ; BE-NEXT: [[O3:%.*]] = or i64 [[O2]], [[S4]]
872 ; BE-NEXT: ret i64 [[O3]]
874 %p1 = getelementptr i16, ptr %p, i32 1
875 %p2 = getelementptr i16, ptr %p, i32 2
876 %p3 = getelementptr i16, ptr %p, i32 3
877 %l1 = load i16, ptr %p
878 %l2 = load i16, ptr %p1
879 %l3 = load i16, ptr %p2
880 %l4 = load i16, ptr %p3
882 %e1 = zext i16 %l1 to i64
883 %e2 = zext i16 %l2 to i64
884 %e3 = zext i16 %l3 to i64
885 %e4 = zext i16 %l4 to i64
887 %s2 = shl i64 %e2, 16
888 %s3 = shl i64 %e3, 32
889 %s4 = shl i64 %e4, 48
891 %o1 = or i64 %e1, %s2
892 %o2 = or i64 %o1, %s3
893 %o3 = or i64 %o2, %s4
897 define i64 @loadCombine_i64_BE(ptr %p) {
898 ; LE-LABEL: @loadCombine_i64_BE(
899 ; LE-NEXT: [[P1:%.*]] = getelementptr i16, ptr [[P:%.*]], i32 1
900 ; LE-NEXT: [[P2:%.*]] = getelementptr i16, ptr [[P]], i32 2
901 ; LE-NEXT: [[P3:%.*]] = getelementptr i16, ptr [[P]], i32 3
902 ; LE-NEXT: [[L1:%.*]] = load i16, ptr [[P]], align 2
903 ; LE-NEXT: [[L2:%.*]] = load i16, ptr [[P1]], align 2
904 ; LE-NEXT: [[L3:%.*]] = load i16, ptr [[P2]], align 2
905 ; LE-NEXT: [[L4:%.*]] = load i16, ptr [[P3]], align 2
906 ; LE-NEXT: [[E1:%.*]] = zext i16 [[L1]] to i64
907 ; LE-NEXT: [[E2:%.*]] = zext i16 [[L2]] to i64
908 ; LE-NEXT: [[E3:%.*]] = zext i16 [[L3]] to i64
909 ; LE-NEXT: [[E4:%.*]] = zext i16 [[L4]] to i64
910 ; LE-NEXT: [[S1:%.*]] = shl i64 [[E1]], 48
911 ; LE-NEXT: [[S2:%.*]] = shl i64 [[E2]], 32
912 ; LE-NEXT: [[S3:%.*]] = shl i64 [[E3]], 16
913 ; LE-NEXT: [[O1:%.*]] = or i64 [[S1]], [[S2]]
914 ; LE-NEXT: [[O2:%.*]] = or i64 [[O1]], [[S3]]
915 ; LE-NEXT: [[O3:%.*]] = or i64 [[O2]], [[E4]]
916 ; LE-NEXT: ret i64 [[O3]]
918 ; BE-LABEL: @loadCombine_i64_BE(
919 ; BE-NEXT: [[L1:%.*]] = load i64, ptr [[P:%.*]], align 2
920 ; BE-NEXT: ret i64 [[L1]]
922 %p1 = getelementptr i16, ptr %p, i32 1
923 %p2 = getelementptr i16, ptr %p, i32 2
924 %p3 = getelementptr i16, ptr %p, i32 3
925 %l1 = load i16, ptr %p
926 %l2 = load i16, ptr %p1
927 %l3 = load i16, ptr %p2
928 %l4 = load i16, ptr %p3
930 %e1 = zext i16 %l1 to i64
931 %e2 = zext i16 %l2 to i64
932 %e3 = zext i16 %l3 to i64
933 %e4 = zext i16 %l4 to i64
935 %s1 = shl i64 %e1, 48
936 %s2 = shl i64 %e2, 32
937 %s3 = shl i64 %e3, 16
939 %o1 = or i64 %s1, %s2
940 %o2 = or i64 %o1, %s3
941 %o3 = or i64 %o2, %e4
945 define i16 @loadCombine_2consecutive_atomic(ptr %p) {
946 ; ALL-LABEL: @loadCombine_2consecutive_atomic(
947 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
948 ; ALL-NEXT: [[L1:%.*]] = load atomic i8, ptr [[P]] monotonic, align 1
949 ; ALL-NEXT: [[L2:%.*]] = load atomic i8, ptr [[P1]] monotonic, align 1
950 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i16
951 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i16
952 ; ALL-NEXT: [[S2:%.*]] = shl i16 [[E2]], 8
953 ; ALL-NEXT: [[O1:%.*]] = or i16 [[E1]], [[S2]]
954 ; ALL-NEXT: ret i16 [[O1]]
956 %p1 = getelementptr i8, ptr %p, i32 1
957 %l1 = load atomic i8, ptr %p monotonic, align 1
958 %l2 = load atomic i8, ptr %p1 monotonic, align 1
959 %e1 = zext i8 %l1 to i16
960 %e2 = zext i8 %l2 to i16
962 %o1 = or i16 %e1, %s2
966 define i16 @loadCombine_2consecutive_volatile(ptr %p) {
967 ; ALL-LABEL: @loadCombine_2consecutive_volatile(
968 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
969 ; ALL-NEXT: [[L1:%.*]] = load volatile i8, ptr [[P]], align 1
970 ; ALL-NEXT: [[L2:%.*]] = load volatile i8, ptr [[P1]], align 1
971 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i16
972 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i16
973 ; ALL-NEXT: [[S2:%.*]] = shl i16 [[E2]], 8
974 ; ALL-NEXT: [[O1:%.*]] = or i16 [[E1]], [[S2]]
975 ; ALL-NEXT: ret i16 [[O1]]
977 %p1 = getelementptr i8, ptr %p, i32 1
978 %l1 = load volatile i8, ptr %p, align 1
979 %l2 = load volatile i8, ptr %p1, align 1
980 %e1 = zext i8 %l1 to i16
981 %e2 = zext i8 %l2 to i16
983 %o1 = or i16 %e1, %s2
987 define i16 @loadCombine_2consecutive_separateBB(ptr %p) {
988 ; ALL-LABEL: @loadCombine_2consecutive_separateBB(
989 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
990 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
991 ; ALL-NEXT: br label [[BB2:%.*]]
993 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
994 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i16
995 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i16
996 ; ALL-NEXT: [[S2:%.*]] = shl i16 [[E2]], 8
997 ; ALL-NEXT: [[O1:%.*]] = or i16 [[E1]], [[S2]]
998 ; ALL-NEXT: ret i16 [[O1]]
1000 %p1 = getelementptr i8, ptr %p, i32 1
1001 %l1 = load i8, ptr %p, align 1
1005 %l2 = load i8, ptr %p1, align 1
1006 %e1 = zext i8 %l1 to i16
1007 %e2 = zext i8 %l2 to i16
1008 %s2 = shl i16 %e2, 8
1009 %o1 = or i16 %e1, %s2
1013 define i16 @loadCombine_2consecutive_separateptr(ptr %p, ptr %p2) {
1014 ; ALL-LABEL: @loadCombine_2consecutive_separateptr(
1015 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P2:%.*]], i32 1
1016 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P:%.*]], align 1
1017 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
1018 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i16
1019 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i16
1020 ; ALL-NEXT: [[S2:%.*]] = shl i16 [[E2]], 8
1021 ; ALL-NEXT: [[O1:%.*]] = or i16 [[E1]], [[S2]]
1022 ; ALL-NEXT: ret i16 [[O1]]
1024 %p1 = getelementptr i8, ptr %p2, i32 1
1025 %l1 = load i8, ptr %p, align 1
1026 %l2 = load i8, ptr %p1, align 1
1027 %e1 = zext i8 %l1 to i16
1028 %e2 = zext i8 %l2 to i16
1029 %s2 = shl i16 %e2, 8
1030 %o1 = or i16 %e1, %s2
1034 define i64 @load64_farLoads(ptr %ptr) {
1035 ; LE-LABEL: @load64_farLoads(
1037 ; LE-NEXT: [[TMP0:%.*]] = load i64, ptr [[PTR:%.*]], align 1
1038 ; LE-NEXT: ret i64 [[TMP0]]
1040 ; BE-LABEL: @load64_farLoads(
1042 ; BE-NEXT: [[TMP0:%.*]] = load i8, ptr [[PTR:%.*]], align 1
1043 ; BE-NEXT: [[CONV:%.*]] = zext i8 [[TMP0]] to i64
1044 ; BE-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i64 1
1045 ; BE-NEXT: [[TMP1:%.*]] = load i8, ptr [[ARRAYIDX1]], align 1
1046 ; BE-NEXT: [[CONV2:%.*]] = zext i8 [[TMP1]] to i64
1047 ; BE-NEXT: [[SHL:%.*]] = shl i64 [[CONV2]], 8
1048 ; BE-NEXT: [[OR:%.*]] = or i64 [[CONV]], [[SHL]]
1049 ; BE-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i64 2
1050 ; BE-NEXT: [[TMP2:%.*]] = load i8, ptr [[ARRAYIDX3]], align 1
1051 ; BE-NEXT: [[CONV4:%.*]] = zext i8 [[TMP2]] to i64
1052 ; BE-NEXT: [[SHL5:%.*]] = shl i64 [[CONV4]], 16
1053 ; BE-NEXT: [[OR6:%.*]] = or i64 [[OR]], [[SHL5]]
1054 ; BE-NEXT: [[ARRAYIDX7:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i64 3
1055 ; BE-NEXT: [[TMP3:%.*]] = load i8, ptr [[ARRAYIDX7]], align 1
1056 ; BE-NEXT: [[CONV8:%.*]] = zext i8 [[TMP3]] to i64
1057 ; BE-NEXT: [[SHL9:%.*]] = shl i64 [[CONV8]], 24
1058 ; BE-NEXT: [[OR10:%.*]] = or i64 [[OR6]], [[SHL9]]
1059 ; BE-NEXT: [[ARRAYIDX11:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i64 4
1060 ; BE-NEXT: [[TMP4:%.*]] = load i8, ptr [[ARRAYIDX11]], align 1
1061 ; BE-NEXT: [[CONV12:%.*]] = zext i8 [[TMP4]] to i64
1062 ; BE-NEXT: [[SHL13:%.*]] = shl i64 [[CONV12]], 32
1063 ; BE-NEXT: [[OR14:%.*]] = or i64 [[OR10]], [[SHL13]]
1064 ; BE-NEXT: [[ARRAYIDX15:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i64 5
1065 ; BE-NEXT: [[TMP5:%.*]] = load i8, ptr [[ARRAYIDX15]], align 1
1066 ; BE-NEXT: [[CONV16:%.*]] = zext i8 [[TMP5]] to i64
1067 ; BE-NEXT: [[SHL17:%.*]] = shl i64 [[CONV16]], 40
1068 ; BE-NEXT: [[OR18:%.*]] = or i64 [[OR14]], [[SHL17]]
1069 ; BE-NEXT: [[ARRAYIDX19:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i64 6
1070 ; BE-NEXT: [[TMP6:%.*]] = load i8, ptr [[ARRAYIDX19]], align 1
1071 ; BE-NEXT: [[CONV20:%.*]] = zext i8 [[TMP6]] to i64
1072 ; BE-NEXT: [[SHL21:%.*]] = shl i64 [[CONV20]], 48
1073 ; BE-NEXT: [[OR22:%.*]] = or i64 [[OR18]], [[SHL21]]
1074 ; BE-NEXT: [[ARRAYIDX23:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i64 7
1075 ; BE-NEXT: [[TMP7:%.*]] = load i8, ptr [[ARRAYIDX23]], align 1
1076 ; BE-NEXT: [[CONV24:%.*]] = zext i8 [[TMP7]] to i64
1077 ; BE-NEXT: [[SHL25:%.*]] = shl i64 [[CONV24]], 56
1078 ; BE-NEXT: [[OR26:%.*]] = or i64 [[OR22]], [[SHL25]]
1079 ; BE-NEXT: ret i64 [[OR26]]
1082 %0 = load i8, ptr %ptr, align 1
1083 %conv = zext i8 %0 to i64
1084 %arrayidx1 = getelementptr inbounds i8, ptr %ptr, i64 1
1085 %1 = load i8, ptr %arrayidx1, align 1
1086 %conv2 = zext i8 %1 to i64
1087 %shl = shl i64 %conv2, 8
1088 %or = or i64 %conv, %shl
1089 %arrayidx3 = getelementptr inbounds i8, ptr %ptr, i64 2
1090 %2 = load i8, ptr %arrayidx3, align 1
1091 %conv4 = zext i8 %2 to i64
1092 %shl5 = shl i64 %conv4, 16
1093 %or6 = or i64 %or, %shl5
1094 %arrayidx7 = getelementptr inbounds i8, ptr %ptr, i64 3
1095 %3 = load i8, ptr %arrayidx7, align 1
1096 %conv8 = zext i8 %3 to i64
1097 %shl9 = shl i64 %conv8, 24
1098 %or10 = or i64 %or6, %shl9
1099 %arrayidx11 = getelementptr inbounds i8, ptr %ptr, i64 4
1100 %4 = load i8, ptr %arrayidx11, align 1
1101 %conv12 = zext i8 %4 to i64
1102 %shl13 = shl i64 %conv12, 32
1103 %or14 = or i64 %or10, %shl13
1104 %arrayidx15 = getelementptr inbounds i8, ptr %ptr, i64 5
1105 %5 = load i8, ptr %arrayidx15, align 1
1106 %conv16 = zext i8 %5 to i64
1107 %shl17 = shl i64 %conv16, 40
1108 %or18 = or i64 %or14, %shl17
1109 %arrayidx19 = getelementptr inbounds i8, ptr %ptr, i64 6
1110 %6 = load i8, ptr %arrayidx19, align 1
1111 %conv20 = zext i8 %6 to i64
1112 %shl21 = shl i64 %conv20, 48
1113 %or22 = or i64 %or18, %shl21
1114 %arrayidx23 = getelementptr inbounds i8, ptr %ptr, i64 7
1115 %7 = load i8, ptr %arrayidx23, align 1
1116 %conv24 = zext i8 %7 to i64
1117 %shl25 = shl i64 %conv24, 56
1118 %or26 = or i64 %or22, %shl25
1122 define i32 @loadCombine_4consecutive_metadata(ptr %p, ptr %pstr) {
1123 ; LE-LABEL: @loadCombine_4consecutive_metadata(
1124 ; LE-NEXT: [[L1:%.*]] = load i32, ptr [[P:%.*]], align 1, !alias.scope !0
1125 ; LE-NEXT: store i32 25, ptr [[PSTR:%.*]], align 4, !noalias !0
1126 ; LE-NEXT: ret i32 [[L1]]
1128 ; BE-LABEL: @loadCombine_4consecutive_metadata(
1129 ; BE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
1130 ; BE-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
1131 ; BE-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
1132 ; BE-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1, !alias.scope !0
1133 ; BE-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1, !alias.scope !0
1134 ; BE-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1, !alias.scope !0
1135 ; BE-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1, !alias.scope !0
1136 ; BE-NEXT: store i32 25, ptr [[PSTR:%.*]], align 4, !noalias !0
1137 ; BE-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
1138 ; BE-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1139 ; BE-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
1140 ; BE-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
1141 ; BE-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
1142 ; BE-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
1143 ; BE-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
1144 ; BE-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
1145 ; BE-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
1146 ; BE-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
1147 ; BE-NEXT: ret i32 [[O3]]
1149 %p1 = getelementptr i8, ptr %p, i32 1
1150 %p2 = getelementptr i8, ptr %p, i32 2
1151 %p3 = getelementptr i8, ptr %p, i32 3
1152 %l1 = load i8, ptr %p, !alias.scope !2
1153 %l2 = load i8, ptr %p1, !alias.scope !2
1154 %l3 = load i8, ptr %p2, !alias.scope !2
1155 %l4 = load i8, ptr %p3, !alias.scope !2
1156 store i32 25, ptr %pstr, !noalias !2
1158 %e1 = zext i8 %l1 to i32
1159 %e2 = zext i8 %l2 to i32
1160 %e3 = zext i8 %l3 to i32
1161 %e4 = zext i8 %l4 to i32
1163 %s2 = shl i32 %e2, 8
1164 %s3 = shl i32 %e3, 16
1165 %s4 = shl i32 %e4, 24
1167 %o1 = or i32 %e1, %s2
1168 %o2 = or i32 %o1, %s3
1169 %o3 = or i32 %o2, %s4
1174 !1 = distinct !{!1, !0}
1178 ; CHECK: !1 = distinct !{!1, !2}
1179 ; CHECK: !2 = distinct !{!2}
1181 define i16 @loadCombine_4consecutive_4bit(ptr %p) {
1182 ; ALL-LABEL: @loadCombine_4consecutive_4bit(
1183 ; ALL-NEXT: [[P1:%.*]] = getelementptr i4, ptr [[P:%.*]], i32 1
1184 ; ALL-NEXT: [[P2:%.*]] = getelementptr i4, ptr [[P]], i32 2
1185 ; ALL-NEXT: [[P3:%.*]] = getelementptr i4, ptr [[P]], i32 3
1186 ; ALL-NEXT: [[L1:%.*]] = load i4, ptr [[P]], align 1
1187 ; ALL-NEXT: [[L2:%.*]] = load i4, ptr [[P1]], align 1
1188 ; ALL-NEXT: [[L3:%.*]] = load i4, ptr [[P2]], align 1
1189 ; ALL-NEXT: [[L4:%.*]] = load i4, ptr [[P3]], align 1
1190 ; ALL-NEXT: [[E1:%.*]] = zext i4 [[L1]] to i16
1191 ; ALL-NEXT: [[E2:%.*]] = zext i4 [[L2]] to i16
1192 ; ALL-NEXT: [[E3:%.*]] = zext i4 [[L3]] to i16
1193 ; ALL-NEXT: [[E4:%.*]] = zext i4 [[L4]] to i16
1194 ; ALL-NEXT: [[S2:%.*]] = shl i16 [[E2]], 4
1195 ; ALL-NEXT: [[S3:%.*]] = shl i16 [[E3]], 8
1196 ; ALL-NEXT: [[S4:%.*]] = shl i16 [[E4]], 12
1197 ; ALL-NEXT: [[O1:%.*]] = or i16 [[E1]], [[S2]]
1198 ; ALL-NEXT: [[O2:%.*]] = or i16 [[O1]], [[S3]]
1199 ; ALL-NEXT: [[O3:%.*]] = or i16 [[O2]], [[S4]]
1200 ; ALL-NEXT: ret i16 [[O3]]
1202 %p1 = getelementptr i4, ptr %p, i32 1
1203 %p2 = getelementptr i4, ptr %p, i32 2
1204 %p3 = getelementptr i4, ptr %p, i32 3
1205 %l1 = load i4, ptr %p
1206 %l2 = load i4, ptr %p1
1207 %l3 = load i4, ptr %p2
1208 %l4 = load i4, ptr %p3
1209 %e1 = zext i4 %l1 to i16
1210 %e2 = zext i4 %l2 to i16
1211 %e3 = zext i4 %l3 to i16
1212 %e4 = zext i4 %l4 to i16
1213 %s2 = shl i16 %e2, 4
1214 %s3 = shl i16 %e3, 8
1215 %s4 = shl i16 %e4, 12
1216 %o1 = or i16 %e1, %s2
1217 %o2 = or i16 %o1, %s3
1218 %o3 = or i16 %o2, %s4
1222 define i32 @loadCombine_4consecutive_rev(ptr %p) {
1223 ; LE-LABEL: @loadCombine_4consecutive_rev(
1224 ; LE-NEXT: [[L1:%.*]] = load i32, ptr [[P:%.*]], align 1
1225 ; LE-NEXT: ret i32 [[L1]]
1227 ; BE-LABEL: @loadCombine_4consecutive_rev(
1228 ; BE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
1229 ; BE-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
1230 ; BE-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
1231 ; BE-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
1232 ; BE-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
1233 ; BE-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
1234 ; BE-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
1235 ; BE-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
1236 ; BE-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1237 ; BE-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
1238 ; BE-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
1239 ; BE-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
1240 ; BE-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
1241 ; BE-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
1242 ; BE-NEXT: [[O1:%.*]] = or i32 [[S4]], [[S3]]
1243 ; BE-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S2]]
1244 ; BE-NEXT: [[O3:%.*]] = or i32 [[O2]], [[E1]]
1245 ; BE-NEXT: ret i32 [[O3]]
1247 %p1 = getelementptr i8, ptr %p, i32 1
1248 %p2 = getelementptr i8, ptr %p, i32 2
1249 %p3 = getelementptr i8, ptr %p, i32 3
1250 %l1 = load i8, ptr %p
1251 %l2 = load i8, ptr %p1
1252 %l3 = load i8, ptr %p2
1253 %l4 = load i8, ptr %p3
1255 %e1 = zext i8 %l1 to i32
1256 %e2 = zext i8 %l2 to i32
1257 %e3 = zext i8 %l3 to i32
1258 %e4 = zext i8 %l4 to i32
1260 %s2 = shl i32 %e2, 8
1261 %s3 = shl i32 %e3, 16
1262 %s4 = shl i32 %e4, 24
1264 %o1 = or i32 %s4, %s3
1265 %o2 = or i32 %o1, %s2
1266 %o3 = or i32 %o2, %e1
1270 define i64 @loadCombine_8consecutive_rev(ptr %p) {
1271 ; LE-LABEL: @loadCombine_8consecutive_rev(
1272 ; LE-NEXT: [[L1:%.*]] = load i64, ptr [[P:%.*]], align 1
1273 ; LE-NEXT: ret i64 [[L1]]
1275 ; BE-LABEL: @loadCombine_8consecutive_rev(
1276 ; BE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
1277 ; BE-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
1278 ; BE-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
1279 ; BE-NEXT: [[P4:%.*]] = getelementptr i8, ptr [[P]], i32 4
1280 ; BE-NEXT: [[P5:%.*]] = getelementptr i8, ptr [[P]], i32 5
1281 ; BE-NEXT: [[P6:%.*]] = getelementptr i8, ptr [[P]], i32 6
1282 ; BE-NEXT: [[P7:%.*]] = getelementptr i8, ptr [[P]], i32 7
1283 ; BE-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
1284 ; BE-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
1285 ; BE-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
1286 ; BE-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
1287 ; BE-NEXT: [[L5:%.*]] = load i8, ptr [[P4]], align 1
1288 ; BE-NEXT: [[L6:%.*]] = load i8, ptr [[P5]], align 1
1289 ; BE-NEXT: [[L7:%.*]] = load i8, ptr [[P6]], align 1
1290 ; BE-NEXT: [[L8:%.*]] = load i8, ptr [[P7]], align 1
1291 ; BE-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i64
1292 ; BE-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i64
1293 ; BE-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i64
1294 ; BE-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i64
1295 ; BE-NEXT: [[E5:%.*]] = zext i8 [[L5]] to i64
1296 ; BE-NEXT: [[E6:%.*]] = zext i8 [[L6]] to i64
1297 ; BE-NEXT: [[E7:%.*]] = zext i8 [[L7]] to i64
1298 ; BE-NEXT: [[E8:%.*]] = zext i8 [[L8]] to i64
1299 ; BE-NEXT: [[S2:%.*]] = shl i64 [[E2]], 8
1300 ; BE-NEXT: [[S3:%.*]] = shl i64 [[E3]], 16
1301 ; BE-NEXT: [[S4:%.*]] = shl i64 [[E4]], 24
1302 ; BE-NEXT: [[S5:%.*]] = shl i64 [[E5]], 32
1303 ; BE-NEXT: [[S6:%.*]] = shl i64 [[E6]], 40
1304 ; BE-NEXT: [[S7:%.*]] = shl i64 [[E7]], 48
1305 ; BE-NEXT: [[S8:%.*]] = shl i64 [[E8]], 56
1306 ; BE-NEXT: [[O7:%.*]] = or i64 [[S8]], [[S7]]
1307 ; BE-NEXT: [[O6:%.*]] = or i64 [[O7]], [[S6]]
1308 ; BE-NEXT: [[O5:%.*]] = or i64 [[O6]], [[S5]]
1309 ; BE-NEXT: [[O4:%.*]] = or i64 [[O5]], [[S4]]
1310 ; BE-NEXT: [[O3:%.*]] = or i64 [[O4]], [[S3]]
1311 ; BE-NEXT: [[O2:%.*]] = or i64 [[O3]], [[S2]]
1312 ; BE-NEXT: [[O1:%.*]] = or i64 [[O2]], [[E1]]
1313 ; BE-NEXT: ret i64 [[O1]]
1315 %p1 = getelementptr i8, ptr %p, i32 1
1316 %p2 = getelementptr i8, ptr %p, i32 2
1317 %p3 = getelementptr i8, ptr %p, i32 3
1318 %p4 = getelementptr i8, ptr %p, i32 4
1319 %p5 = getelementptr i8, ptr %p, i32 5
1320 %p6 = getelementptr i8, ptr %p, i32 6
1321 %p7 = getelementptr i8, ptr %p, i32 7
1322 %l1 = load i8, ptr %p
1323 %l2 = load i8, ptr %p1
1324 %l3 = load i8, ptr %p2
1325 %l4 = load i8, ptr %p3
1326 %l5 = load i8, ptr %p4
1327 %l6 = load i8, ptr %p5
1328 %l7 = load i8, ptr %p6
1329 %l8 = load i8, ptr %p7
1331 %e1 = zext i8 %l1 to i64
1332 %e2 = zext i8 %l2 to i64
1333 %e3 = zext i8 %l3 to i64
1334 %e4 = zext i8 %l4 to i64
1335 %e5 = zext i8 %l5 to i64
1336 %e6 = zext i8 %l6 to i64
1337 %e7 = zext i8 %l7 to i64
1338 %e8 = zext i8 %l8 to i64
1340 %s2 = shl i64 %e2, 8
1341 %s3 = shl i64 %e3, 16
1342 %s4 = shl i64 %e4, 24
1343 %s5 = shl i64 %e5, 32
1344 %s6 = shl i64 %e6, 40
1345 %s7 = shl i64 %e7, 48
1346 %s8 = shl i64 %e8, 56
1348 %o7 = or i64 %s8, %s7
1349 %o6 = or i64 %o7, %s6
1350 %o5 = or i64 %o6, %s5
1351 %o4 = or i64 %o5, %s4
1352 %o3 = or i64 %o4, %s3
1353 %o2 = or i64 %o3, %s2
1354 %o1 = or i64 %o2, %e1
1358 define i64 @loadCombine_8consecutive_rev_BE(ptr %p) {
1359 ; LE-LABEL: @loadCombine_8consecutive_rev_BE(
1360 ; LE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
1361 ; LE-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
1362 ; LE-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
1363 ; LE-NEXT: [[P4:%.*]] = getelementptr i8, ptr [[P]], i32 4
1364 ; LE-NEXT: [[P5:%.*]] = getelementptr i8, ptr [[P]], i32 5
1365 ; LE-NEXT: [[P6:%.*]] = getelementptr i8, ptr [[P]], i32 6
1366 ; LE-NEXT: [[P7:%.*]] = getelementptr i8, ptr [[P]], i32 7
1367 ; LE-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
1368 ; LE-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
1369 ; LE-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
1370 ; LE-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
1371 ; LE-NEXT: [[L5:%.*]] = load i8, ptr [[P4]], align 1
1372 ; LE-NEXT: [[L6:%.*]] = load i8, ptr [[P5]], align 1
1373 ; LE-NEXT: [[L7:%.*]] = load i8, ptr [[P6]], align 1
1374 ; LE-NEXT: [[L8:%.*]] = load i8, ptr [[P7]], align 1
1375 ; LE-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i64
1376 ; LE-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i64
1377 ; LE-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i64
1378 ; LE-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i64
1379 ; LE-NEXT: [[E5:%.*]] = zext i8 [[L5]] to i64
1380 ; LE-NEXT: [[E6:%.*]] = zext i8 [[L6]] to i64
1381 ; LE-NEXT: [[E7:%.*]] = zext i8 [[L7]] to i64
1382 ; LE-NEXT: [[E8:%.*]] = zext i8 [[L8]] to i64
1383 ; LE-NEXT: [[S1:%.*]] = shl i64 [[E1]], 56
1384 ; LE-NEXT: [[S2:%.*]] = shl i64 [[E2]], 48
1385 ; LE-NEXT: [[S3:%.*]] = shl i64 [[E3]], 40
1386 ; LE-NEXT: [[S4:%.*]] = shl i64 [[E4]], 32
1387 ; LE-NEXT: [[S5:%.*]] = shl i64 [[E5]], 24
1388 ; LE-NEXT: [[S6:%.*]] = shl i64 [[E6]], 16
1389 ; LE-NEXT: [[S7:%.*]] = shl i64 [[E7]], 8
1390 ; LE-NEXT: [[O7:%.*]] = or i64 [[E8]], [[S7]]
1391 ; LE-NEXT: [[O6:%.*]] = or i64 [[O7]], [[S6]]
1392 ; LE-NEXT: [[O5:%.*]] = or i64 [[O6]], [[S5]]
1393 ; LE-NEXT: [[O4:%.*]] = or i64 [[O5]], [[S4]]
1394 ; LE-NEXT: [[O3:%.*]] = or i64 [[O4]], [[S3]]
1395 ; LE-NEXT: [[O2:%.*]] = or i64 [[O3]], [[S2]]
1396 ; LE-NEXT: [[O1:%.*]] = or i64 [[O2]], [[S1]]
1397 ; LE-NEXT: ret i64 [[O1]]
1399 ; BE-LABEL: @loadCombine_8consecutive_rev_BE(
1400 ; BE-NEXT: [[L1:%.*]] = load i64, ptr [[P:%.*]], align 1
1401 ; BE-NEXT: ret i64 [[L1]]
1403 %p1 = getelementptr i8, ptr %p, i32 1
1404 %p2 = getelementptr i8, ptr %p, i32 2
1405 %p3 = getelementptr i8, ptr %p, i32 3
1406 %p4 = getelementptr i8, ptr %p, i32 4
1407 %p5 = getelementptr i8, ptr %p, i32 5
1408 %p6 = getelementptr i8, ptr %p, i32 6
1409 %p7 = getelementptr i8, ptr %p, i32 7
1410 %l1 = load i8, ptr %p
1411 %l2 = load i8, ptr %p1
1412 %l3 = load i8, ptr %p2
1413 %l4 = load i8, ptr %p3
1414 %l5 = load i8, ptr %p4
1415 %l6 = load i8, ptr %p5
1416 %l7 = load i8, ptr %p6
1417 %l8 = load i8, ptr %p7
1419 %e1 = zext i8 %l1 to i64
1420 %e2 = zext i8 %l2 to i64
1421 %e3 = zext i8 %l3 to i64
1422 %e4 = zext i8 %l4 to i64
1423 %e5 = zext i8 %l5 to i64
1424 %e6 = zext i8 %l6 to i64
1425 %e7 = zext i8 %l7 to i64
1426 %e8 = zext i8 %l8 to i64
1428 %s1 = shl i64 %e1, 56
1429 %s2 = shl i64 %e2, 48
1430 %s3 = shl i64 %e3, 40
1431 %s4 = shl i64 %e4, 32
1432 %s5 = shl i64 %e5, 24
1433 %s6 = shl i64 %e6, 16
1434 %s7 = shl i64 %e7, 8
1436 %o7 = or i64 %e8, %s7
1437 %o6 = or i64 %o7, %s6
1438 %o5 = or i64 %o6, %s5
1439 %o4 = or i64 %o5, %s4
1440 %o3 = or i64 %o4, %s3
1441 %o2 = or i64 %o3, %s2
1442 %o1 = or i64 %o2, %s1
1446 define i64 @eggs(ptr noundef readonly %arg) {
1448 ; LE-NEXT: [[TMP3:%.*]] = load i64, ptr [[ARG:%.*]], align 1
1449 ; LE-NEXT: ret i64 [[TMP3]]
1452 ; BE-NEXT: [[TMP3:%.*]] = load i8, ptr [[ARG:%.*]], align 1
1453 ; BE-NEXT: [[TMP4:%.*]] = getelementptr inbounds i8, ptr [[ARG]], i64 1
1454 ; BE-NEXT: [[TMP5:%.*]] = load i8, ptr [[TMP4]], align 1
1455 ; BE-NEXT: [[TMP6:%.*]] = getelementptr inbounds i8, ptr [[ARG]], i64 2
1456 ; BE-NEXT: [[TMP7:%.*]] = load i8, ptr [[TMP6]], align 1
1457 ; BE-NEXT: [[TMP8:%.*]] = getelementptr inbounds i8, ptr [[ARG]], i64 3
1458 ; BE-NEXT: [[TMP9:%.*]] = load i8, ptr [[TMP8]], align 1
1459 ; BE-NEXT: [[TMP10:%.*]] = getelementptr inbounds i8, ptr [[ARG]], i64 4
1460 ; BE-NEXT: [[TMP11:%.*]] = load i8, ptr [[TMP10]], align 1
1461 ; BE-NEXT: [[TMP12:%.*]] = getelementptr inbounds i8, ptr [[ARG]], i64 5
1462 ; BE-NEXT: [[TMP13:%.*]] = load i8, ptr [[TMP12]], align 1
1463 ; BE-NEXT: [[TMP14:%.*]] = getelementptr inbounds i8, ptr [[ARG]], i64 6
1464 ; BE-NEXT: [[TMP15:%.*]] = load i8, ptr [[TMP14]], align 1
1465 ; BE-NEXT: [[TMP16:%.*]] = getelementptr inbounds i8, ptr [[ARG]], i64 7
1466 ; BE-NEXT: [[TMP17:%.*]] = load i8, ptr [[TMP16]], align 1
1467 ; BE-NEXT: [[TMP18:%.*]] = zext i8 [[TMP17]] to i64
1468 ; BE-NEXT: [[TMP19:%.*]] = shl nuw i64 [[TMP18]], 56
1469 ; BE-NEXT: [[TMP20:%.*]] = zext i8 [[TMP15]] to i64
1470 ; BE-NEXT: [[TMP21:%.*]] = shl nuw nsw i64 [[TMP20]], 48
1471 ; BE-NEXT: [[TMP22:%.*]] = or i64 [[TMP19]], [[TMP21]]
1472 ; BE-NEXT: [[TMP23:%.*]] = zext i8 [[TMP13]] to i64
1473 ; BE-NEXT: [[TMP24:%.*]] = shl nuw nsw i64 [[TMP23]], 40
1474 ; BE-NEXT: [[TMP25:%.*]] = or i64 [[TMP22]], [[TMP24]]
1475 ; BE-NEXT: [[TMP26:%.*]] = zext i8 [[TMP11]] to i64
1476 ; BE-NEXT: [[TMP27:%.*]] = shl nuw nsw i64 [[TMP26]], 32
1477 ; BE-NEXT: [[TMP28:%.*]] = or i64 [[TMP25]], [[TMP27]]
1478 ; BE-NEXT: [[TMP29:%.*]] = zext i8 [[TMP9]] to i64
1479 ; BE-NEXT: [[TMP30:%.*]] = shl nuw nsw i64 [[TMP29]], 24
1480 ; BE-NEXT: [[TMP31:%.*]] = or i64 [[TMP28]], [[TMP30]]
1481 ; BE-NEXT: [[TMP32:%.*]] = zext i8 [[TMP7]] to i64
1482 ; BE-NEXT: [[TMP33:%.*]] = shl nuw nsw i64 [[TMP32]], 16
1483 ; BE-NEXT: [[TMP34:%.*]] = zext i8 [[TMP5]] to i64
1484 ; BE-NEXT: [[TMP35:%.*]] = shl nuw nsw i64 [[TMP34]], 8
1485 ; BE-NEXT: [[TMP36:%.*]] = or i64 [[TMP31]], [[TMP33]]
1486 ; BE-NEXT: [[TMP37:%.*]] = zext i8 [[TMP3]] to i64
1487 ; BE-NEXT: [[TMP38:%.*]] = or i64 [[TMP36]], [[TMP35]]
1488 ; BE-NEXT: [[TMP39:%.*]] = or i64 [[TMP38]], [[TMP37]]
1489 ; BE-NEXT: ret i64 [[TMP39]]
1491 %tmp3 = load i8, ptr %arg, align 1
1492 %tmp4 = getelementptr inbounds i8, ptr %arg, i64 1
1493 %tmp5 = load i8, ptr %tmp4, align 1
1494 %tmp6 = getelementptr inbounds i8, ptr %arg, i64 2
1495 %tmp7 = load i8, ptr %tmp6, align 1
1496 %tmp8 = getelementptr inbounds i8, ptr %arg, i64 3
1497 %tmp9 = load i8, ptr %tmp8, align 1
1498 %tmp10 = getelementptr inbounds i8, ptr %arg, i64 4
1499 %tmp11 = load i8, ptr %tmp10, align 1
1500 %tmp12 = getelementptr inbounds i8, ptr %arg, i64 5
1501 %tmp13 = load i8, ptr %tmp12, align 1
1502 %tmp14 = getelementptr inbounds i8, ptr %arg, i64 6
1503 %tmp15 = load i8, ptr %tmp14, align 1
1504 %tmp16 = getelementptr inbounds i8, ptr %arg, i64 7
1505 %tmp17 = load i8, ptr %tmp16, align 1
1506 %tmp18 = zext i8 %tmp17 to i64
1507 %tmp19 = shl nuw i64 %tmp18, 56
1508 %tmp20 = zext i8 %tmp15 to i64
1509 %tmp21 = shl nuw nsw i64 %tmp20, 48
1510 %tmp22 = or i64 %tmp19, %tmp21
1511 %tmp23 = zext i8 %tmp13 to i64
1512 %tmp24 = shl nuw nsw i64 %tmp23, 40
1513 %tmp25 = or i64 %tmp22, %tmp24
1514 %tmp26 = zext i8 %tmp11 to i64
1515 %tmp27 = shl nuw nsw i64 %tmp26, 32
1516 %tmp28 = or i64 %tmp25, %tmp27
1517 %tmp29 = zext i8 %tmp9 to i64
1518 %tmp30 = shl nuw nsw i64 %tmp29, 24
1519 %tmp31 = or i64 %tmp28, %tmp30
1520 %tmp32 = zext i8 %tmp7 to i64
1521 %tmp33 = shl nuw nsw i64 %tmp32, 16
1522 %tmp34 = zext i8 %tmp5 to i64
1523 %tmp35 = shl nuw nsw i64 %tmp34, 8
1524 %tmp36 = or i64 %tmp31, %tmp33
1525 %tmp37 = zext i8 %tmp3 to i64
1526 %tmp38 = or i64 %tmp36, %tmp35
1527 %tmp39 = or i64 %tmp38, %tmp37
1531 define i32 @loadCombine_4consecutive_mixsize1(ptr %p) {
1532 ; ALL-LABEL: @loadCombine_4consecutive_mixsize1(
1533 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 2
1534 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 3
1535 ; ALL-NEXT: [[L1:%.*]] = load i16, ptr [[P]], align 2
1536 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
1537 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
1538 ; ALL-NEXT: [[E1:%.*]] = zext i16 [[L1]] to i32
1539 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1540 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
1541 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 16
1542 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 24
1543 ; ALL-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
1544 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
1545 ; ALL-NEXT: ret i32 [[O2]]
1547 %p1 = getelementptr i8, ptr %p, i32 2
1548 %p2 = getelementptr i8, ptr %p, i32 3
1549 %l1 = load i16, ptr %p
1550 %l2 = load i8, ptr %p1
1551 %l3 = load i8, ptr %p2
1553 %e1 = zext i16 %l1 to i32
1554 %e2 = zext i8 %l2 to i32
1555 %e3 = zext i8 %l3 to i32
1557 %s2 = shl i32 %e2, 16
1558 %s3 = shl i32 %e3, 24
1560 %o1 = or i32 %e1, %s2
1561 %o2 = or i32 %o1, %s3
1565 define i32 @loadCombine_4consecutive_mixsize1_BE(ptr %p) {
1566 ; ALL-LABEL: @loadCombine_4consecutive_mixsize1_BE(
1567 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 2
1568 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 3
1569 ; ALL-NEXT: [[L1:%.*]] = load i16, ptr [[P]], align 2
1570 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
1571 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
1572 ; ALL-NEXT: [[E1:%.*]] = zext i16 [[L1]] to i32
1573 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1574 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
1575 ; ALL-NEXT: [[S1:%.*]] = shl i32 [[E1]], 16
1576 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
1577 ; ALL-NEXT: [[O1:%.*]] = or i32 [[S1]], [[S2]]
1578 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[E3]]
1579 ; ALL-NEXT: ret i32 [[O2]]
1581 %p1 = getelementptr i8, ptr %p, i32 2
1582 %p2 = getelementptr i8, ptr %p, i32 3
1583 %l1 = load i16, ptr %p
1584 %l2 = load i8, ptr %p1
1585 %l3 = load i8, ptr %p2
1587 %e1 = zext i16 %l1 to i32
1588 %e2 = zext i8 %l2 to i32
1589 %e3 = zext i8 %l3 to i32
1591 %s1 = shl i32 %e1, 16
1592 %s2 = shl i32 %e2, 8
1594 %o1 = or i32 %s1, %s2
1595 %o2 = or i32 %o1, %e3
1599 define i32 @loadCombine_4consecutive_rev_mixsize1(ptr %p) {
1600 ; ALL-LABEL: @loadCombine_4consecutive_rev_mixsize1(
1601 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 2
1602 ; ALL-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
1603 ; ALL-NEXT: [[L1:%.*]] = load i16, ptr [[P]], align 2
1604 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P2]], align 1
1605 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P3]], align 1
1606 ; ALL-NEXT: [[E1:%.*]] = zext i16 [[L1]] to i32
1607 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1608 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
1609 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 16
1610 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 24
1611 ; ALL-NEXT: [[O1:%.*]] = or i32 [[S3]], [[S2]]
1612 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[E1]]
1613 ; ALL-NEXT: ret i32 [[O2]]
1615 %p2 = getelementptr i8, ptr %p, i32 2
1616 %p3 = getelementptr i8, ptr %p, i32 3
1617 %l1 = load i16, ptr %p
1618 %l2 = load i8, ptr %p2
1619 %l3 = load i8, ptr %p3
1621 %e1 = zext i16 %l1 to i32
1622 %e2 = zext i8 %l2 to i32
1623 %e3 = zext i8 %l3 to i32
1625 %s2 = shl i32 %e2, 16
1626 %s3 = shl i32 %e3, 24
1628 %o1 = or i32 %s3, %s2
1629 %o2 = or i32 %o1, %e1
1633 define i32 @loadCombine_4consecutive_rev_mixsize1_BE(ptr %p) {
1634 ; ALL-LABEL: @loadCombine_4consecutive_rev_mixsize1_BE(
1635 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 2
1636 ; ALL-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
1637 ; ALL-NEXT: [[L1:%.*]] = load i16, ptr [[P]], align 2
1638 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P2]], align 1
1639 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P3]], align 1
1640 ; ALL-NEXT: [[E1:%.*]] = zext i16 [[L1]] to i32
1641 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1642 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
1643 ; ALL-NEXT: [[S1:%.*]] = shl i32 [[E1]], 16
1644 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
1645 ; ALL-NEXT: [[O1:%.*]] = or i32 [[E3]], [[S2]]
1646 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S1]]
1647 ; ALL-NEXT: ret i32 [[O2]]
1649 %p2 = getelementptr i8, ptr %p, i32 2
1650 %p3 = getelementptr i8, ptr %p, i32 3
1651 %l1 = load i16, ptr %p
1652 %l2 = load i8, ptr %p2
1653 %l3 = load i8, ptr %p3
1655 %e1 = zext i16 %l1 to i32
1656 %e2 = zext i8 %l2 to i32
1657 %e3 = zext i8 %l3 to i32
1659 %s1 = shl i32 %e1, 16
1660 %s2 = shl i32 %e2, 8
1662 %o1 = or i32 %e3, %s2
1663 %o2 = or i32 %o1, %s1
1667 define i32 @loadCombine_4consecutive_mixsize2(ptr %p) {
1668 ; ALL-LABEL: @loadCombine_4consecutive_mixsize2(
1669 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
1670 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
1671 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
1672 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
1673 ; ALL-NEXT: [[L3:%.*]] = load i16, ptr [[P2]], align 2
1674 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
1675 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1676 ; ALL-NEXT: [[E3:%.*]] = zext i16 [[L3]] to i32
1677 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
1678 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
1679 ; ALL-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
1680 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
1681 ; ALL-NEXT: ret i32 [[O2]]
1683 %p1 = getelementptr i8, ptr %p, i32 1
1684 %p2 = getelementptr i8, ptr %p, i32 2
1685 %l1 = load i8, ptr %p
1686 %l2 = load i8, ptr %p1
1687 %l3 = load i16, ptr %p2
1689 %e1 = zext i8 %l1 to i32
1690 %e2 = zext i8 %l2 to i32
1691 %e3 = zext i16 %l3 to i32
1693 %s2 = shl i32 %e2, 8
1694 %s3 = shl i32 %e3, 16
1696 %o1 = or i32 %e1, %s2
1697 %o2 = or i32 %o1, %s3
1701 define i32 @loadCombine_4consecutive_lower_index_comes_before(ptr %p) {
1702 ; LE-LABEL: @loadCombine_4consecutive_lower_index_comes_before(
1703 ; LE-NEXT: [[L1:%.*]] = load i32, ptr [[P:%.*]], align 1
1704 ; LE-NEXT: ret i32 [[L1]]
1706 ; BE-LABEL: @loadCombine_4consecutive_lower_index_comes_before(
1707 ; BE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
1708 ; BE-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
1709 ; BE-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
1710 ; BE-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
1711 ; BE-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
1712 ; BE-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
1713 ; BE-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
1714 ; BE-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
1715 ; BE-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1716 ; BE-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
1717 ; BE-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
1718 ; BE-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
1719 ; BE-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
1720 ; BE-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
1721 ; BE-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
1722 ; BE-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
1723 ; BE-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
1724 ; BE-NEXT: ret i32 [[O3]]
1726 %p1 = getelementptr i8, ptr %p, i32 1
1727 %p2 = getelementptr i8, ptr %p, i32 2
1728 %p3 = getelementptr i8, ptr %p, i32 3
1729 %l4 = load i8, ptr %p3
1730 %l3 = load i8, ptr %p2
1731 %l2 = load i8, ptr %p1
1732 %l1 = load i8, ptr %p
1734 %e1 = zext i8 %l1 to i32
1735 %e2 = zext i8 %l2 to i32
1736 %e3 = zext i8 %l3 to i32
1737 %e4 = zext i8 %l4 to i32
1739 %s2 = shl i32 %e2, 8
1740 %s3 = shl i32 %e3, 16
1741 %s4 = shl i32 %e4, 24
1743 %o1 = or i32 %e1, %s2
1744 %o2 = or i32 %o1, %s3
1745 %o3 = or i32 %o2, %s4
1749 define i16 @loadCombine_2consecutive_badinsert(ptr %p) {
1750 ; ALL-LABEL: @loadCombine_2consecutive_badinsert(
1751 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
1752 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
1753 ; ALL-NEXT: store i8 0, ptr [[P1]], align 1
1754 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
1755 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i16
1756 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i16
1757 ; ALL-NEXT: [[S2:%.*]] = shl i16 [[E2]], 8
1758 ; ALL-NEXT: [[O1:%.*]] = or i16 [[E1]], [[S2]]
1759 ; ALL-NEXT: ret i16 [[O1]]
1761 %p1 = getelementptr i8, ptr %p, i32 1
1762 %l2 = load i8, ptr %p1
1763 store i8 0, ptr %p1, align 1
1764 %l1 = load i8, ptr %p
1765 %e1 = zext i8 %l1 to i16
1766 %e2 = zext i8 %l2 to i16
1767 %s2 = shl i16 %e2, 8
1768 %o1 = or i16 %e1, %s2
1772 define i32 @loadCombine_4consecutive_badinsert(ptr %p) {
1773 ; LE-LABEL: @loadCombine_4consecutive_badinsert(
1774 ; LE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
1775 ; LE-NEXT: [[L1:%.*]] = load i32, ptr [[P]], align 1
1776 ; LE-NEXT: store i8 0, ptr [[P1]], align 1
1777 ; LE-NEXT: ret i32 [[L1]]
1779 ; BE-LABEL: @loadCombine_4consecutive_badinsert(
1780 ; BE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
1781 ; BE-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
1782 ; BE-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
1783 ; BE-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
1784 ; BE-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
1785 ; BE-NEXT: store i8 0, ptr [[P1]], align 1
1786 ; BE-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
1787 ; BE-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
1788 ; BE-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
1789 ; BE-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1790 ; BE-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
1791 ; BE-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
1792 ; BE-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
1793 ; BE-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
1794 ; BE-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
1795 ; BE-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
1796 ; BE-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
1797 ; BE-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
1798 ; BE-NEXT: ret i32 [[O3]]
1800 %p1 = getelementptr i8, ptr %p, i32 1
1801 %p2 = getelementptr i8, ptr %p, i32 2
1802 %p3 = getelementptr i8, ptr %p, i32 3
1803 %l2 = load i8, ptr %p1
1804 %l3 = load i8, ptr %p2
1805 store i8 0, ptr %p1, align 1
1806 %l4 = load i8, ptr %p3
1807 %l1 = load i8, ptr %p
1809 %e1 = zext i8 %l1 to i32
1810 %e2 = zext i8 %l2 to i32
1811 %e3 = zext i8 %l3 to i32
1812 %e4 = zext i8 %l4 to i32
1814 %s2 = shl i32 %e2, 8
1815 %s3 = shl i32 %e3, 16
1816 %s4 = shl i32 %e4, 24
1818 %o1 = or i32 %e1, %s2
1819 %o2 = or i32 %o1, %s3
1820 %o3 = or i32 %o2, %s4
1824 define i32 @loadCombine_4consecutive_badinsert2(ptr %p) {
1825 ; ALL-LABEL: @loadCombine_4consecutive_badinsert2(
1826 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
1827 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
1828 ; ALL-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
1829 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
1830 ; ALL-NEXT: store i8 0, ptr [[P3]], align 1
1831 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
1832 ; ALL-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
1833 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
1834 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
1835 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1836 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
1837 ; ALL-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
1838 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
1839 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
1840 ; ALL-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
1841 ; ALL-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
1842 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
1843 ; ALL-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
1844 ; ALL-NEXT: ret i32 [[O3]]
1846 %p1 = getelementptr i8, ptr %p, i32 1
1847 %p2 = getelementptr i8, ptr %p, i32 2
1848 %p3 = getelementptr i8, ptr %p, i32 3
1849 %l2 = load i8, ptr %p1
1850 store i8 0, ptr %p3, align 1
1851 %l3 = load i8, ptr %p2
1852 %l4 = load i8, ptr %p3
1853 %l1 = load i8, ptr %p
1855 %e1 = zext i8 %l1 to i32
1856 %e2 = zext i8 %l2 to i32
1857 %e3 = zext i8 %l3 to i32
1858 %e4 = zext i8 %l4 to i32
1860 %s2 = shl i32 %e2, 8
1861 %s3 = shl i32 %e3, 16
1862 %s4 = shl i32 %e4, 24
1864 %o1 = or i32 %e1, %s2
1865 %o2 = or i32 %o1, %s3
1866 %o3 = or i32 %o2, %s4
1870 define i32 @loadCombine_4consecutive_badinsert3(ptr %p) {
1871 ; LE-LABEL: @loadCombine_4consecutive_badinsert3(
1872 ; LE-NEXT: [[TMP1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
1873 ; LE-NEXT: [[L1:%.*]] = load i32, ptr [[TMP1]], align 1
1874 ; LE-NEXT: ret i32 [[L1]]
1876 ; BE-LABEL: @loadCombine_4consecutive_badinsert3(
1877 ; BE-NEXT: [[P4:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 4
1878 ; BE-NEXT: [[L4:%.*]] = load i8, ptr [[P4]], align 1
1879 ; BE-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
1880 ; BE-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
1881 ; BE-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
1882 ; BE-NEXT: [[L3:%.*]] = load i8, ptr [[P3]], align 1
1883 ; BE-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
1884 ; BE-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
1885 ; BE-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
1886 ; BE-NEXT: [[L2:%.*]] = load i8, ptr [[P2]], align 1
1887 ; BE-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1888 ; BE-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
1889 ; BE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P]], i32 1
1890 ; BE-NEXT: [[L1:%.*]] = load i8, ptr [[P1]], align 1
1891 ; BE-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
1892 ; BE-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
1893 ; BE-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
1894 ; BE-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
1895 ; BE-NEXT: ret i32 [[O3]]
1897 %p4 = getelementptr i8, ptr %p, i32 4
1898 %l4 = load i8, ptr %p4
1899 %e4 = zext i8 %l4 to i32
1900 %s4 = shl i32 %e4, 24
1902 %p3 = getelementptr i8, ptr %p, i32 3
1903 %l3 = load i8, ptr %p3
1904 %e3 = zext i8 %l3 to i32
1905 %s3 = shl i32 %e3, 16
1907 %p2 = getelementptr i8, ptr %p, i32 2
1908 %l2 = load i8, ptr %p2
1909 %e2 = zext i8 %l2 to i32
1910 %s2 = shl i32 %e2, 8
1912 %p1 = getelementptr i8, ptr %p, i32 1
1913 %l1 = load i8, ptr %p1
1914 %e1 = zext i8 %l1 to i32
1916 %o1 = or i32 %e1, %s2
1917 %o2 = or i32 %o1, %s3
1918 %o3 = or i32 %o2, %s4
1923 define i32 @loadCombine_4consecutive_badinsert4(ptr %p) {
1924 ; LE-LABEL: @loadCombine_4consecutive_badinsert4(
1926 ; LE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 1
1927 ; LE-NEXT: [[C1:%.*]] = load i8, ptr [[P1]], align 1
1928 ; LE-NEXT: [[CMP:%.*]] = icmp eq i8 [[C1]], 0
1929 ; LE-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BB2:%.*]]
1931 ; LE-NEXT: [[L1:%.*]] = load i32, ptr [[P1]], align 1
1932 ; LE-NEXT: br label [[END]]
1934 ; LE-NEXT: [[COND:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[L1]], [[BB2]] ]
1935 ; LE-NEXT: ret i32 [[COND]]
1937 ; BE-LABEL: @loadCombine_4consecutive_badinsert4(
1939 ; BE-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 1
1940 ; BE-NEXT: [[C1:%.*]] = load i8, ptr [[P1]], align 1
1941 ; BE-NEXT: [[CMP:%.*]] = icmp eq i8 [[C1]], 0
1942 ; BE-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[BB2:%.*]]
1944 ; BE-NEXT: [[L1:%.*]] = load i8, ptr [[P1]], align 1
1945 ; BE-NEXT: [[C2:%.*]] = zext i8 [[L1]] to i32
1946 ; BE-NEXT: [[P4:%.*]] = getelementptr i8, ptr [[P]], i64 4
1947 ; BE-NEXT: [[L4:%.*]] = load i8, ptr [[P4]], align 1
1948 ; BE-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
1949 ; BE-NEXT: [[S4:%.*]] = shl nuw i32 [[E4]], 24
1950 ; BE-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i64 3
1951 ; BE-NEXT: [[L3:%.*]] = load i8, ptr [[P3]], align 1
1952 ; BE-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
1953 ; BE-NEXT: [[S3:%.*]] = shl nuw nsw i32 [[E3]], 16
1954 ; BE-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i64 2
1955 ; BE-NEXT: [[L2:%.*]] = load i8, ptr [[P2]], align 1
1956 ; BE-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
1957 ; BE-NEXT: [[S2:%.*]] = shl nuw nsw i32 [[E2]], 8
1958 ; BE-NEXT: [[O1:%.*]] = or i32 [[S2]], [[C2]]
1959 ; BE-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
1960 ; BE-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
1961 ; BE-NEXT: br label [[END]]
1963 ; BE-NEXT: [[COND:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[O3]], [[BB2]] ]
1964 ; BE-NEXT: ret i32 [[COND]]
1967 %p1 = getelementptr i8, ptr %p, i64 1
1968 %c1 = load i8, ptr %p1, align 1
1969 %cmp = icmp eq i8 %c1, 0
1970 br i1 %cmp, label %end, label %bb2
1973 %l1 = load i8, ptr %p1, align 1
1974 %c2 = zext i8 %l1 to i32
1975 %p4 = getelementptr i8, ptr %p, i64 4
1976 %l4 = load i8, ptr %p4, align 1
1977 %e4 = zext i8 %l4 to i32
1978 %s4 = shl nuw i32 %e4, 24
1979 %p3 = getelementptr i8, ptr %p, i64 3
1980 %l3 = load i8, ptr %p3, align 1
1981 %e3 = zext i8 %l3 to i32
1982 %s3 = shl nuw nsw i32 %e3, 16
1983 %p2 = getelementptr i8, ptr %p, i64 2
1984 %l2 = load i8, ptr %p2, align 1
1985 %e2 = zext i8 %l2 to i32
1986 %s2 = shl nuw nsw i32 %e2, 8
1987 %o1 = or i32 %s2, %c2
1988 %o2 = or i32 %o1, %s3
1989 %o3 = or i32 %o2, %s4
1993 %cond = phi i32 [ 0, %entry ], [ %o3, %bb2 ]
1997 define i32 @loadCombine_4consecutive_badinsert5(ptr %p) {
1998 ; ALL-LABEL: @loadCombine_4consecutive_badinsert5(
1999 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
2000 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
2001 ; ALL-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
2002 ; ALL-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
2003 ; ALL-NEXT: store i8 0, ptr [[P2]], align 1
2004 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
2005 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
2006 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
2007 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
2008 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
2009 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
2010 ; ALL-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
2011 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
2012 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
2013 ; ALL-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
2014 ; ALL-NEXT: [[O1:%.*]] = or i32 [[E1]], [[S2]]
2015 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S3]]
2016 ; ALL-NEXT: [[O3:%.*]] = or i32 [[O2]], [[S4]]
2017 ; ALL-NEXT: ret i32 [[O3]]
2019 %p1 = getelementptr i8, ptr %p, i32 1
2020 %p2 = getelementptr i8, ptr %p, i32 2
2021 %p3 = getelementptr i8, ptr %p, i32 3
2022 %l4 = load i8, ptr %p3
2023 store i8 0, ptr %p2, align 1
2024 %l1 = load i8, ptr %p
2025 %l2 = load i8, ptr %p1
2026 %l3 = load i8, ptr %p2
2028 %e1 = zext i8 %l1 to i32
2029 %e2 = zext i8 %l2 to i32
2030 %e3 = zext i8 %l3 to i32
2031 %e4 = zext i8 %l4 to i32
2033 %s2 = shl i32 %e2, 8
2034 %s3 = shl i32 %e3, 16
2035 %s4 = shl i32 %e4, 24
2037 %o1 = or i32 %e1, %s2
2038 %o2 = or i32 %o1, %s3
2039 %o3 = or i32 %o2, %s4
2043 define i32 @loadCombine_4consecutive_badinsert6(ptr %p) {
2044 ; ALL-LABEL: @loadCombine_4consecutive_badinsert6(
2045 ; ALL-NEXT: [[P1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 1
2046 ; ALL-NEXT: [[P2:%.*]] = getelementptr i8, ptr [[P]], i32 2
2047 ; ALL-NEXT: [[P3:%.*]] = getelementptr i8, ptr [[P]], i32 3
2048 ; ALL-NEXT: [[L1:%.*]] = load i8, ptr [[P]], align 1
2049 ; ALL-NEXT: [[L2:%.*]] = load i8, ptr [[P1]], align 1
2050 ; ALL-NEXT: store i8 0, ptr [[P3]], align 1
2051 ; ALL-NEXT: [[L3:%.*]] = load i8, ptr [[P2]], align 1
2052 ; ALL-NEXT: [[L4:%.*]] = load i8, ptr [[P3]], align 1
2053 ; ALL-NEXT: [[E1:%.*]] = zext i8 [[L1]] to i32
2054 ; ALL-NEXT: [[E2:%.*]] = zext i8 [[L2]] to i32
2055 ; ALL-NEXT: [[E3:%.*]] = zext i8 [[L3]] to i32
2056 ; ALL-NEXT: [[E4:%.*]] = zext i8 [[L4]] to i32
2057 ; ALL-NEXT: [[S2:%.*]] = shl i32 [[E2]], 8
2058 ; ALL-NEXT: [[S3:%.*]] = shl i32 [[E3]], 16
2059 ; ALL-NEXT: [[S4:%.*]] = shl i32 [[E4]], 24
2060 ; ALL-NEXT: [[O1:%.*]] = or i32 [[S3]], [[S4]]
2061 ; ALL-NEXT: [[O2:%.*]] = or i32 [[O1]], [[S2]]
2062 ; ALL-NEXT: [[O3:%.*]] = or i32 [[O2]], [[E1]]
2063 ; ALL-NEXT: ret i32 [[O3]]
2065 %p1 = getelementptr i8, ptr %p, i32 1
2066 %p2 = getelementptr i8, ptr %p, i32 2
2067 %p3 = getelementptr i8, ptr %p, i32 3
2068 %l1 = load i8, ptr %p
2069 %l2 = load i8, ptr %p1
2070 store i8 0, ptr %p3, align 1
2071 %l3 = load i8, ptr %p2
2072 %l4 = load i8, ptr %p3
2074 %e1 = zext i8 %l1 to i32
2075 %e2 = zext i8 %l2 to i32
2076 %e3 = zext i8 %l3 to i32
2077 %e4 = zext i8 %l4 to i32
2079 %s2 = shl i32 %e2, 8
2080 %s3 = shl i32 %e3, 16
2081 %s4 = shl i32 %e4, 24
2083 %o1 = or i32 %s3, %s4
2084 %o2 = or i32 %o1, %s2
2085 %o3 = or i32 %o2, %e1
2089 define void @nested_gep(ptr %p, ptr %dest) {
2090 ; LE-LABEL: @nested_gep(
2091 ; LE-NEXT: [[TMP1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 68
2092 ; LE-NEXT: [[LD2:%.*]] = load i64, ptr [[TMP1]], align 4
2093 ; LE-NEXT: [[TRUNC:%.*]] = trunc i64 [[LD2]] to i32
2094 ; LE-NEXT: store i32 [[TRUNC]], ptr [[DEST:%.*]], align 4
2097 ; BE-LABEL: @nested_gep(
2098 ; BE-NEXT: [[GEP1:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 72
2099 ; BE-NEXT: [[LD1:%.*]] = load i32, ptr [[GEP1]], align 4
2100 ; BE-NEXT: [[LD1_ZEXT:%.*]] = zext i32 [[LD1]] to i64
2101 ; BE-NEXT: [[LD1_SHL:%.*]] = shl nuw i64 [[LD1_ZEXT]], 32
2102 ; BE-NEXT: [[GEP2:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 64
2103 ; BE-NEXT: [[FINAL_PTR:%.*]] = getelementptr inbounds i8, ptr [[GEP2]], i64 4
2104 ; BE-NEXT: [[LD2:%.*]] = load i32, ptr [[FINAL_PTR]], align 4
2105 ; BE-NEXT: [[LD2_ZEXT:%.*]] = zext i32 [[LD2]] to i64
2106 ; BE-NEXT: [[OR:%.*]] = or i64 [[LD1_SHL]], [[LD2_ZEXT]]
2107 ; BE-NEXT: [[ADD:%.*]] = add i64 [[OR]], 0
2108 ; BE-NEXT: [[TRUNC:%.*]] = trunc i64 [[ADD]] to i32
2109 ; BE-NEXT: store i32 [[TRUNC]], ptr [[DEST:%.*]], align 4
2112 %gep1 = getelementptr inbounds i8, ptr %p, i64 72
2113 %ld1 = load i32, ptr %gep1, align 4
2114 %ld1_zext = zext i32 %ld1 to i64
2115 %ld1_shl = shl nuw i64 %ld1_zext, 32
2116 %gep2 = getelementptr inbounds i8, ptr %p, i64 64
2117 ; Don't move final_ptr before gep2
2118 %final_ptr = getelementptr inbounds i8, ptr %gep2, i64 4
2119 %ld2 = load i32, ptr %final_ptr, align 4
2120 %ld2_zext = zext i32 %ld2 to i64
2121 %or = or i64 %ld1_shl, %ld2_zext
2122 %add = add i64 %or, 0
2123 %trunc = trunc i64 %add to i32
2124 store i32 %trunc, ptr %dest, align 4
2129 define void @bitcast_gep(ptr %p, ptr %dest) {
2130 ; LE-LABEL: @bitcast_gep(
2131 ; LE-NEXT: [[TMP1:%.*]] = getelementptr i8, ptr [[P:%.*]], i32 68
2132 ; LE-NEXT: [[LD2:%.*]] = load i64, ptr [[TMP1]], align 4
2133 ; LE-NEXT: [[TRUNC:%.*]] = trunc i64 [[LD2]] to i32
2134 ; LE-NEXT: store i32 [[TRUNC]], ptr [[DEST:%.*]], align 4
2137 ; BE-LABEL: @bitcast_gep(
2138 ; BE-NEXT: [[GEP1:%.*]] = getelementptr inbounds i8, ptr [[P:%.*]], i64 72
2139 ; BE-NEXT: [[LD1:%.*]] = load i32, ptr [[GEP1]], align 4
2140 ; BE-NEXT: [[LD1_ZEXT:%.*]] = zext i32 [[LD1]] to i64
2141 ; BE-NEXT: [[LD1_SHL:%.*]] = shl nuw i64 [[LD1_ZEXT]], 32
2142 ; BE-NEXT: [[GEP2:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 68
2143 ; BE-NEXT: [[FINAL_PTR:%.*]] = bitcast ptr [[GEP2]] to ptr
2144 ; BE-NEXT: [[LD2:%.*]] = load i32, ptr [[FINAL_PTR]], align 4
2145 ; BE-NEXT: [[LD2_ZEXT:%.*]] = zext i32 [[LD2]] to i64
2146 ; BE-NEXT: [[OR:%.*]] = or i64 [[LD1_SHL]], [[LD2_ZEXT]]
2147 ; BE-NEXT: [[ADD:%.*]] = add i64 [[OR]], 0
2148 ; BE-NEXT: [[TRUNC:%.*]] = trunc i64 [[ADD]] to i32
2149 ; BE-NEXT: store i32 [[TRUNC]], ptr [[DEST:%.*]], align 4
2152 %gep1 = getelementptr inbounds i8, ptr %p, i64 72
2153 %ld1 = load i32, ptr %gep1, align 4
2154 %ld1_zext = zext i32 %ld1 to i64
2155 %ld1_shl = shl nuw i64 %ld1_zext, 32
2156 %gep2 = getelementptr inbounds i8, ptr %p, i64 68
2157 ; Don't move final_ptr before gep2
2158 %final_ptr = bitcast ptr %gep2 to ptr
2159 %ld2 = load i32, ptr %final_ptr, align 4
2160 %ld2_zext = zext i32 %ld2 to i64
2161 %or = or i64 %ld1_shl, %ld2_zext
2162 %add = add i64 %or, 0
2163 %trunc = trunc i64 %add to i32
2164 store i32 %trunc, ptr %dest, align 4