Removed extra whitespace. (Testing commit access). NFC.
[oota-llvm.git] / test / Transforms / InstCombine / load.ll
1 ; RUN: opt -instcombine -S < %s | FileCheck %s
2
3 ; This test makes sure that these instructions are properly eliminated.
4
5 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
6
7 @X = constant i32 42            ; <i32*> [#uses=2]
8 @X2 = constant i32 47           ; <i32*> [#uses=1]
9 @Y = constant [2 x { i32, float }] [ { i32, float } { i32 12, float 1.000000e+00 }, { i32, float } { i32 37, float 0x3FF3B2FEC0000000 } ]               ; <[2 x { i32, float }]*> [#uses=2]
10 @Z = constant [2 x { i32, float }] zeroinitializer              ; <[2 x { i32, float }]*> [#uses=1]
11
12 @GLOBAL = internal constant [4 x i32] zeroinitializer
13
14
15 ; CHECK-LABEL: @test1(
16 ; CHECK-NOT: load
17 define i32 @test1() {
18         %B = load i32* @X               ; <i32> [#uses=1]
19         ret i32 %B
20 }
21
22 ; CHECK-LABEL: @test2(
23 ; CHECK-NOT: load
24 define float @test2() {
25         %A = getelementptr [2 x { i32, float }]* @Y, i64 0, i64 1, i32 1                ; <float*> [#uses=1]
26         %B = load float* %A             ; <float> [#uses=1]
27         ret float %B
28 }
29
30 ; CHECK-LABEL: @test3(
31 ; CHECK-NOT: load
32 define i32 @test3() {
33         %A = getelementptr [2 x { i32, float }]* @Y, i64 0, i64 0, i32 0                ; <i32*> [#uses=1]
34         %B = load i32* %A               ; <i32> [#uses=1]
35         ret i32 %B
36 }
37
38 ; CHECK-LABEL: @test4(
39 ; CHECK-NOT: load
40 define i32 @test4() {
41         %A = getelementptr [2 x { i32, float }]* @Z, i64 0, i64 1, i32 0                ; <i32*> [#uses=1]
42         %B = load i32* %A               ; <i32> [#uses=1]
43         ret i32 %B
44 }
45
46 ; CHECK-LABEL: @test5(
47 ; CHECK-NOT: load
48 define i32 @test5(i1 %C) {
49         %Y = select i1 %C, i32* @X, i32* @X2            ; <i32*> [#uses=1]
50         %Z = load i32* %Y               ; <i32> [#uses=1]
51         ret i32 %Z
52 }
53
54 ; CHECK-LABEL: @test7(
55 ; CHECK-NOT: load
56 define i32 @test7(i32 %X) {
57         %V = getelementptr i32* null, i32 %X            ; <i32*> [#uses=1]
58         %R = load i32* %V               ; <i32> [#uses=1]
59         ret i32 %R
60 }
61
62 ; CHECK-LABEL: @test8(
63 ; CHECK-NOT: load
64 define i32 @test8(i32* %P) {
65         store i32 1, i32* %P
66         %X = load i32* %P               ; <i32> [#uses=1]
67         ret i32 %X
68 }
69
70 ; CHECK-LABEL: @test9(
71 ; CHECK-NOT: load
72 define i32 @test9(i32* %P) {
73         %X = load i32* %P               ; <i32> [#uses=1]
74         %Y = load i32* %P               ; <i32> [#uses=1]
75         %Z = sub i32 %X, %Y             ; <i32> [#uses=1]
76         ret i32 %Z
77 }
78
79 ; CHECK-LABEL: @test10(
80 ; CHECK-NOT: load
81 define i32 @test10(i1 %C.upgrd.1, i32* %P, i32* %Q) {
82         br i1 %C.upgrd.1, label %T, label %F
83 T:              ; preds = %0
84         store i32 1, i32* %Q
85         store i32 0, i32* %P
86         br label %C
87 F:              ; preds = %0
88         store i32 0, i32* %P
89         br label %C
90 C:              ; preds = %F, %T
91         %V = load i32* %P               ; <i32> [#uses=1]
92         ret i32 %V
93 }
94
95 ; CHECK-LABEL: @test11(
96 ; CHECK-NOT: load
97 define double @test11(double* %p) {
98   %t0 = getelementptr double* %p, i32 1
99   store double 2.0, double* %t0
100   %t1 = getelementptr double* %p, i32 1
101   %x = load double* %t1
102   ret double %x
103 }
104
105 ; CHECK-LABEL: @test12(
106 ; CHECK-NOT: load
107 define i32 @test12(i32* %P) {
108   %A = alloca i32
109   store i32 123, i32* %A
110   ; Cast the result of the load not the source
111   %Q = bitcast i32* %A to i32*
112   %V = load i32* %Q
113   ret i32 %V
114 }
115
116 ; CHECK-LABEL: @test13(
117 ; CHECK-NOT: load
118 define <16 x i8> @test13(<2 x i64> %x) {
119   %tmp = load <16 x i8>* bitcast ([4 x i32]* @GLOBAL to <16 x i8>*)
120   ret <16 x i8> %tmp
121 }
122
123 define i8 @test14(i8 %x, i32 %y) {
124 ; This test must not have the store of %x forwarded to the load -- there is an
125 ; intervening store if %y. However, the intervening store occurs with a different
126 ; type and size and to a different pointer value. This is ensuring that none of
127 ; those confuse the analysis into thinking that the second store does not alias
128 ; the first.
129 ; CHECK-LABEL: @test14(
130 ; CHECK:         %[[R:.*]] = load i8*
131 ; CHECK-NEXT:    ret i8 %[[R]]
132   %a = alloca i32
133   %a.i8 = bitcast i32* %a to i8*
134   store i8 %x, i8* %a.i8
135   store i32 %y, i32* %a
136   %r = load i8* %a.i8
137   ret i8 %r
138 }
139
140 @test15_global = external global i32
141
142 define i8 @test15(i8 %x, i32 %y) {
143 ; Same test as @test14 essentially, but using a global instead of an alloca.
144 ; CHECK-LABEL: @test15(
145 ; CHECK:         %[[R:.*]] = load i8*
146 ; CHECK-NEXT:    ret i8 %[[R]]
147   %g.i8 = bitcast i32* @test15_global to i8*
148   store i8 %x, i8* %g.i8
149   store i32 %y, i32* @test15_global
150   %r = load i8* %g.i8
151   ret i8 %r
152 }