1 ; "PLAIN" - No optimizations. This tests the target-independent
3 ; RUN: opt -S -o - < %s | FileCheck --check-prefix=PLAIN %s
5 ; "OPT" - Optimizations but no targetdata. This tests target-independent
6 ; folding in the optimizers.
7 ; RUN: opt -S -o - -instcombine -globalopt < %s | FileCheck --check-prefix=OPT %s
9 ; "TO" - Optimizations and targetdata. This tests target-dependent
10 ; folding in the optimizers.
11 ; RUN: opt -S -o - -instcombine -globalopt -default-data-layout="e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" < %s | FileCheck --check-prefix=TO %s
13 ; "SCEV" - ScalarEvolution but no targetdata.
14 ; RUN: opt -analyze -scalar-evolution < %s | FileCheck --check-prefix=SCEV %s
16 ; ScalarEvolution with targetdata isn't interesting on these testcases
17 ; because ScalarEvolution doesn't attempt to duplicate all of instcombine's
18 ; and the constant folders' folding.
20 ; PLAIN: %0 = type { i1, double }
21 ; PLAIN: %1 = type { double, float, double, double }
22 ; PLAIN: %2 = type { i64, i64 }
23 ; OPT: %0 = type { i1, double }
24 ; OPT: %1 = type { double, float, double, double }
25 ; OPT: %2 = type { i64, i64 }
27 ; The automatic constant folder in opt does not have targetdata access, so
28 ; it can't fold gep arithmetic, in general. However, the constant folder run
29 ; from instcombine and global opt can use targetdata.
31 ; PLAIN: @G8 = global i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1)
32 ; PLAIN: @G1 = global i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1)
33 ; PLAIN: @F8 = global i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2)
34 ; PLAIN: @F1 = global i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2)
35 ; PLAIN: @H8 = global i8* getelementptr (i8* null, i32 -1)
36 ; PLAIN: @H1 = global i1* getelementptr (i1* null, i32 -1)
37 ; OPT: @G8 = global i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1)
38 ; OPT: @G1 = global i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1)
39 ; OPT: @F8 = global i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2)
40 ; OPT: @F1 = global i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2)
41 ; OPT: @H8 = global i8* getelementptr (i8* null, i32 -1)
42 ; OPT: @H1 = global i1* getelementptr (i1* null, i32 -1)
43 ; TO: @G8 = global i8* null
44 ; TO: @G1 = global i1* null
45 ; TO: @F8 = global i8* inttoptr (i64 -1 to i8*)
46 ; TO: @F1 = global i1* inttoptr (i64 -1 to i1*)
47 ; TO: @H8 = global i8* inttoptr (i64 -1 to i8*)
48 ; TO: @H1 = global i1* inttoptr (i64 -1 to i1*)
50 @G8 = global i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1)
51 @G1 = global i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1)
52 @F8 = global i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2)
53 @F1 = global i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2)
54 @H8 = global i8* getelementptr (i8* inttoptr (i32 0 to i8*), i32 -1)
55 @H1 = global i1* getelementptr (i1* inttoptr (i32 0 to i1*), i32 -1)
57 ; The target-independent folder should be able to do some clever
58 ; simplifications on sizeof, alignof, and offsetof expressions. The
59 ; target-dependent folder should fold these down to constants.
61 ; PLAIN: @a = constant i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2310)
62 ; PLAIN: @b = constant i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64)
63 ; PLAIN: @c = constant i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2)
64 ; PLAIN: @d = constant i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 11)
65 ; PLAIN: @e = constant i64 ptrtoint (double* getelementptr (%1* null, i64 0, i32 2) to i64)
66 ; PLAIN: @f = constant i64 1
67 ; PLAIN: @g = constant i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64)
68 ; OPT: @a = constant i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2310)
69 ; OPT: @b = constant i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64)
70 ; OPT: @c = constant i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2)
71 ; OPT: @d = constant i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 11)
72 ; OPT: @e = constant i64 ptrtoint (double* getelementptr (%1* null, i64 0, i32 2) to i64)
73 ; OPT: @f = constant i64 1
74 ; OPT: @g = constant i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64)
75 ; TO: @a = constant i64 18480
76 ; TO: @b = constant i64 8
77 ; TO: @c = constant i64 16
78 ; TO: @d = constant i64 88
79 ; TO: @e = constant i64 16
80 ; TO: @f = constant i64 1
81 ; TO: @g = constant i64 8
83 @a = constant i64 mul (i64 3, i64 mul (i64 ptrtoint ({[7 x double], [7 x double]}* getelementptr ({[7 x double], [7 x double]}* null, i64 11) to i64), i64 5))
84 @b = constant i64 ptrtoint ([13 x double]* getelementptr ({i1, [13 x double]}* null, i64 0, i32 1) to i64)
85 @c = constant i64 ptrtoint (double* getelementptr ({double, double, double, double}* null, i64 0, i32 2) to i64)
86 @d = constant i64 ptrtoint (double* getelementptr ([13 x double]* null, i64 0, i32 11) to i64)
87 @e = constant i64 ptrtoint (double* getelementptr ({double, float, double, double}* null, i64 0, i32 2) to i64)
88 @f = constant i64 ptrtoint (<{ i16, i128 }>* getelementptr ({i1, <{ i16, i128 }>}* null, i64 0, i32 1) to i64)
89 @g = constant i64 ptrtoint ({double, double}* getelementptr ({i1, {double, double}}* null, i64 0, i32 1) to i64)
91 ; The target-dependent folder should cast GEP indices to integer-sized pointers.
93 ; PLAIN: @M = constant i64* getelementptr (i64* null, i32 1)
94 ; PLAIN: @N = constant i64* getelementptr (%2* null, i32 0, i32 1)
95 ; PLAIN: @O = constant i64* getelementptr ([2 x i64]* null, i32 0, i32 1)
96 ; OPT: @M = constant i64* getelementptr (i64* null, i32 1)
97 ; OPT: @N = constant i64* getelementptr (%2* null, i32 0, i32 1)
98 ; OPT: @O = constant i64* getelementptr ([2 x i64]* null, i32 0, i32 1)
99 ; TO: @M = constant i64* inttoptr (i64 8 to i64*)
100 ; TO: @N = constant i64* inttoptr (i64 8 to i64*)
101 ; TO: @O = constant i64* inttoptr (i64 8 to i64*)
103 @M = constant i64* getelementptr (i64 *null, i32 1)
104 @N = constant i64* getelementptr ({ i64, i64 } *null, i32 0, i32 1)
105 @O = constant i64* getelementptr ([2 x i64] *null, i32 0, i32 1)
107 ; Duplicate all of the above as function return values rather than
108 ; global initializers.
110 ; PLAIN: define i8* @goo8() nounwind {
111 ; PLAIN: %t = bitcast i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1) to i8*
114 ; PLAIN: define i1* @goo1() nounwind {
115 ; PLAIN: %t = bitcast i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1) to i1*
118 ; PLAIN: define i8* @foo8() nounwind {
119 ; PLAIN: %t = bitcast i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2) to i8*
122 ; PLAIN: define i1* @foo1() nounwind {
123 ; PLAIN: %t = bitcast i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2) to i1*
126 ; PLAIN: define i8* @hoo8() nounwind {
127 ; PLAIN: %t = bitcast i8* getelementptr (i8* null, i32 -1) to i8*
130 ; PLAIN: define i1* @hoo1() nounwind {
131 ; PLAIN: %t = bitcast i1* getelementptr (i1* null, i32 -1) to i1*
134 ; OPT: define i8* @goo8() nounwind {
135 ; OPT: ret i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1)
137 ; OPT: define i1* @goo1() nounwind {
138 ; OPT: ret i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1)
140 ; OPT: define i8* @foo8() nounwind {
141 ; OPT: ret i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2)
143 ; OPT: define i1* @foo1() nounwind {
144 ; OPT: ret i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2)
146 ; OPT: define i8* @hoo8() nounwind {
147 ; OPT: ret i8* getelementptr (i8* null, i32 -1)
149 ; OPT: define i1* @hoo1() nounwind {
150 ; OPT: ret i1* getelementptr (i1* null, i32 -1)
152 ; TO: define i8* @goo8() nounwind {
155 ; TO: define i1* @goo1() nounwind {
158 ; TO: define i8* @foo8() nounwind {
159 ; TO: ret i8* inttoptr (i64 -1 to i8*)
161 ; TO: define i1* @foo1() nounwind {
162 ; TO: ret i1* inttoptr (i64 -1 to i1*)
164 ; TO: define i8* @hoo8() nounwind {
165 ; TO: ret i8* inttoptr (i64 -1 to i8*)
167 ; TO: define i1* @hoo1() nounwind {
168 ; TO: ret i1* inttoptr (i64 -1 to i1*)
170 ; SCEV: Classifying expressions for: @goo8
171 ; SCEV: %t = bitcast i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1) to i8*
172 ; SCEV: --> ((-1 * sizeof(i8)) + inttoptr (i32 1 to i8*))
173 ; SCEV: Classifying expressions for: @goo1
174 ; SCEV: %t = bitcast i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1) to i1*
175 ; SCEV: --> ((-1 * sizeof(i1)) + inttoptr (i32 1 to i1*))
176 ; SCEV: Classifying expressions for: @foo8
177 ; SCEV: %t = bitcast i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2) to i8*
178 ; SCEV: --> ((-2 * sizeof(i8)) + inttoptr (i32 1 to i8*))
179 ; SCEV: Classifying expressions for: @foo1
180 ; SCEV: %t = bitcast i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2) to i1*
181 ; SCEV: --> ((-2 * sizeof(i1)) + inttoptr (i32 1 to i1*))
182 ; SCEV: Classifying expressions for: @hoo8
183 ; SCEV: --> (-1 * sizeof(i8))
184 ; SCEV: Classifying expressions for: @hoo1
185 ; SCEV: --> (-1 * sizeof(i1))
187 define i8* @goo8() nounwind {
188 %t = bitcast i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1) to i8*
191 define i1* @goo1() nounwind {
192 %t = bitcast i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1) to i1*
195 define i8* @foo8() nounwind {
196 %t = bitcast i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2) to i8*
199 define i1* @foo1() nounwind {
200 %t = bitcast i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2) to i1*
203 define i8* @hoo8() nounwind {
204 %t = bitcast i8* getelementptr (i8* inttoptr (i32 0 to i8*), i32 -1) to i8*
207 define i1* @hoo1() nounwind {
208 %t = bitcast i1* getelementptr (i1* inttoptr (i32 0 to i1*), i32 -1) to i1*
212 ; PLAIN: define i64 @fa() nounwind {
213 ; PLAIN: %t = bitcast i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2310) to i64
216 ; PLAIN: define i64 @fb() nounwind {
217 ; PLAIN: %t = bitcast i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64) to i64
220 ; PLAIN: define i64 @fc() nounwind {
221 ; PLAIN: %t = bitcast i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2) to i64
224 ; PLAIN: define i64 @fd() nounwind {
225 ; PLAIN: %t = bitcast i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 11) to i64
228 ; PLAIN: define i64 @fe() nounwind {
229 ; PLAIN: %t = bitcast i64 ptrtoint (double* getelementptr (%1* null, i64 0, i32 2) to i64) to i64
232 ; PLAIN: define i64 @ff() nounwind {
233 ; PLAIN: %t = bitcast i64 1 to i64
236 ; PLAIN: define i64 @fg() nounwind {
237 ; PLAIN: %t = bitcast i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64)
240 ; OPT: define i64 @fa() nounwind {
241 ; OPT: ret i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2310)
243 ; OPT: define i64 @fb() nounwind {
244 ; OPT: ret i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64)
246 ; OPT: define i64 @fc() nounwind {
247 ; OPT: ret i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2)
249 ; OPT: define i64 @fd() nounwind {
250 ; OPT: ret i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 11)
252 ; OPT: define i64 @fe() nounwind {
253 ; OPT: ret i64 ptrtoint (double* getelementptr (%1* null, i64 0, i32 2) to i64)
255 ; OPT: define i64 @ff() nounwind {
258 ; OPT: define i64 @fg() nounwind {
259 ; OPT: ret i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64)
261 ; TO: define i64 @fa() nounwind {
264 ; TO: define i64 @fb() nounwind {
267 ; TO: define i64 @fc() nounwind {
270 ; TO: define i64 @fd() nounwind {
273 ; TO: define i64 @fe() nounwind {
276 ; TO: define i64 @ff() nounwind {
279 ; TO: define i64 @fg() nounwind {
282 ; SCEV: Classifying expressions for: @fa
283 ; SCEV: %t = bitcast i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2310) to i64
284 ; SCEV: --> (2310 * sizeof(double))
285 ; SCEV: Classifying expressions for: @fb
286 ; SCEV: %t = bitcast i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64) to i64
287 ; SCEV: --> alignof(double)
288 ; SCEV: Classifying expressions for: @fc
289 ; SCEV: %t = bitcast i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2) to i64
290 ; SCEV: --> (2 * sizeof(double))
291 ; SCEV: Classifying expressions for: @fd
292 ; SCEV: %t = bitcast i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 11) to i64
293 ; SCEV: --> (11 * sizeof(double))
294 ; SCEV: Classifying expressions for: @fe
295 ; SCEV: %t = bitcast i64 ptrtoint (double* getelementptr (%1* null, i64 0, i32 2) to i64) to i64
296 ; SCEV: --> offsetof({ double, float, double, double }, 2)
297 ; SCEV: Classifying expressions for: @ff
298 ; SCEV: %t = bitcast i64 1 to i64
300 ; SCEV: Classifying expressions for: @fg
301 ; SCEV: %t = bitcast i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64)
302 ; SCEV: --> alignof(double)
304 define i64 @fa() nounwind {
305 %t = bitcast i64 mul (i64 3, i64 mul (i64 ptrtoint ({[7 x double], [7 x double]}* getelementptr ({[7 x double], [7 x double]}* null, i64 11) to i64), i64 5)) to i64
308 define i64 @fb() nounwind {
309 %t = bitcast i64 ptrtoint ([13 x double]* getelementptr ({i1, [13 x double]}* null, i64 0, i32 1) to i64) to i64
312 define i64 @fc() nounwind {
313 %t = bitcast i64 ptrtoint (double* getelementptr ({double, double, double, double}* null, i64 0, i32 2) to i64) to i64
316 define i64 @fd() nounwind {
317 %t = bitcast i64 ptrtoint (double* getelementptr ([13 x double]* null, i64 0, i32 11) to i64) to i64
320 define i64 @fe() nounwind {
321 %t = bitcast i64 ptrtoint (double* getelementptr ({double, float, double, double}* null, i64 0, i32 2) to i64) to i64
324 define i64 @ff() nounwind {
325 %t = bitcast i64 ptrtoint (<{ i16, i128 }>* getelementptr ({i1, <{ i16, i128 }>}* null, i64 0, i32 1) to i64) to i64
328 define i64 @fg() nounwind {
329 %t = bitcast i64 ptrtoint ({double, double}* getelementptr ({i1, {double, double}}* null, i64 0, i32 1) to i64) to i64
333 ; PLAIN: define i64* @fM() nounwind {
334 ; PLAIN: %t = bitcast i64* getelementptr (i64* null, i32 1) to i64*
337 ; PLAIN: define i64* @fN() nounwind {
338 ; PLAIN: %t = bitcast i64* getelementptr (%2* null, i32 0, i32 1) to i64*
341 ; PLAIN: define i64* @fO() nounwind {
342 ; PLAIN: %t = bitcast i64* getelementptr ([2 x i64]* null, i32 0, i32 1) to i64*
345 ; OPT: define i64* @fM() nounwind {
346 ; OPT: ret i64* getelementptr (i64* null, i32 1)
348 ; OPT: define i64* @fN() nounwind {
349 ; OPT: ret i64* getelementptr (%2* null, i32 0, i32 1)
351 ; OPT: define i64* @fO() nounwind {
352 ; OPT: ret i64* getelementptr ([2 x i64]* null, i32 0, i32 1)
354 ; TO: define i64* @fM() nounwind {
355 ; TO: ret i64* inttoptr (i64 8 to i64*)
357 ; TO: define i64* @fN() nounwind {
358 ; TO: ret i64* inttoptr (i64 8 to i64*)
360 ; TO: define i64* @fO() nounwind {
361 ; TO: ret i64* inttoptr (i64 8 to i64*)
363 ; SCEV: Classifying expressions for: @fM
364 ; SCEV: %t = bitcast i64* getelementptr (i64* null, i32 1) to i64*
365 ; SCEV: --> sizeof(i64)
366 ; SCEV: Classifying expressions for: @fN
367 ; SCEV: %t = bitcast i64* getelementptr (%2* null, i32 0, i32 1) to i64*
368 ; SCEV: --> sizeof(i64)
369 ; SCEV: Classifying expressions for: @fO
370 ; SCEV: %t = bitcast i64* getelementptr ([2 x i64]* null, i32 0, i32 1) to i64*
371 ; SCEV: --> sizeof(i64)
373 define i64* @fM() nounwind {
374 %t = bitcast i64* getelementptr (i64 *null, i32 1) to i64*
377 define i64* @fN() nounwind {
378 %t = bitcast i64* getelementptr ({ i64, i64 } *null, i32 0, i32 1) to i64*
381 define i64* @fO() nounwind {
382 %t = bitcast i64* getelementptr ([2 x i64] *null, i32 0, i32 1) to i64*