[InstCombine] Signed saturation tests. NFC
[llvm-complete.git] / test / Transforms / GVN / PRE / rle.ll
bloba461be6f4f8fd12bad9bf43a344dc572e7e4cdec
1 ; RUN: opt < %s -data-layout="e-p:32:32:32-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-n8:16:32" -basicaa -gvn -S -die | FileCheck %s
2 ; RUN: opt < %s -data-layout="E-p:32:32:32-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-n32"      -basicaa -gvn -S -die | FileCheck %s
4 ;; Trivial RLE test.
5 define i32 @test0(i32 %V, i32* %P) {
6   store i32 %V, i32* %P
8   %A = load i32, i32* %P
9   ret i32 %A
10 ; CHECK-LABEL: @test0(
11 ; CHECK: ret i32 %V
15 ;;===----------------------------------------------------------------------===;;
16 ;; Tests for crashers
17 ;;===----------------------------------------------------------------------===;;
19 ;; PR5016
20 define i8 @crash0({i32, i32} %A, {i32, i32}* %P) {
21   store {i32, i32} %A, {i32, i32}* %P
22   %X = bitcast {i32, i32}* %P to i8*
23   %Y = load i8, i8* %X
24   ret i8 %Y
27 ;; No PR filed, crashed in CaptureTracker.
28 declare void @helper()
29 define void @crash1() {
30   tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* undef, i8* undef, i64 undef, i1 false) nounwind
31   %tmp = load i8, i8* bitcast (void ()* @helper to i8*)
32   %x = icmp eq i8 %tmp, 15
33   ret void
37 ;;===----------------------------------------------------------------------===;;
38 ;; Store -> Load  and  Load -> Load forwarding where src and dst are different
39 ;; types, but where the base pointer is a must alias.
40 ;;===----------------------------------------------------------------------===;;
42 ;; i32 -> f32 forwarding.
43 define float @coerce_mustalias1(i32 %V, i32* %P) {
44   store i32 %V, i32* %P
45    
46   %P2 = bitcast i32* %P to float*
48   %A = load float, float* %P2
49   ret float %A
50 ; CHECK-LABEL: @coerce_mustalias1(
51 ; CHECK-NOT: load
52 ; CHECK: ret float 
55 ;; i32* -> float forwarding.
56 define float @coerce_mustalias2(i32* %V, i32** %P) {
57   store i32* %V, i32** %P
58    
59   %P2 = bitcast i32** %P to float*
61   %A = load float, float* %P2
62   ret float %A
63 ; CHECK-LABEL: @coerce_mustalias2(
64 ; CHECK-NOT: load
65 ; CHECK: ret float 
68 ;; float -> i32* forwarding.
69 define i32* @coerce_mustalias3(float %V, float* %P) {
70   store float %V, float* %P
71    
72   %P2 = bitcast float* %P to i32**
74   %A = load i32*, i32** %P2
75   ret i32* %A
76 ; CHECK-LABEL: @coerce_mustalias3(
77 ; CHECK-NOT: load
78 ; CHECK: ret i32* 
81 ;; i32 -> f32 load forwarding.
82 define float @coerce_mustalias4(i32* %P, i1 %cond) {
83   %A = load i32, i32* %P
84   
85   %P2 = bitcast i32* %P to float*
86   %B = load float, float* %P2
87   br i1 %cond, label %T, label %F
89   ret float %B
90   
92   %X = bitcast i32 %A to float
93   ret float %X
95 ; CHECK-LABEL: @coerce_mustalias4(
96 ; CHECK: %A = load i32, i32* %P
97 ; CHECK-NOT: load
98 ; CHECK: ret float
99 ; CHECK: F:
102 ;; i32 -> i8 forwarding
103 define i8 @coerce_mustalias5(i32 %V, i32* %P) {
104   store i32 %V, i32* %P
105    
106   %P2 = bitcast i32* %P to i8*
108   %A = load i8, i8* %P2
109   ret i8 %A
110 ; CHECK-LABEL: @coerce_mustalias5(
111 ; CHECK-NOT: load
112 ; CHECK: ret i8
115 ;; i64 -> float forwarding
116 define float @coerce_mustalias6(i64 %V, i64* %P) {
117   store i64 %V, i64* %P
118    
119   %P2 = bitcast i64* %P to float*
121   %A = load float, float* %P2
122   ret float %A
123 ; CHECK-LABEL: @coerce_mustalias6(
124 ; CHECK-NOT: load
125 ; CHECK: ret float
128 ;; i64 -> i8* (32-bit) forwarding
129 define i8* @coerce_mustalias7(i64 %V, i64* %P) {
130   store i64 %V, i64* %P
131    
132   %P2 = bitcast i64* %P to i8**
134   %A = load i8*, i8** %P2
135   ret i8* %A
136 ; CHECK-LABEL: @coerce_mustalias7(
137 ; CHECK-NOT: load
138 ; CHECK: ret i8*
141 ; memset -> i16 forwarding.
142 define signext i16 @memset_to_i16_local(i16* %A) nounwind ssp {
143 entry:
144   %conv = bitcast i16* %A to i8* 
145   tail call void @llvm.memset.p0i8.i64(i8* %conv, i8 1, i64 200, i1 false)
146   %arrayidx = getelementptr inbounds i16, i16* %A, i64 42
147   %tmp2 = load i16, i16* %arrayidx
148   ret i16 %tmp2
149 ; CHECK-LABEL: @memset_to_i16_local(
150 ; CHECK-NOT: load
151 ; CHECK: ret i16 257
154 ; memset -> float forwarding.
155 define float @memset_to_float_local(float* %A, i8 %Val) nounwind ssp {
156 entry:
157   %conv = bitcast float* %A to i8*                ; <i8*> [#uses=1]
158   tail call void @llvm.memset.p0i8.i64(i8* %conv, i8 %Val, i64 400, i1 false)
159   %arrayidx = getelementptr inbounds float, float* %A, i64 42 ; <float*> [#uses=1]
160   %tmp2 = load float, float* %arrayidx                   ; <float> [#uses=1]
161   ret float %tmp2
162 ; CHECK-LABEL: @memset_to_float_local(
163 ; CHECK-NOT: load
164 ; CHECK: zext
165 ; CHECK-NEXT: shl
166 ; CHECK-NEXT: or
167 ; CHECK-NEXT: shl
168 ; CHECK-NEXT: or
169 ; CHECK-NEXT: bitcast
170 ; CHECK-NEXT: ret float
173 ;; non-local memset -> i16 load forwarding.
174 define i16 @memset_to_i16_nonlocal0(i16* %P, i1 %cond) {
175   %P3 = bitcast i16* %P to i8*
176   br i1 %cond, label %T, label %F
178   tail call void @llvm.memset.p0i8.i64(i8* %P3, i8 1, i64 400, i1 false)
179   br label %Cont
180   
182   tail call void @llvm.memset.p0i8.i64(i8* %P3, i8 2, i64 400, i1 false)
183   br label %Cont
185 Cont:
186   %P2 = getelementptr i16, i16* %P, i32 4
187   %A = load i16, i16* %P2
188   ret i16 %A
190 ; CHECK-LABEL: @memset_to_i16_nonlocal0(
191 ; CHECK: Cont:
192 ; CHECK-NEXT:   %A = phi i16 [ 514, %F ], [ 257, %T ]
193 ; CHECK-NOT: load
194 ; CHECK: ret i16 %A
197 @GCst = constant {i32, float, i32 } { i32 42, float 14., i32 97 }
198 @GCst_as1 = addrspace(1) constant {i32, float, i32 } { i32 42, float 14., i32 97 }
200 ; memset -> float forwarding.
201 define float @memcpy_to_float_local(float* %A) nounwind ssp {
202 entry:
203   %conv = bitcast float* %A to i8*                ; <i8*> [#uses=1]
204   tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %conv, i8* bitcast ({i32, float, i32 }* @GCst to i8*), i64 12, i1 false)
205   %arrayidx = getelementptr inbounds float, float* %A, i64 1 ; <float*> [#uses=1]
206   %tmp2 = load float, float* %arrayidx                   ; <float> [#uses=1]
207   ret float %tmp2
208 ; CHECK-LABEL: @memcpy_to_float_local(
209 ; CHECK-NOT: load
210 ; CHECK: ret float 1.400000e+01
213 ; memcpy from address space 1
214 define float @memcpy_to_float_local_as1(float* %A) nounwind ssp {
215 entry:
216   %conv = bitcast float* %A to i8*                ; <i8*> [#uses=1]
217   tail call void @llvm.memcpy.p0i8.p1i8.i64(i8* %conv, i8 addrspace(1)* bitcast ({i32, float, i32 } addrspace(1)* @GCst_as1 to i8 addrspace(1)*), i64 12, i1 false)
218   %arrayidx = getelementptr inbounds float, float* %A, i64 1 ; <float*> [#uses=1]
219   %tmp2 = load float, float* %arrayidx                   ; <float> [#uses=1]
220   ret float %tmp2
221 ; CHECK-LABEL: @memcpy_to_float_local_as1(
222 ; CHECK-NOT: load
223 ; CHECK: ret float 1.400000e+01
226 ;; non-local i32/float -> i8 load forwarding.
227 define i8 @coerce_mustalias_nonlocal0(i32* %P, i1 %cond) {
228   %P2 = bitcast i32* %P to float*
229   %P3 = bitcast i32* %P to i8*
230   br i1 %cond, label %T, label %F
232   store i32 42, i32* %P
233   br label %Cont
234   
236   store float 1.0, float* %P2
237   br label %Cont
239 Cont:
240   %A = load i8, i8* %P3
241   ret i8 %A
243 ; CHECK-LABEL: @coerce_mustalias_nonlocal0(
244 ; CHECK: Cont:
245 ; CHECK:   %A = phi i8 [
246 ; CHECK-NOT: load
247 ; CHECK: ret i8 %A
251 ;; non-local i32/float -> i8 load forwarding.  This also tests that the "P3"
252 ;; bitcast equivalence can be properly phi translated.
253 define i8 @coerce_mustalias_nonlocal1(i32* %P, i1 %cond) {
254   %P2 = bitcast i32* %P to float*
255   br i1 %cond, label %T, label %F
257   store i32 42, i32* %P
258   br label %Cont
259   
261   store float 1.0, float* %P2
262   br label %Cont
264 Cont:
265   %P3 = bitcast i32* %P to i8*
266   %A = load i8, i8* %P3
267   ret i8 %A
269 ; CHECK-LABEL: @coerce_mustalias_nonlocal1(
270 ; CHECK: Cont:
271 ; CHECK:   %A = phi i8 [
272 ; CHECK-NOT: load
273 ; CHECK: ret i8 %A
277 ;; non-local i32 -> i8 partial redundancy load forwarding.
278 define i8 @coerce_mustalias_pre0(i32* %P, i1 %cond) {
279   %P3 = bitcast i32* %P to i8*
280   br i1 %cond, label %T, label %F
282   store i32 42, i32* %P
283   br label %Cont
284   
286   br label %Cont
288 Cont:
289   %A = load i8, i8* %P3
290   ret i8 %A
292 ; CHECK-LABEL: @coerce_mustalias_pre0(
293 ; CHECK: F:
294 ; CHECK:   load i8, i8* %P3
295 ; CHECK: Cont:
296 ; CHECK:   %A = phi i8 [
297 ; CHECK-NOT: load
298 ; CHECK: ret i8 %A
301 ;;===----------------------------------------------------------------------===;;
302 ;; Store -> Load  and  Load -> Load forwarding where src and dst are different
303 ;; types, and the reload is an offset from the store pointer.
304 ;;===----------------------------------------------------------------------===;;
306 ;; i32 -> i8 forwarding.
307 ;; PR4216
308 define i8 @coerce_offset0(i32 %V, i32* %P) {
309   store i32 %V, i32* %P
310    
311   %P2 = bitcast i32* %P to i8*
312   %P3 = getelementptr i8, i8* %P2, i32 2
314   %A = load i8, i8* %P3
315   ret i8 %A
316 ; CHECK-LABEL: @coerce_offset0(
317 ; CHECK-NOT: load
318 ; CHECK: ret i8
321 ;; non-local i32/float -> i8 load forwarding.
322 define i8 @coerce_offset_nonlocal0(i32* %P, i1 %cond) {
323   %P2 = bitcast i32* %P to float*
324   %P3 = bitcast i32* %P to i8*
325   %P4 = getelementptr i8, i8* %P3, i32 2
326   br i1 %cond, label %T, label %F
328   store i32 57005, i32* %P
329   br label %Cont
330   
332   store float 1.0, float* %P2
333   br label %Cont
335 Cont:
336   %A = load i8, i8* %P4
337   ret i8 %A
339 ; CHECK-LABEL: @coerce_offset_nonlocal0(
340 ; CHECK: Cont:
341 ; CHECK:   %A = phi i8 [
342 ; CHECK-NOT: load
343 ; CHECK: ret i8 %A
347 ;; non-local i32 -> i8 partial redundancy load forwarding.
348 define i8 @coerce_offset_pre0(i32* %P, i1 %cond) {
349   %P3 = bitcast i32* %P to i8*
350   %P4 = getelementptr i8, i8* %P3, i32 2
351   br i1 %cond, label %T, label %F
353   store i32 42, i32* %P
354   br label %Cont
355   
357   br label %Cont
359 Cont:
360   %A = load i8, i8* %P4
361   ret i8 %A
363 ; CHECK-LABEL: @coerce_offset_pre0(
364 ; CHECK: F:
365 ; CHECK:   load i8, i8* %P4
366 ; CHECK: Cont:
367 ; CHECK:   %A = phi i8 [
368 ; CHECK-NOT: load
369 ; CHECK: ret i8 %A
372 define i32 @chained_load(i32** %p, i32 %x, i32 %y) {
373 block1:
374   %A = alloca i32*
376   %z = load i32*, i32** %p
377   store i32* %z, i32** %A
378   %cmp = icmp eq i32 %x, %y
379   br i1 %cmp, label %block2, label %block3
381 block2:
382  %a = load i32*, i32** %p
383  br label %block4
385 block3:
386   %b = load i32*, i32** %p
387   br label %block4
389 block4:
390   %c = load i32*, i32** %p
391   %d = load i32, i32* %c
392   ret i32 %d
393   
394 ; CHECK-LABEL: @chained_load(
395 ; CHECK: %z = load i32*, i32** %p
396 ; CHECK-NOT: load
397 ; CHECK: %d = load i32, i32* %z
398 ; CHECK-NEXT: ret i32 %d
402 declare i1 @cond() readonly
403 declare i1 @cond2() readonly
405 define i32 @phi_trans2() {
406 ; CHECK-LABEL: @phi_trans2(
407 entry:
408   %P = alloca i32, i32 400
409   br label %F1
410   
412   %A = phi i32 [1, %entry], [2, %F]
413   %cond2 = call i1 @cond()
414   br i1 %cond2, label %T1, label %TY
415   
417   %P2 = getelementptr i32, i32* %P, i32 %A
418   %x = load i32, i32* %P2
419   %cond = call i1 @cond2()
420   br i1 %cond, label %TX, label %F
421   
423   %P3 = getelementptr i32, i32* %P, i32 2
424   store i32 17, i32* %P3
425   
426   store i32 42, i32* %P2  ; Provides "P[A]".
427   br label %F1
430   ; This load should not be compiled to 'ret i32 42'.  An overly clever
431   ; implementation of GVN would see that we're returning 17 if the loop
432   ; executes once or 42 if it executes more than that, but we'd have to do
433   ; loop restructuring to expose this, and GVN shouldn't do this sort of CFG
434   ; transformation.
435   
436 ; CHECK: TX:
437 ; CHECK: ret i32 %x
438   ret i32 %x
440   ret i32 0
443 define i32 @phi_trans3(i32* %p, i32 %x, i32 %y, i32 %z) {
444 ; CHECK-LABEL: @phi_trans3(
445 block1:
446   %cmpxy = icmp eq i32 %x, %y
447   br i1 %cmpxy, label %block2, label %block3
449 block2:
450  store i32 87, i32* %p
451  br label %block4
453 block3:
454   %p2 = getelementptr i32, i32* %p, i32 43
455   store i32 97, i32* %p2
456   br label %block4
458 block4:
459   %A = phi i32 [-1, %block2], [42, %block3]
460   br i1 %cmpxy, label %block5, label %exit
461   
462 ; CHECK: block4:
463 ; CHECK-NEXT: %D = phi i32 [ 87, %block2 ], [ 97, %block3 ]  
464 ; CHECK-NOT: load
466 block5:
467   %B = add i32 %A, 1
468   br i1 %cmpxy, label %block6, label %exit
469   
470 block6:
471   %C = getelementptr i32, i32* %p, i32 %B
472   br i1 %cmpxy, label %block7, label %exit
473   
474 block7:
475   %D = load i32, i32* %C
476   ret i32 %D
477   
478 ; CHECK: block7:
479 ; CHECK-NEXT: ret i32 %D
481 exit:
482   ret i32 -1
485 define i8 @phi_trans4(i8* %p) {
486 ; CHECK-LABEL: @phi_trans4(
487 entry:
488   %X3 = getelementptr i8, i8* %p, i32 192
489   store i8 192, i8* %X3
490   
491   %X = getelementptr i8, i8* %p, i32 4
492   %Y = load i8, i8* %X
493   br label %loop
495 loop:
496   %i = phi i32 [4, %entry], [192, %loop]
497   %X2 = getelementptr i8, i8* %p, i32 %i
498   %Y2 = load i8, i8* %X2
499   
500 ; CHECK: loop:
501 ; CHECK-NEXT: %Y2 = phi i8 [ %Y, %entry ], [ 0, %loop ]
502 ; CHECK-NOT: load i8
503   
504   %cond = call i1 @cond2()
506   %Z = bitcast i8 *%X3 to i32*
507   store i32 0, i32* %Z
508   br i1 %cond, label %loop, label %out
509   
510 out:
511   %R = add i8 %Y, %Y2
512   ret i8 %R
515 define i8 @phi_trans5(i8* %p) {
516 ; CHECK-LABEL: @phi_trans5(
517 entry:
518   
519   %X4 = getelementptr i8, i8* %p, i32 2
520   store i8 19, i8* %X4
521   
522   %X = getelementptr i8, i8* %p, i32 4
523   %Y = load i8, i8* %X
524   br label %loop
526 loop:
527   %i = phi i32 [4, %entry], [3, %cont]
528   %X2 = getelementptr i8, i8* %p, i32 %i
529   %Y2 = load i8, i8* %X2  ; Ensure this load is not being incorrectly replaced.
530   %cond = call i1 @cond2()
531   br i1 %cond, label %cont, label %out
533 cont:
534   %Z = getelementptr i8, i8* %X2, i32 -1
535   %Z2 = bitcast i8 *%Z to i32*
536   store i32 50462976, i32* %Z2  ;; (1 << 8) | (2 << 16) | (3 << 24)
539 ; CHECK: store i32
540 ; CHECK-NEXT: getelementptr i8, i8* %p, i32 3
541 ; CHECK-NEXT: load i8, i8*
542   br label %loop
543   
544 out:
545   %R = add i8 %Y, %Y2
546   ret i8 %R
549 declare void @use_i32(i32) readonly
551 ; indirectbr currently prevents MergeBlockIntoPredecessor from merging latch
552 ; into header. Make sure we translate the address for %l1 correctly where
553 ; parts of the address computations are in different basic blocks.
554 define i32 @phi_trans6(i32* noalias nocapture readonly %x, i1 %cond) {
555 ; CHECK-LABEL: define i32 @phi_trans6(
556 ; CHECK-LABEL: entry:
557 ; CHECK-NEXT:   %l0 = load i32, i32* %x
559 ; CHECK-LABEL: header:
560 ; CHECK-NEXT:    %l1 = phi i32 [ %l0, %entry ], [ %l1.pre, %latch.header_crit_edge ]
561 ; CHECK-NEXT:    %iv = phi i32 [ 0, %entry ], [ %iv.next, %latch.header_crit_edge ]
562 ; CHECK-NEXT:    indirectbr i8* blockaddress(@phi_trans6, %latch), [label %latch]
564 ; CHECK-LABEL: latch:
565 ; CHECK-NEXT:    %iv.next = add i32 %iv, 1
566 ; CHECK-NEXT:    br i1 %cond, label %exit, label %latch.header_crit_edge
568 ; CHECK-LABEL: latch.header_crit_edge:
569 ; CHECK-NEXT:    %gep.1.phi.trans.insert.phi.trans.insert = getelementptr i32, i32* %x, i32 %iv.next
570 ; CHECK-NEXT:    %l1.pre = load i32, i32* %gep.1.phi.trans.insert.phi.trans.insert
571 ; CHECK-LABEL:   br label %header
573 entry:
574   %l0 = load i32, i32* %x
575   call void @use_i32(i32 %l0)
576   br label %header
578 header:
579   %iv = phi i32 [0, %entry], [ %iv.next, %latch]
580   indirectbr i8* blockaddress(@phi_trans6, %latch), [label %latch]
582 latch:
583   %gep.1 = getelementptr i32, i32* %x, i32 %iv
584   %l1 = load i32, i32* %gep.1
585   %iv.next = add i32 %iv, 1
586   br i1 %cond, label %exit, label %header
588 exit:
589   ret i32 %l1
592 ; FIXME: Currently we fail to translate the PHI in this case.
593 define i32 @phi_trans7(i32* noalias nocapture readonly %x, i1 %cond) {
594 ; CHECK-LABEL: define i32 @phi_trans7(
595 ; CHECK-LABEL: entry:
596 ; CHECK-NEXT:   %l0 = load i32, i32* %x
598 ; CHECK-LABEL: header:
599 ; CHECK-NEXT:    %iv = phi i32 [ 2, %entry ], [ %iv.next, %latch.header_crit_edge ]
600 ; CHECK-NEXT:    %offset = add i32 %iv, -2
601 ; CHECK-NEXT:    indirectbr i8* blockaddress(@phi_trans7, %latch), [label %latch]
603 ; CHECK-LABEL: latch:
604 ; CHECK-NEXT:    %gep.1 = getelementptr i32, i32* %x, i32 %offset
605 ; CHECK-NEXT:    %l1 = load i32, i32* %gep.1
606 ; CHECK-NEXT:    %iv.next = add i32 %iv, 1
607 ; CHECK-NEXT:    br i1 %cond, label %exit, label %latch.header_crit_edge
609 ; CHECK-LABEL: latch.header_crit_edge:
610 ; CHECK-LABEL:   br label %header
612 entry:
613   %l0 = load i32, i32* %x
614   call void @use_i32(i32 %l0)
615   br label %header
617 header:
618   %iv = phi i32 [2, %entry], [ %iv.next, %latch]
619   %offset = add i32 %iv, -2
620   indirectbr i8* blockaddress(@phi_trans7, %latch), [label %latch]
622 latch:
623   %gep.1 = getelementptr i32, i32* %x, i32 %offset
624   %l1 = load i32, i32* %gep.1
625   %iv.next = add i32 %iv, 1
626   br i1 %cond, label %exit, label %header
628 exit:
629   ret i32 %l1
632 ; FIXME: Currently we fail to translate the PHI in this case.
633 define i32 @phi_trans8(i32* noalias nocapture readonly %x, i1 %cond) {
634 ; CHECK-LABEL: define i32 @phi_trans8(
635 ; CHECK-LABEL: entry:
636 ; CHECK-NEXT:   %l0 = load i32, i32* %x
638 ; CHECK-LABEL: header:
639 ; CHECK-NEXT:    %iv = phi i32 [ 2, %entry ], [ %iv.next, %latch.header_crit_edge ]
640 ; CHECK-NEXT:    indirectbr i8* blockaddress(@phi_trans8, %latch), [label %latch]
642 ; CHECK-LABEL: latch:
643 ; CHECK-NEXT:    %offset = add i32 %iv, -2
644 ; CHECK-NEXT:    %gep.1 = getelementptr i32, i32* %x, i32 %offset
645 ; CHECK-NEXT:    %l1 = load i32, i32* %gep.1
646 ; CHECK-NEXT:    %iv.next = add i32 %iv, 1
647 ; CHECK-NEXT:    br i1 %cond, label %exit, label %latch.header_crit_edge
649 ; CHECK-LABEL: latch.header_crit_edge:
650 ; CHECK-LABEL:   br label %header
652 entry:
653   %l0 = load i32, i32* %x
654   call void @use_i32(i32 %l0)
655   br label %header
657 header:
658   %iv = phi i32 [2, %entry], [ %iv.next, %latch]
659   indirectbr i8* blockaddress(@phi_trans8, %latch), [label %latch]
661 latch:
662   %offset = add i32 %iv, -2
663   %gep.1 = getelementptr i32, i32* %x, i32 %offset
664   %l1 = load i32, i32* %gep.1
665   %iv.next = add i32 %iv, 1
666   br i1 %cond, label %exit, label %header
668 exit:
669   ret i32 %l1
674 ; PR6642
675 define i32 @memset_to_load() nounwind readnone {
676 entry:
677   %x = alloca [256 x i32], align 4                ; <[256 x i32]*> [#uses=2]
678   %tmp = bitcast [256 x i32]* %x to i8*           ; <i8*> [#uses=1]
679   call void @llvm.memset.p0i8.i64(i8* align 4 %tmp, i8 0, i64 1024, i1 false)
680   %arraydecay = getelementptr inbounds [256 x i32], [256 x i32]* %x, i32 0, i32 0 ; <i32*>
681   %tmp1 = load i32, i32* %arraydecay                   ; <i32> [#uses=1]
682   ret i32 %tmp1
683 ; CHECK-LABEL: @memset_to_load(
684 ; CHECK: ret i32 0
688 ;;===----------------------------------------------------------------------===;;
689 ;; Load -> Load forwarding in partial alias case.
690 ;;===----------------------------------------------------------------------===;;
692 define i32 @load_load_partial_alias(i8* %P) nounwind ssp {
693 entry:
694   %0 = bitcast i8* %P to i32*
695   %tmp2 = load i32, i32* %0
696   %add.ptr = getelementptr inbounds i8, i8* %P, i64 1
697   %tmp5 = load i8, i8* %add.ptr
698   %conv = zext i8 %tmp5 to i32
699   %add = add nsw i32 %tmp2, %conv
700   ret i32 %add
702 ; TEMPORARILYDISABLED-LABEL: @load_load_partial_alias(
703 ; TEMPORARILYDISABLED: load i32, i32*
704 ; TEMPORARILYDISABLED-NOT: load
705 ; TEMPORARILYDISABLED: lshr i32 {{.*}}, 8
706 ; TEMPORARILYDISABLED-NOT: load
707 ; TEMPORARILYDISABLED: trunc i32 {{.*}} to i8
708 ; TEMPORARILYDISABLED-NOT: load
709 ; TEMPORARILYDISABLED: ret i32
713 ; Cross block partial alias case.
714 define i32 @load_load_partial_alias_cross_block(i8* %P) nounwind ssp {
715 entry:
716   %xx = bitcast i8* %P to i32*
717   %x1 = load i32, i32* %xx, align 4
718   %cmp = icmp eq i32 %x1, 127
719   br i1 %cmp, label %land.lhs.true, label %if.end
721 land.lhs.true:                                    ; preds = %entry
722   %arrayidx4 = getelementptr inbounds i8, i8* %P, i64 1
723   %tmp5 = load i8, i8* %arrayidx4, align 1
724   %conv6 = zext i8 %tmp5 to i32
725   ret i32 %conv6
727 if.end:
728   ret i32 52
729 ; TEMPORARILY_DISABLED-LABEL: @load_load_partial_alias_cross_block(
730 ; TEMPORARILY_DISABLED: land.lhs.true:
731 ; TEMPORARILY_DISABLED-NOT: load i8
732 ; TEMPORARILY_DISABLED: ret i32 %conv6
736 ;;===----------------------------------------------------------------------===;;
737 ;; Load Widening
738 ;; We explicitly choose NOT to widen. And are testing to make sure we don't.
739 ;;===----------------------------------------------------------------------===;;
741 %widening1 = type { i32, i8, i8, i8, i8 }
743 @f = global %widening1 zeroinitializer, align 4
745 define i32 @test_widening1(i8* %P) nounwind ssp noredzone {
746 entry:
747   %tmp = load i8, i8* getelementptr inbounds (%widening1, %widening1* @f, i64 0, i32 1), align 4
748   %conv = zext i8 %tmp to i32
749   %tmp1 = load i8, i8* getelementptr inbounds (%widening1, %widening1* @f, i64 0, i32 2), align 1
750   %conv2 = zext i8 %tmp1 to i32
751   %add = add nsw i32 %conv, %conv2
752   ret i32 %add
753 ; CHECK-LABEL: @test_widening1(
754 ; CHECK-NOT: load
755 ; CHECK: load i8, i8*
756 ; CHECK: load i8, i8*
757 ; CHECK-NOT: load
758 ; CHECK: ret i32
761 define i32 @test_widening2() nounwind ssp noredzone {
762 entry:
763   %tmp = load i8, i8* getelementptr inbounds (%widening1, %widening1* @f, i64 0, i32 1), align 4
764   %conv = zext i8 %tmp to i32
765   %tmp1 = load i8, i8* getelementptr inbounds (%widening1, %widening1* @f, i64 0, i32 2), align 1
766   %conv2 = zext i8 %tmp1 to i32
767   %add = add nsw i32 %conv, %conv2
769   %tmp2 = load i8, i8* getelementptr inbounds (%widening1, %widening1* @f, i64 0, i32 3), align 2
770   %conv3 = zext i8 %tmp2 to i32
771   %add2 = add nsw i32 %add, %conv3
773   %tmp3 = load i8, i8* getelementptr inbounds (%widening1, %widening1* @f, i64 0, i32 4), align 1
774   %conv4 = zext i8 %tmp3 to i32
775   %add3 = add nsw i32 %add2, %conv3
777   ret i32 %add3
778 ; CHECK-LABEL: @test_widening2(
779 ; CHECK-NOT: load
780 ; CHECK: load i8, i8*
781 ; CHECK: load i8, i8*
782 ; CHECK: load i8, i8*
783 ; CHECK: load i8, i8*
784 ; CHECK-NOT: load
785 ; CHECK: ret i32
789 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
791 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
792 declare void @llvm.memcpy.p0i8.p1i8.i64(i8* nocapture, i8 addrspace(1)* nocapture, i64, i1) nounwind
795 ;;===----------------------------------------------------------------------===;;
796 ;; Load -> Store dependency which isn't interfered with by a call that happens
797 ;; before the pointer was captured.
798 ;;===----------------------------------------------------------------------===;;
800 %class.X = type { [8 x i8] }
802 @_ZTV1X = weak_odr constant [5 x i8*] zeroinitializer
803 @_ZTV1Y = weak_odr constant [5 x i8*] zeroinitializer
805 declare void @use()
806 declare void @use3(i8***, i8**)
808 ; PR8908
809 define void @test_escape1() nounwind {
810   %x = alloca i8**, align 8
811   store i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @_ZTV1X, i64 0, i64 2), i8*** %x, align 8
812   call void @use() nounwind
813   %DEAD = load i8**, i8*** %x, align 8
814   call void @use3(i8*** %x, i8** %DEAD) nounwind
815   ret void
816 ; CHECK: test_escape1
817 ; CHECK-NOT: DEAD
818 ; CHECK: ret