Taints the non-acquire RMW's store address with the load part
[oota-llvm.git] / test / Transforms / InstCombine / load.ll
1 ; RUN: opt -instcombine -S < %s | FileCheck %s
2 ; RUN: opt -passes=instcombine -S < %s | FileCheck %s
3
4 ; This test makes sure that these instructions are properly eliminated.
5
6 target datalayout = "e-m:e-p:64:64:64-i64:64-f80:128-n8:16:32:64-S128"
7
8 @X = constant i32 42            ; <i32*> [#uses=2]
9 @X2 = constant i32 47           ; <i32*> [#uses=1]
10 @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]
11 @Z = constant [2 x { i32, float }] zeroinitializer              ; <[2 x { i32, float }]*> [#uses=1]
12
13 @GLOBAL = internal constant [4 x i32] zeroinitializer
14
15
16 ; CHECK-LABEL: @test1(
17 ; CHECK-NOT: load
18 define i32 @test1() {
19         %B = load i32, i32* @X          ; <i32> [#uses=1]
20         ret i32 %B
21 }
22
23 ; CHECK-LABEL: @test2(
24 ; CHECK-NOT: load
25 define float @test2() {
26         %A = getelementptr [2 x { i32, float }], [2 x { i32, float }]* @Y, i64 0, i64 1, i32 1          ; <float*> [#uses=1]
27         %B = load float, float* %A              ; <float> [#uses=1]
28         ret float %B
29 }
30
31 ; CHECK-LABEL: @test3(
32 ; CHECK-NOT: load
33 define i32 @test3() {
34         %A = getelementptr [2 x { i32, float }], [2 x { i32, float }]* @Y, i64 0, i64 0, i32 0          ; <i32*> [#uses=1]
35         %B = load i32, i32* %A          ; <i32> [#uses=1]
36         ret i32 %B
37 }
38
39 ; CHECK-LABEL: @test4(
40 ; CHECK-NOT: load
41 define i32 @test4() {
42         %A = getelementptr [2 x { i32, float }], [2 x { i32, float }]* @Z, i64 0, i64 1, i32 0          ; <i32*> [#uses=1]
43         %B = load i32, i32* %A          ; <i32> [#uses=1]
44         ret i32 %B
45 }
46
47 ; CHECK-LABEL: @test5(
48 ; CHECK-NOT: load
49 define i32 @test5(i1 %C) {
50         %Y = select i1 %C, i32* @X, i32* @X2            ; <i32*> [#uses=1]
51         %Z = load i32, i32* %Y          ; <i32> [#uses=1]
52         ret i32 %Z
53 }
54
55 ; CHECK-LABEL: @test7(
56 ; CHECK-NOT: load
57 define i32 @test7(i32 %X) {
58         %V = getelementptr i32, i32* null, i32 %X               ; <i32*> [#uses=1]
59         %R = load i32, i32* %V          ; <i32> [#uses=1]
60         ret i32 %R
61 }
62
63 ; CHECK-LABEL: @test8(
64 ; CHECK-NOT: load
65 define i32 @test8(i32* %P) {
66         store i32 1, i32* %P
67         %X = load i32, i32* %P          ; <i32> [#uses=1]
68         ret i32 %X
69 }
70
71 ; CHECK-LABEL: @test9(
72 ; CHECK-NOT: load
73 define i32 @test9(i32* %P) {
74         %X = load i32, i32* %P          ; <i32> [#uses=1]
75         %Y = load i32, i32* %P          ; <i32> [#uses=1]
76         %Z = sub i32 %X, %Y             ; <i32> [#uses=1]
77         ret i32 %Z
78 }
79
80 ; CHECK-LABEL: @test10(
81 ; CHECK-NOT: load
82 define i32 @test10(i1 %C.upgrd.1, i32* %P, i32* %Q) {
83         br i1 %C.upgrd.1, label %T, label %F
84 T:              ; preds = %0
85         store i32 1, i32* %Q
86         store i32 0, i32* %P
87         br label %C
88 F:              ; preds = %0
89         store i32 0, i32* %P
90         br label %C
91 C:              ; preds = %F, %T
92         %V = load i32, i32* %P          ; <i32> [#uses=1]
93         ret i32 %V
94 }
95
96 ; CHECK-LABEL: @test11(
97 ; CHECK-NOT: load
98 define double @test11(double* %p) {
99   %t0 = getelementptr double, double* %p, i32 1
100   store double 2.0, double* %t0
101   %t1 = getelementptr double, double* %p, i32 1
102   %x = load double, double* %t1
103   ret double %x
104 }
105
106 ; CHECK-LABEL: @test12(
107 ; CHECK-NOT: load
108 define i32 @test12(i32* %P) {
109   %A = alloca i32
110   store i32 123, i32* %A
111   ; Cast the result of the load not the source
112   %Q = bitcast i32* %A to i32*
113   %V = load i32, i32* %Q
114   ret i32 %V
115 }
116
117 ; CHECK-LABEL: @test13(
118 ; CHECK-NOT: load
119 define <16 x i8> @test13(<2 x i64> %x) {
120   %tmp = load <16 x i8>, <16 x i8>* bitcast ([4 x i32]* @GLOBAL to <16 x i8>*)
121   ret <16 x i8> %tmp
122 }
123
124 define i8 @test14(i8 %x, i32 %y) {
125 ; This test must not have the store of %x forwarded to the load -- there is an
126 ; intervening store if %y. However, the intervening store occurs with a different
127 ; type and size and to a different pointer value. This is ensuring that none of
128 ; those confuse the analysis into thinking that the second store does not alias
129 ; the first.
130 ; CHECK-LABEL: @test14(
131 ; CHECK:         %[[R:.*]] = load i8, i8*
132 ; CHECK-NEXT:    ret i8 %[[R]]
133   %a = alloca i32
134   %a.i8 = bitcast i32* %a to i8*
135   store i8 %x, i8* %a.i8
136   store i32 %y, i32* %a
137   %r = load i8, i8* %a.i8
138   ret i8 %r
139 }
140
141 @test15_global = external global i32
142
143 define i8 @test15(i8 %x, i32 %y) {
144 ; Same test as @test14 essentially, but using a global instead of an alloca.
145 ; CHECK-LABEL: @test15(
146 ; CHECK:         %[[R:.*]] = load i8, i8*
147 ; CHECK-NEXT:    ret i8 %[[R]]
148   %g.i8 = bitcast i32* @test15_global to i8*
149   store i8 %x, i8* %g.i8
150   store i32 %y, i32* @test15_global
151   %r = load i8, i8* %g.i8
152   ret i8 %r
153 }
154
155 define void @test16(i8* %x, i8* %a, i8* %b, i8* %c) {
156 ; Check that we canonicalize loads which are only stored to use integer types
157 ; when there is a valid integer type.
158 ; CHECK-LABEL: @test16(
159 ; CHECK: %[[L1:.*]] = load i32, i32*
160 ; CHECK-NOT: load
161 ; CHECK: store i32 %[[L1]], i32*
162 ; CHECK: store i32 %[[L1]], i32*
163 ; CHECK-NOT: store
164 ; CHECK: %[[L1:.*]] = load i32, i32*
165 ; CHECK-NOT: load
166 ; CHECK: store i32 %[[L1]], i32*
167 ; CHECK: store i32 %[[L1]], i32*
168 ; CHECK-NOT: store
169 ; CHECK: ret
170
171 entry:
172   %x.cast = bitcast i8* %x to float*
173   %a.cast = bitcast i8* %a to float*
174   %b.cast = bitcast i8* %b to float*
175   %c.cast = bitcast i8* %c to i32*
176
177   %x1 = load float, float* %x.cast
178   store float %x1, float* %a.cast
179   store float %x1, float* %b.cast
180
181   %x2 = load float, float* %x.cast
182   store float %x2, float* %b.cast
183   %x2.cast = bitcast float %x2 to i32
184   store i32 %x2.cast, i32* %c.cast
185
186   ret void
187 }
188
189 define void @test17(i8** %x, i8 %y) {
190 ; Check that in cases similar to @test16 we don't try to rewrite a load when
191 ; its only use is a store but it is used as the pointer to that store rather
192 ; than the value.
193 ;
194 ; CHECK-LABEL: @test17(
195 ; CHECK: %[[L:.*]] = load i8*, i8**
196 ; CHECK: store i8 %y, i8* %[[L]]
197
198 entry:
199   %x.load = load i8*, i8** %x
200   store i8 %y, i8* %x.load
201
202   ret void
203 }