Fix test.
[oota-llvm.git] / test / Other / constant-fold-gep.ll
1 ; "PLAIN" - No optimizations. This tests the target-independent
2 ; constant folder.
3 ; RUN: opt -S -o - < %s | FileCheck --check-prefix=PLAIN %s
4
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
8
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
12
13 ; "SCEV" - ScalarEvolution but no targetdata.
14 ; RUN: opt -analyze -scalar-evolution < %s | FileCheck --check-prefix=SCEV %s
15
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.
19
20 ; PLAIN: %0 = type { i1, double }
21 ; PLAIN: %1 = type { double, float, double, double }
22 ; PLAIN: %2 = type { i1, i1* }
23 ; PLAIN: %3 = type { i64, i64 }
24 ; PLAIN: %4 = type { i32, i32 }
25 ; OPT: %0 = type { i1, double }
26 ; OPT: %1 = type { double, float, double, double }
27 ; OPT: %2 = type { i1, i1* }
28 ; OPT: %3 = type { i64, i64 }
29 ; OPT: %4 = type { i32, i32 }
30
31 ; The automatic constant folder in opt does not have targetdata access, so
32 ; it can't fold gep arithmetic, in general. However, the constant folder run
33 ; from instcombine and global opt can use targetdata.
34
35 ; PLAIN: @G8 = global i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1)
36 ; PLAIN: @G1 = global i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1)
37 ; PLAIN: @F8 = global i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2)
38 ; PLAIN: @F1 = global i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2)
39 ; PLAIN: @H8 = global i8* getelementptr (i8* null, i32 -1)
40 ; PLAIN: @H1 = global i1* getelementptr (i1* null, i32 -1)
41 ; OPT: @G8 = global i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1)
42 ; OPT: @G1 = global i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1)
43 ; OPT: @F8 = global i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2)
44 ; OPT: @F1 = global i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2)
45 ; OPT: @H8 = global i8* getelementptr (i8* null, i32 -1)
46 ; OPT: @H1 = global i1* getelementptr (i1* null, i32 -1)
47 ; TO: @G8 = global i8* null
48 ; TO: @G1 = global i1* null
49 ; TO: @F8 = global i8* inttoptr (i64 -1 to i8*)
50 ; TO: @F1 = global i1* inttoptr (i64 -1 to i1*)
51 ; TO: @H8 = global i8* inttoptr (i64 -1 to i8*)
52 ; TO: @H1 = global i1* inttoptr (i64 -1 to i1*)
53
54 @G8 = global i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1)
55 @G1 = global i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1)
56 @F8 = global i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2)
57 @F1 = global i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2)
58 @H8 = global i8* getelementptr (i8* inttoptr (i32 0 to i8*), i32 -1)
59 @H1 = global i1* getelementptr (i1* inttoptr (i32 0 to i1*), i32 -1)
60
61 ; The target-independent folder should be able to do some clever
62 ; simplifications on sizeof, alignof, and offsetof expressions. The
63 ; target-dependent folder should fold these down to constants.
64
65 ; PLAIN: @a = constant i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2310)
66 ; PLAIN: @b = constant i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64)
67 ; PLAIN: @c = constant i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2)
68 ; PLAIN: @d = constant i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 11)
69 ; PLAIN: @e = constant i64 ptrtoint (double* getelementptr (%1* null, i64 0, i32 2) to i64)
70 ; PLAIN: @f = constant i64 1
71 ; PLAIN: @g = constant i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64)
72 ; PLAIN: @h = constant i64 ptrtoint (i1** getelementptr (i1** null, i32 1) to i64)
73 ; PLAIN: @i = constant i64 ptrtoint (i1** getelementptr (%2* null, i64 0, i32 1) to i64)
74 ; OPT: @a = constant i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2310)
75 ; OPT: @b = constant i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64)
76 ; OPT: @c = constant i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2)
77 ; OPT: @d = constant i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 11)
78 ; OPT: @e = constant i64 ptrtoint (double* getelementptr (%1* null, i64 0, i32 2) to i64)
79 ; OPT: @f = constant i64 1
80 ; OPT: @g = constant i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64)
81 ; OPT: @h = constant i64 ptrtoint (i1** getelementptr (i1** null, i32 1) to i64)
82 ; OPT: @i = constant i64 ptrtoint (i1** getelementptr (%2* null, i64 0, i32 1) to i64)
83 ; TO: @a = constant i64 18480
84 ; TO: @b = constant i64 8
85 ; TO: @c = constant i64 16
86 ; TO: @d = constant i64 88
87 ; TO: @e = constant i64 16
88 ; TO: @f = constant i64 1
89 ; TO: @g = constant i64 8
90 ; TO: @h = constant i64 8
91 ; TO: @i = constant i64 8
92
93 @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))
94 @b = constant i64 ptrtoint ([13 x double]* getelementptr ({i1, [13 x double]}* null, i64 0, i32 1) to i64)
95 @c = constant i64 ptrtoint (double* getelementptr ({double, double, double, double}* null, i64 0, i32 2) to i64)
96 @d = constant i64 ptrtoint (double* getelementptr ([13 x double]* null, i64 0, i32 11) to i64)
97 @e = constant i64 ptrtoint (double* getelementptr ({double, float, double, double}* null, i64 0, i32 2) to i64)
98 @f = constant i64 ptrtoint (<{ i16, i128 }>* getelementptr ({i1, <{ i16, i128 }>}* null, i64 0, i32 1) to i64)
99 @g = constant i64 ptrtoint ({double, double}* getelementptr ({i1, {double, double}}* null, i64 0, i32 1) to i64)
100 @h = constant i64 ptrtoint (double** getelementptr (double** null, i64 1) to i64)
101 @i = constant i64 ptrtoint (double** getelementptr ({i1, double*}* null, i64 0, i32 1) to i64)
102
103 ; The target-dependent folder should cast GEP indices to integer-sized pointers.
104
105 ; PLAIN: @M = constant i64* getelementptr (i64* null, i32 1)
106 ; PLAIN: @N = constant i64* getelementptr (%3* null, i32 0, i32 1)
107 ; PLAIN: @O = constant i64* getelementptr ([2 x i64]* null, i32 0, i32 1)
108 ; OPT: @M = constant i64* getelementptr (i64* null, i32 1)
109 ; OPT: @N = constant i64* getelementptr (%3* null, i32 0, i32 1)
110 ; OPT: @O = constant i64* getelementptr ([2 x i64]* null, i32 0, i32 1)
111 ; TO: @M = constant i64* inttoptr (i64 8 to i64*)
112 ; TO: @N = constant i64* inttoptr (i64 8 to i64*)
113 ; TO: @O = constant i64* inttoptr (i64 8 to i64*)
114
115 @M = constant i64* getelementptr (i64* null, i32 1)
116 @N = constant i64* getelementptr ({ i64, i64 }* null, i32 0, i32 1)
117 @O = constant i64* getelementptr ([2 x i64]* null, i32 0, i32 1)
118
119 ; Fold GEP of a GEP. Theoretically some of these cases could be folded
120 ; without using targetdata, however that's not implemented yet.
121
122 ; PLAIN: @Z = global i32* getelementptr inbounds (i32* getelementptr inbounds ([3 x %4]* @ext, i64 0, i64 1, i32 0), i64 1)
123 ; OPT: @Z = global i32* getelementptr (i32* getelementptr inbounds ([3 x %4]* @ext, i64 0, i64 1, i32 0), i64 1)
124 ; TO: @Z = global i32* getelementptr inbounds ([3 x %0]* @ext, i64 0, i64 1, i32 1)
125
126 @ext = external global [3 x { i32, i32 }]
127 @Z = global i32* getelementptr inbounds (i32* getelementptr inbounds ([3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1)
128
129 ; Duplicate all of the above as function return values rather than
130 ; global initializers.
131
132 ; PLAIN: define i8* @goo8() nounwind {
133 ; PLAIN:   %t = bitcast i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1) to i8*
134 ; PLAIN:   ret i8* %t
135 ; PLAIN: }
136 ; PLAIN: define i1* @goo1() nounwind {
137 ; PLAIN:   %t = bitcast i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1) to i1*
138 ; PLAIN:   ret i1* %t
139 ; PLAIN: }
140 ; PLAIN: define i8* @foo8() nounwind {
141 ; PLAIN:   %t = bitcast i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2) to i8*
142 ; PLAIN:   ret i8* %t
143 ; PLAIN: }
144 ; PLAIN: define i1* @foo1() nounwind {
145 ; PLAIN:   %t = bitcast i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2) to i1*
146 ; PLAIN:   ret i1* %t
147 ; PLAIN: }
148 ; PLAIN: define i8* @hoo8() nounwind {
149 ; PLAIN:   %t = bitcast i8* getelementptr (i8* null, i32 -1) to i8*
150 ; PLAIN:   ret i8* %t
151 ; PLAIN: }
152 ; PLAIN: define i1* @hoo1() nounwind {
153 ; PLAIN:   %t = bitcast i1* getelementptr (i1* null, i32 -1) to i1*
154 ; PLAIN:   ret i1* %t
155 ; PLAIN: }
156 ; OPT: define i8* @goo8() nounwind {
157 ; OPT:   ret i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1)
158 ; OPT: }
159 ; OPT: define i1* @goo1() nounwind {
160 ; OPT:   ret i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1)
161 ; OPT: }
162 ; OPT: define i8* @foo8() nounwind {
163 ; OPT:   ret i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2)
164 ; OPT: }
165 ; OPT: define i1* @foo1() nounwind {
166 ; OPT:   ret i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2)
167 ; OPT: }
168 ; OPT: define i8* @hoo8() nounwind {
169 ; OPT:   ret i8* getelementptr (i8* null, i32 -1)
170 ; OPT: }
171 ; OPT: define i1* @hoo1() nounwind {
172 ; OPT:   ret i1* getelementptr (i1* null, i32 -1)
173 ; OPT: }
174 ; TO: define i8* @goo8() nounwind {
175 ; TO:   ret i8* null
176 ; TO: }
177 ; TO: define i1* @goo1() nounwind {
178 ; TO:   ret i1* null
179 ; TO: }
180 ; TO: define i8* @foo8() nounwind {
181 ; TO:   ret i8* inttoptr (i64 -1 to i8*)
182 ; TO: }
183 ; TO: define i1* @foo1() nounwind {
184 ; TO:   ret i1* inttoptr (i64 -1 to i1*)
185 ; TO: }
186 ; TO: define i8* @hoo8() nounwind {
187 ; TO:   ret i8* inttoptr (i64 -1 to i8*)
188 ; TO: }
189 ; TO: define i1* @hoo1() nounwind {
190 ; TO:   ret i1* inttoptr (i64 -1 to i1*)
191 ; TO: }
192 ; SCEV: Classifying expressions for: @goo8
193 ; SCEV:   %t = bitcast i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1) to i8*
194 ; SCEV:   -->  ((-1 * sizeof(i8)) + inttoptr (i32 1 to i8*))
195 ; SCEV: Classifying expressions for: @goo1
196 ; SCEV:   %t = bitcast i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1) to i1*
197 ; SCEV:   -->  ((-1 * sizeof(i1)) + inttoptr (i32 1 to i1*))
198 ; SCEV: Classifying expressions for: @foo8
199 ; SCEV:   %t = bitcast i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2) to i8*
200 ; SCEV:   -->  ((-2 * sizeof(i8)) + inttoptr (i32 1 to i8*))
201 ; SCEV: Classifying expressions for: @foo1
202 ; SCEV:   %t = bitcast i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2) to i1*
203 ; SCEV:   -->  ((-2 * sizeof(i1)) + inttoptr (i32 1 to i1*))
204 ; SCEV: Classifying expressions for: @hoo8
205 ; SCEV:   -->  (-1 * sizeof(i8))
206 ; SCEV: Classifying expressions for: @hoo1
207 ; SCEV:   -->  (-1 * sizeof(i1))
208
209 define i8* @goo8() nounwind {
210   %t = bitcast i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -1) to i8*
211   ret i8* %t
212 }
213 define i1* @goo1() nounwind {
214   %t = bitcast i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -1) to i1*
215   ret i1* %t
216 }
217 define i8* @foo8() nounwind {
218   %t = bitcast i8* getelementptr (i8* inttoptr (i32 1 to i8*), i32 -2) to i8*
219   ret i8* %t
220 }
221 define i1* @foo1() nounwind {
222   %t = bitcast i1* getelementptr (i1* inttoptr (i32 1 to i1*), i32 -2) to i1*
223   ret i1* %t
224 }
225 define i8* @hoo8() nounwind {
226   %t = bitcast i8* getelementptr (i8* inttoptr (i32 0 to i8*), i32 -1) to i8*
227   ret i8* %t
228 }
229 define i1* @hoo1() nounwind {
230   %t = bitcast i1* getelementptr (i1* inttoptr (i32 0 to i1*), i32 -1) to i1*
231   ret i1* %t
232 }
233
234 ; PLAIN: define i64 @fa() nounwind {
235 ; PLAIN:   %t = bitcast i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2310) to i64
236 ; PLAIN:   ret i64 %t
237 ; PLAIN: }
238 ; PLAIN: define i64 @fb() nounwind {
239 ; PLAIN:   %t = bitcast i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64) to i64
240 ; PLAIN:   ret i64 %t
241 ; PLAIN: }
242 ; PLAIN: define i64 @fc() nounwind {
243 ; PLAIN:   %t = bitcast i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2) to i64
244 ; PLAIN:   ret i64 %t
245 ; PLAIN: }
246 ; PLAIN: define i64 @fd() nounwind {
247 ; PLAIN:   %t = bitcast i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 11) to i64
248 ; PLAIN:   ret i64 %t
249 ; PLAIN: }
250 ; PLAIN: define i64 @fe() nounwind {
251 ; PLAIN:   %t = bitcast i64 ptrtoint (double* getelementptr (%1* null, i64 0, i32 2) to i64) to i64
252 ; PLAIN:   ret i64 %t
253 ; PLAIN: }
254 ; PLAIN: define i64 @ff() nounwind {
255 ; PLAIN:   %t = bitcast i64 1 to i64
256 ; PLAIN:   ret i64 %t
257 ; PLAIN: }
258 ; PLAIN: define i64 @fg() nounwind {
259 ; PLAIN:   %t = bitcast i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64) to i64
260 ; PLAIN:   ret i64 %t
261 ; PLAIN: }
262 ; PLAIN: define i64 @fh() nounwind {
263 ; PLAIN:   %t = bitcast i64 ptrtoint (i1** getelementptr (i1** null, i32 1) to i64) to i64
264 ; PLAIN:   ret i64 %t
265 ; PLAIN: }
266 ; PLAIN: define i64 @fi() nounwind {
267 ; PLAIN:   %t = bitcast i64 ptrtoint (i1** getelementptr (%2* null, i64 0, i32 1) to i64) to i64
268 ; PLAIN:   ret i64 %t
269 ; PLAIN: }
270 ; OPT: define i64 @fa() nounwind {
271 ; OPT:   ret i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2310)
272 ; OPT: }
273 ; OPT: define i64 @fb() nounwind {
274 ; OPT:   ret i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64)
275 ; OPT: }
276 ; OPT: define i64 @fc() nounwind {
277 ; OPT:   ret i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2)
278 ; OPT: }
279 ; OPT: define i64 @fd() nounwind {
280 ; OPT:   ret i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 11)
281 ; OPT: }
282 ; OPT: define i64 @fe() nounwind {
283 ; OPT:   ret i64 ptrtoint (double* getelementptr (%1* null, i64 0, i32 2) to i64)
284 ; OPT: }
285 ; OPT: define i64 @ff() nounwind {
286 ; OPT:   ret i64 1
287 ; OPT: }
288 ; OPT: define i64 @fg() nounwind {
289 ; OPT:   ret i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64)
290 ; OPT: }
291 ; OPT: define i64 @fh() nounwind {
292 ; OPT:   ret i64 ptrtoint (i1** getelementptr (i1** null, i32 1) to i64)
293 ; OPT: }
294 ; OPT: define i64 @fi() nounwind {
295 ; OPT:   ret i64 ptrtoint (i1** getelementptr (%2* null, i64 0, i32 1) to i64)
296 ; OPT: }
297 ; TO: define i64 @fa() nounwind {
298 ; TO:   ret i64 18480
299 ; TO: }
300 ; TO: define i64 @fb() nounwind {
301 ; TO:   ret i64 8
302 ; TO: }
303 ; TO: define i64 @fc() nounwind {
304 ; TO:   ret i64 16
305 ; TO: }
306 ; TO: define i64 @fd() nounwind {
307 ; TO:   ret i64 88
308 ; TO: }
309 ; TO: define i64 @fe() nounwind {
310 ; TO:   ret i64 16
311 ; TO: }
312 ; TO: define i64 @ff() nounwind {
313 ; TO:   ret i64 1
314 ; TO: }
315 ; TO: define i64 @fg() nounwind {
316 ; TO:   ret i64 8
317 ; TO: }
318 ; TO: define i64 @fh() nounwind {
319 ; TO:   ret i64 8
320 ; TO: }
321 ; TO: define i64 @fi() nounwind {
322 ; TO:   ret i64 8
323 ; TO: }
324 ; SCEV: Classifying expressions for: @fa
325 ; SCEV:   %t = bitcast i64 mul (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2310) to i64 
326 ; SCEV:   -->  (2310 * sizeof(double))
327 ; SCEV: Classifying expressions for: @fb
328 ; SCEV:   %t = bitcast i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64) to i64 
329 ; SCEV:   -->  alignof(double)
330 ; SCEV: Classifying expressions for: @fc
331 ; SCEV:   %t = bitcast i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 2) to i64 
332 ; SCEV:   -->  (2 * sizeof(double))
333 ; SCEV: Classifying expressions for: @fd
334 ; SCEV:   %t = bitcast i64 mul nuw (i64 ptrtoint (double* getelementptr (double* null, i32 1) to i64), i64 11) to i64 
335 ; SCEV:   -->  (11 * sizeof(double))
336 ; SCEV: Classifying expressions for: @fe
337 ; SCEV:   %t = bitcast i64 ptrtoint (double* getelementptr (%1* null, i64 0, i32 2) to i64) to i64 
338 ; SCEV:   -->  offsetof({ double, float, double, double }, 2)
339 ; SCEV: Classifying expressions for: @ff
340 ; SCEV:   %t = bitcast i64 1 to i64 
341 ; SCEV:   -->  1
342 ; SCEV: Classifying expressions for: @fg
343 ; SCEV:   %t = bitcast i64 ptrtoint (double* getelementptr (%0* null, i64 0, i32 1) to i64) to i64
344 ; SCEV:   -->  alignof(double)
345 ; SCEV: Classifying expressions for: @fh
346 ; SCEV:   %t = bitcast i64 ptrtoint (i1** getelementptr (i1** null, i32 1) to i64) to i64
347 ; SCEV:   -->  sizeof(i1*)
348 ; SCEV: Classifying expressions for: @fi
349 ; SCEV:   %t = bitcast i64 ptrtoint (i1** getelementptr (%2* null, i64 0, i32 1) to i64) to i64
350 ; SCEV:   -->  alignof(i1*)
351
352 define i64 @fa() nounwind {
353   %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
354   ret i64 %t
355 }
356 define i64 @fb() nounwind {
357   %t = bitcast i64 ptrtoint ([13 x double]* getelementptr ({i1, [13 x double]}* null, i64 0, i32 1) to i64) to i64
358   ret i64 %t
359 }
360 define i64 @fc() nounwind {
361   %t = bitcast i64 ptrtoint (double* getelementptr ({double, double, double, double}* null, i64 0, i32 2) to i64) to i64
362   ret i64 %t
363 }
364 define i64 @fd() nounwind {
365   %t = bitcast i64 ptrtoint (double* getelementptr ([13 x double]* null, i64 0, i32 11) to i64) to i64
366   ret i64 %t
367 }
368 define i64 @fe() nounwind {
369   %t = bitcast i64 ptrtoint (double* getelementptr ({double, float, double, double}* null, i64 0, i32 2) to i64) to i64
370   ret i64 %t
371 }
372 define i64 @ff() nounwind {
373   %t = bitcast i64 ptrtoint (<{ i16, i128 }>* getelementptr ({i1, <{ i16, i128 }>}* null, i64 0, i32 1) to i64) to i64
374   ret i64 %t
375 }
376 define i64 @fg() nounwind {
377   %t = bitcast i64 ptrtoint ({double, double}* getelementptr ({i1, {double, double}}* null, i64 0, i32 1) to i64) to i64
378   ret i64 %t
379 }
380 define i64 @fh() nounwind {
381   %t = bitcast i64 ptrtoint (double** getelementptr (double** null, i32 1) to i64) to i64
382   ret i64 %t
383 }
384 define i64 @fi() nounwind {
385   %t = bitcast i64 ptrtoint (double** getelementptr ({i1, double*}* null, i64 0, i32 1) to i64) to i64
386   ret i64 %t
387 }
388
389 ; PLAIN: define i64* @fM() nounwind {
390 ; PLAIN:   %t = bitcast i64* getelementptr (i64* null, i32 1) to i64*
391 ; PLAIN:   ret i64* %t
392 ; PLAIN: }
393 ; PLAIN: define i64* @fN() nounwind {
394 ; PLAIN:   %t = bitcast i64* getelementptr (%3* null, i32 0, i32 1) to i64*
395 ; PLAIN:   ret i64* %t
396 ; PLAIN: }
397 ; PLAIN: define i64* @fO() nounwind {
398 ; PLAIN:   %t = bitcast i64* getelementptr ([2 x i64]* null, i32 0, i32 1) to i64*
399 ; PLAIN:   ret i64* %t
400 ; PLAIN: }
401 ; OPT: define i64* @fM() nounwind {
402 ; OPT:   ret i64* getelementptr (i64* null, i32 1)
403 ; OPT: }
404 ; OPT: define i64* @fN() nounwind {
405 ; OPT:   ret i64* getelementptr (%3* null, i32 0, i32 1)
406 ; OPT: }
407 ; OPT: define i64* @fO() nounwind {
408 ; OPT:   ret i64* getelementptr ([2 x i64]* null, i32 0, i32 1)
409 ; OPT: }
410 ; TO: define i64* @fM() nounwind {
411 ; TO:   ret i64* inttoptr (i64 8 to i64*)
412 ; TO: }
413 ; TO: define i64* @fN() nounwind {
414 ; TO:   ret i64* inttoptr (i64 8 to i64*)
415 ; TO: }
416 ; TO: define i64* @fO() nounwind {
417 ; TO:   ret i64* inttoptr (i64 8 to i64*)
418 ; TO: }
419 ; SCEV: Classifying expressions for: @fM
420 ; SCEV:   %t = bitcast i64* getelementptr (i64* null, i32 1) to i64* 
421 ; SCEV:   -->  sizeof(i64)
422 ; SCEV: Classifying expressions for: @fN
423 ; SCEV:   %t = bitcast i64* getelementptr (%3* null, i32 0, i32 1) to i64* 
424 ; SCEV:   -->  sizeof(i64)
425 ; SCEV: Classifying expressions for: @fO
426 ; SCEV:   %t = bitcast i64* getelementptr ([2 x i64]* null, i32 0, i32 1) to i64* 
427 ; SCEV:   -->  sizeof(i64)
428
429 define i64* @fM() nounwind {
430   %t = bitcast i64* getelementptr (i64* null, i32 1) to i64*
431   ret i64* %t
432 }
433 define i64* @fN() nounwind {
434   %t = bitcast i64* getelementptr ({ i64, i64 }* null, i32 0, i32 1) to i64*
435   ret i64* %t
436 }
437 define i64* @fO() nounwind {
438   %t = bitcast i64* getelementptr ([2 x i64]* null, i32 0, i32 1) to i64*
439   ret i64* %t
440 }
441
442 ; PLAIN: define i32* @fZ() nounwind {
443 ; PLAIN:   %t = bitcast i32* getelementptr inbounds (i32* getelementptr inbounds ([3 x %4]* @ext, i64 0, i64 1, i32 0), i64 1) to i32*
444 ; PLAIN:   ret i32* %t
445 ; PLAIN: }
446 ; OPT: define i32* @fZ() nounwind {
447 ; OPT:   ret i32* getelementptr inbounds (i32* getelementptr inbounds ([3 x %4]* @ext, i64 0, i64 1, i32 0), i64 1)
448 ; OPT: }
449 ; TO: define i32* @fZ() nounwind {
450 ; TO:   ret i32* getelementptr inbounds ([3 x %0]* @ext, i64 0, i64 1, i32 1)
451 ; TO: }
452 ; SCEV: Classifying expressions for: @fZ
453 ; SCEV:   %t = bitcast i32* getelementptr inbounds (i32* getelementptr inbounds ([3 x %4]* @ext, i64 0, i64 1, i32 0), i64 1) to i32*
454 ; SCEV:   -->  ((3 * sizeof(i32)) + @ext)
455
456 define i32* @fZ() nounwind {
457   %t = bitcast i32* getelementptr inbounds (i32* getelementptr inbounds ([3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1) to i32*
458   ret i32* %t
459 }