]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/blob - test/Transforms/InstCombine/load-cmp.ll
Don't do FoldCmpLoadFromIndexedGlobal for non inbounds GEPs
[opencl/llvm.git] / test / Transforms / InstCombine / load-cmp.ll
1 ; RUN: opt -instcombine -S < %s | FileCheck -check-prefix=NODL %s
2 ; RUN: opt -instcombine -S -default-data-layout="p:32:32:32-n8:16:32:64" < %s | FileCheck -check-prefix=P32 %s
4 @G16 = internal constant [10 x i16] [i16 35, i16 82, i16 69, i16 81, i16 85,
5                                      i16 73, i16 82, i16 69, i16 68, i16 0]
6 @GD = internal constant [6 x double]
7    [double -10.0, double 1.0, double 4.0, double 2.0, double -20.0, double -40.0]
9 %Foo = type { i32, i32, i32, i32 }
11 @GS = internal constant %Foo { i32 1, i32 4, i32 9, i32 14 }
13 @GStructArr = internal constant [4 x %Foo] [ %Foo { i32 1, i32 4, i32 9, i32 14 },
14                                              %Foo { i32 5, i32 4, i32 6, i32 11 },
15                                              %Foo { i32 6, i32 5, i32 9, i32 20 },
16                                              %Foo { i32 12, i32 3, i32 9, i32 8 } ]
19 define i1 @test1(i32 %X) {
20   %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i32 %X
21   %Q = load i16* %P
22   %R = icmp eq i16 %Q, 0
23   ret i1 %R
24 ; NODL-LABEL: @test1(
25 ; NODL-NEXT: %R = icmp eq i32 %X, 9
26 ; NODL-NEXT: ret i1 %R
28 ; P32-LABEL: @test1(
29 ; P32-NEXT: %R = icmp eq i32 %X, 9
30 ; P32-NEXT: ret i1 %R
31 }
33 define i1 @test1_noinbounds(i32 %X) {
34   %P = getelementptr [10 x i16]* @G16, i32 0, i32 %X
35   %Q = load i16* %P
36   %R = icmp eq i16 %Q, 0
37   ret i1 %R
38 ; NODL-LABEL: @test1_noinbounds(
39 ; NODL-NEXT: %P = getelementptr [10 x i16]* @G16, i32 0, i32 %X
41 ; P32-LABEL: @test1_noinbounds(
42 ; P32-NEXT: %P = getelementptr [10 x i16]* @G16, i32 0, i32 %X
43 }
45 define i1 @test2(i32 %X) {
46   %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i32 %X
47   %Q = load i16* %P
48   %R = icmp slt i16 %Q, 85
49   ret i1 %R
50 ; NODL-LABEL: @test2(
51 ; NODL-NEXT: %R = icmp ne i32 %X, 4
52 ; NODL-NEXT: ret i1 %R
53 }
55 define i1 @test3(i32 %X) {
56   %P = getelementptr inbounds [6 x double]* @GD, i32 0, i32 %X
57   %Q = load double* %P
58   %R = fcmp oeq double %Q, 1.0
59   ret i1 %R
60 ; NODL-LABEL: @test3(
61 ; NODL-NEXT: %R = icmp eq i32 %X, 1
62 ; NODL-NEXT: ret i1 %R
64 ; P32-LABEL: @test3(
65 ; P32-NEXT: %R = icmp eq i32 %X, 1
66 ; P32-NEXT: ret i1 %R
68 }
70 define i1 @test4(i32 %X) {
71   %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i32 %X
72   %Q = load i16* %P
73   %R = icmp sle i16 %Q, 73
74   ret i1 %R
75 ; NODL-LABEL: @test4(
76 ; NODL-NEXT: lshr i32 933, %X
77 ; NODL-NEXT: and i32 {{.*}}, 1
78 ; NODL-NEXT: %R = icmp ne i32 {{.*}}, 0
79 ; NODL-NEXT: ret i1 %R
81 ; P32-LABEL: @test4(
82 ; P32-NEXT: lshr i32 933, %X
83 ; P32-NEXT: and i32 {{.*}}, 1
84 ; P32-NEXT: %R = icmp ne i32 {{.*}}, 0
85 ; P32-NEXT: ret i1 %R
86 }
88 define i1 @test4_i16(i16 %X) {
89   %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i16 %X
90   %Q = load i16* %P
91   %R = icmp sle i16 %Q, 73
92   ret i1 %R
94 ; NODL-LABEL: @test4_i16(
95 ; NODL-NEXT: lshr i16 933, %X
96 ; NODL-NEXT: and i16 {{.*}}, 1
97 ; NODL-NEXT: %R = icmp ne i16 {{.*}}, 0
98 ; NODL-NEXT: ret i1 %R
100 ; P32-LABEL: @test4_i16(
101 ; P32-NEXT: sext i16 %X to i32
102 ; P32-NEXT: lshr i32 933, %1
103 ; P32-NEXT: and i32 {{.*}}, 1
104 ; P32-NEXT: %R = icmp ne i32 {{.*}}, 0
105 ; P32-NEXT: ret i1 %R
108 define i1 @test5(i32 %X) {
109   %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i32 %X
110   %Q = load i16* %P
111   %R = icmp eq i16 %Q, 69
112   ret i1 %R
113 ; NODL-LABEL: @test5(
114 ; NODL-NEXT: icmp eq i32 %X, 2
115 ; NODL-NEXT: icmp eq i32 %X, 7
116 ; NODL-NEXT: %R = or i1
117 ; NODL-NEXT: ret i1 %R
119 ; P32-LABEL: @test5(
120 ; P32-NEXT: icmp eq i32 %X, 2
121 ; P32-NEXT: icmp eq i32 %X, 7
122 ; P32-NEXT: %R = or i1
123 ; P32-NEXT: ret i1 %R
126 define i1 @test6(i32 %X) {
127   %P = getelementptr inbounds [6 x double]* @GD, i32 0, i32 %X
128   %Q = load double* %P
129   %R = fcmp ogt double %Q, 0.0
130   ret i1 %R
131 ; NODL-LABEL: @test6(
132 ; NODL-NEXT: add i32 %X, -1
133 ; NODL-NEXT: %R = icmp ult i32 {{.*}}, 3
134 ; NODL-NEXT: ret i1 %R
136 ; P32-LABEL: @test6(
137 ; P32-NEXT: add i32 %X, -1
138 ; P32-NEXT: %R = icmp ult i32 {{.*}}, 3
139 ; P32-NEXT: ret i1 %R
142 define i1 @test7(i32 %X) {
143   %P = getelementptr inbounds [6 x double]* @GD, i32 0, i32 %X
144   %Q = load double* %P
145   %R = fcmp olt double %Q, 0.0
146   ret i1 %R
147 ; NODL-LABEL: @test7(
148 ; NODL-NEXT: add i32 %X, -1
149 ; NODL-NEXT: %R = icmp ugt i32 {{.*}}, 2
150 ; NODL-NEXT: ret i1 %R
152 ; P32-LABEL: @test7(
153 ; P32-NEXT: add i32 %X, -1
154 ; P32-NEXT: %R = icmp ugt i32 {{.*}}, 2
155 ; P32-NEXT: ret i1 %R
158 define i1 @test8(i32 %X) {
159   %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i32 %X
160   %Q = load i16* %P
161   %R = and i16 %Q, 3
162   %S = icmp eq i16 %R, 0
163   ret i1 %S
164 ; NODL-LABEL: @test8(
165 ; NODL-NEXT: and i32 %X, -2
166 ; NODL-NEXT: icmp eq i32 {{.*}}, 8
167 ; NODL-NEXT: ret i1
169 ; P32-LABEL: @test8(
170 ; P32-NEXT: and i32 %X, -2
171 ; P32-NEXT: icmp eq i32 {{.*}}, 8
172 ; P32-NEXT: ret i1
175 @GA = internal constant [4 x { i32, i32 } ] [
176   { i32, i32 } { i32 1, i32 0 },
177   { i32, i32 } { i32 2, i32 1 },
178   { i32, i32 } { i32 3, i32 1 },
179   { i32, i32 } { i32 4, i32 0 }
182 define i1 @test9(i32 %X) {
183   %P = getelementptr inbounds [4 x { i32, i32 } ]* @GA, i32 0, i32 %X, i32 1
184   %Q = load i32* %P
185   %R = icmp eq i32 %Q, 1
186   ret i1 %R
187 ; NODL-LABEL: @test9(
188 ; NODL-NEXT: add i32 %X, -1
189 ; NODL-NEXT: icmp ult i32 {{.*}}, 2
190 ; NODL-NEXT: ret i1
192 ; P32-LABEL: @test9(
193 ; P32-NEXT: add i32 %X, -1
194 ; P32-NEXT: icmp ult i32 {{.*}}, 2
195 ; P32-NEXT: ret i1
198 define i1 @test10_struct(i32 %x) {
199 ; NODL-LABEL: @test10_struct(
200 ; NODL: getelementptr inbounds %Foo* @GS, i32 %x, i32 0
202 ; P32-LABEL: @test10_struct(
203 ; P32: getelementptr inbounds %Foo* @GS, i32 %x, i32 0
204   %p = getelementptr inbounds %Foo* @GS, i32 %x, i32 0
205   %q = load i32* %p
206   %r = icmp eq i32 %q, 9
207   ret i1 %r
210 define i1 @test10_struct_noinbounds(i32 %x) {
211 ; NODL-LABEL: @test10_struct_noinbounds(
212 ; NODL: getelementptr %Foo* @GS, i32 %x, i32 0
214 ; P32-LABEL: @test10_struct_noinbounds(
215 ; P32: getelementptr %Foo* @GS, i32 %x, i32 0
216   %p = getelementptr %Foo* @GS, i32 %x, i32 0
217   %q = load i32* %p
218   %r = icmp eq i32 %q, 9
219   ret i1 %r
222 ; Test that the GEP indices are converted before we ever get here
223 ; Index < ptr size
224 define i1 @test10_struct_i16(i16 %x){
225 ; NODL-LABEL: @test10_struct_i16(
226 ; NODL: getelementptr inbounds %Foo* @GS, i16 %x, i32 0
228 ; P32-LABEL: @test10_struct_i16(
229 ; P32: %1 = sext i16 %x to i32
230 ; P32: getelementptr inbounds %Foo* @GS, i32 %1, i32 0
231   %p = getelementptr inbounds %Foo* @GS, i16 %x, i32 0
232   %q = load i32* %p
233   %r = icmp eq i32 %q, 0
234   ret i1 %r
237 ; Test that the GEP indices are converted before we ever get here
238 ; Index > ptr size
239 define i1 @test10_struct_i64(i64 %x){
240 ; NODL-LABEL: @test10_struct_i64(
241 ; NODL: getelementptr inbounds %Foo* @GS, i64 %x, i32 0
243 ; P32-LABEL: @test10_struct_i64(
244 ; P32: %1 = trunc i64 %x to i32
245 ; P32: getelementptr inbounds %Foo* @GS, i32 %1, i32 0
246   %p = getelementptr inbounds %Foo* @GS, i64 %x, i32 0
247   %q = load i32* %p
248   %r = icmp eq i32 %q, 0
249   ret i1 %r
252 define i1 @test10_struct_arr(i32 %x) {
253 ; NODL-LABEL: @test10_struct_arr(
254 ; NODL-NEXT: %r = icmp ne i32 %x, 1
255 ; NODL-NEXT: ret i1 %r
257 ; P32-LABEL: @test10_struct_arr(
258 ; P32-NEXT: %r = icmp ne i32 %x, 1
259 ; P32-NEXT: ret i1 %r
260   %p = getelementptr inbounds [4 x %Foo]* @GStructArr, i32 0, i32 %x, i32 2
261   %q = load i32* %p
262   %r = icmp eq i32 %q, 9
263   ret i1 %r
266 define i1 @test10_struct_arr_i16(i16 %x) {
267 ; NODL-LABEL: @test10_struct_arr_i16(
268 ; NODL-NEXT: %r = icmp ne i16 %x, 1
269 ; NODL-NEXT: ret i1 %r
271 ; P32-LABEL: @test10_struct_arr_i16(
272 ; P32-NEXT: %r = icmp ne i16 %x, 1
273 ; P32-NEXT: ret i1 %r
274   %p = getelementptr inbounds [4 x %Foo]* @GStructArr, i16 0, i16 %x, i32 2
275   %q = load i32* %p
276   %r = icmp eq i32 %q, 9
277   ret i1 %r
280 define i1 @test10_struct_arr_i64(i64 %x) {
281 ; NODL-LABEL: @test10_struct_arr_i64(
282 ; NODL-NEXT: %r = icmp ne i64 %x, 1
283 ; NODL-NEXT: ret i1 %r
285 ; P32-LABEL: @test10_struct_arr_i64(
286 ; P32-NEXT: trunc i64 %x to i32
287 ; P32-NEXT: %r = icmp ne i32 %1, 1
288 ; P32-NEXT: ret i1 %r
289   %p = getelementptr inbounds [4 x %Foo]* @GStructArr, i64 0, i64 %x, i32 2
290   %q = load i32* %p
291   %r = icmp eq i32 %q, 9
292   ret i1 %r