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
22 %R = icmp eq i16 %Q, 0
25 ; NODL-NEXT: %R = icmp eq i32 %X, 9
26 ; NODL-NEXT: ret i1 %R
29 ; P32-NEXT: %R = icmp eq i32 %X, 9
33 define i1 @test1_noinbounds(i32 %X) {
34 %P = getelementptr [10 x i16]* @G16, i32 0, i32 %X
36 %R = icmp eq i16 %Q, 0
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
45 define i1 @test2(i32 %X) {
46 %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i32 %X
48 %R = icmp slt i16 %Q, 85
51 ; NODL-NEXT: %R = icmp ne i32 %X, 4
52 ; NODL-NEXT: ret i1 %R
55 define i1 @test3(i32 %X) {
56 %P = getelementptr inbounds [6 x double]* @GD, i32 0, i32 %X
58 %R = fcmp oeq double %Q, 1.0
61 ; NODL-NEXT: %R = icmp eq i32 %X, 1
62 ; NODL-NEXT: ret i1 %R
65 ; P32-NEXT: %R = icmp eq i32 %X, 1
70 define i1 @test4(i32 %X) {
71 %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i32 %X
73 %R = icmp sle i16 %Q, 73
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
82 ; P32-NEXT: lshr i32 933, %X
83 ; P32-NEXT: and i32 {{.*}}, 1
84 ; P32-NEXT: %R = icmp ne i32 {{.*}}, 0
88 define i1 @test4_i16(i16 %X) {
89 %P = getelementptr inbounds [10 x i16]* @G16, i32 0, i16 %X
91 %R = icmp sle i16 %Q, 73
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
111 %R = icmp eq i16 %Q, 69
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
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
129 %R = fcmp ogt double %Q, 0.0
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
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
145 %R = fcmp olt double %Q, 0.0
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
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
162 %S = icmp eq i16 %R, 0
164 ; NODL-LABEL: @test8(
165 ; NODL-NEXT: and i32 %X, -2
166 ; NODL-NEXT: icmp eq i32 {{.*}}, 8
170 ; P32-NEXT: and i32 %X, -2
171 ; P32-NEXT: icmp eq i32 {{.*}}, 8
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
185 %R = icmp eq i32 %Q, 1
187 ; NODL-LABEL: @test9(
188 ; NODL-NEXT: add i32 %X, -1
189 ; NODL-NEXT: icmp ult i32 {{.*}}, 2
193 ; P32-NEXT: add i32 %X, -1
194 ; P32-NEXT: icmp ult i32 {{.*}}, 2
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
206 %r = icmp eq i32 %q, 9
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
218 %r = icmp eq i32 %q, 9
222 ; Test that the GEP indices are converted before we ever get here
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
233 %r = icmp eq i32 %q, 0
237 ; Test that the GEP indices are converted before we ever get here
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
248 %r = icmp eq i32 %q, 0
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
262 %r = icmp eq i32 %q, 9
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
276 %r = icmp eq i32 %q, 9
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
291 %r = icmp eq i32 %q, 9