1 ; "PLAIN" - No optimizations. This tests the default target layout
3 ; RUN: opt -S -o - < %s | FileCheck --check-prefix=PLAIN %s
5 ; "OPT" - Optimizations but no targetdata. This tests default target layout
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 -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 with default target layout
14 ; RUN: opt -analyze -scalar-evolution < %s -enable-new-pm=0 | FileCheck --check-prefix=SCEV %s
15 ; RUN: opt -passes='print<scalar-evolution>' < %s -disable-output 2>&1 | FileCheck --check-prefix=SCEV %s
18 ; The automatic constant folder in opt does not have targetdata access, so
19 ; it can't fold gep arithmetic, in general. However, the constant folder run
20 ; from instcombine and global opt can use targetdata.
22 ; PLAIN: @G8 = global i8* getelementptr (i8, i8* inttoptr (i32 1 to i8*), i32 -1)
23 ; PLAIN: @G1 = global i1* getelementptr (i1, i1* inttoptr (i32 1 to i1*), i32 -1)
24 ; PLAIN: @F8 = global i8* getelementptr (i8, i8* inttoptr (i32 1 to i8*), i32 -2)
25 ; PLAIN: @F1 = global i1* getelementptr (i1, i1* inttoptr (i32 1 to i1*), i32 -2)
26 ; PLAIN: @H8 = global i8* getelementptr (i8, i8* null, i32 -1)
27 ; PLAIN: @H1 = global i1* getelementptr (i1, i1* null, i32 -1)
28 ; OPT: @G8 = local_unnamed_addr global i8* null
29 ; OPT: @G1 = local_unnamed_addr global i1* null
30 ; OPT: @F8 = local_unnamed_addr global i8* inttoptr (i64 -1 to i8*)
31 ; OPT: @F1 = local_unnamed_addr global i1* inttoptr (i64 -1 to i1*)
32 ; OPT: @H8 = local_unnamed_addr global i8* inttoptr (i64 -1 to i8*)
33 ; OPT: @H1 = local_unnamed_addr global i1* inttoptr (i64 -1 to i1*)
34 ; TO: @G8 = local_unnamed_addr global i8* null
35 ; TO: @G1 = local_unnamed_addr global i1* null
36 ; TO: @F8 = local_unnamed_addr global i8* inttoptr (i64 -1 to i8*)
37 ; TO: @F1 = local_unnamed_addr global i1* inttoptr (i64 -1 to i1*)
38 ; TO: @H8 = local_unnamed_addr global i8* inttoptr (i64 -1 to i8*)
39 ; TO: @H1 = local_unnamed_addr global i1* inttoptr (i64 -1 to i1*)
41 @G8 = global i8* getelementptr (i8, i8* inttoptr (i32 1 to i8*), i32 -1)
42 @G1 = global i1* getelementptr (i1, i1* inttoptr (i32 1 to i1*), i32 -1)
43 @F8 = global i8* getelementptr (i8, i8* inttoptr (i32 1 to i8*), i32 -2)
44 @F1 = global i1* getelementptr (i1, i1* inttoptr (i32 1 to i1*), i32 -2)
45 @H8 = global i8* getelementptr (i8, i8* inttoptr (i32 0 to i8*), i32 -1)
46 @H1 = global i1* getelementptr (i1, i1* inttoptr (i32 0 to i1*), i32 -1)
48 ; The target-independent folder should be able to do some clever
49 ; simplifications on sizeof, alignof, and offsetof expressions. The
50 ; target-dependent folder should fold these down to constants.
52 ; PLAIN: @a = constant i64 mul (i64 ptrtoint ({ [7 x double], [7 x double] }* getelementptr ({ [7 x double], [7 x double] }, { [7 x double], [7 x double] }* null, i64 11) to i64), i64 15)
53 ; PLAIN: @b = constant i64 ptrtoint ([13 x double]* getelementptr ({ i1, [13 x double] }, { i1, [13 x double] }* null, i64 0, i32 1) to i64)
54 ; PLAIN: @c = constant i64 ptrtoint (double* getelementptr ({ double, double, double, double }, { double, double, double, double }* null, i64 0, i32 2) to i64)
55 ; PLAIN: @d = constant i64 ptrtoint (double* getelementptr ([13 x double], [13 x double]* null, i64 0, i32 11) to i64)
56 ; PLAIN: @e = constant i64 ptrtoint (double* getelementptr ({ double, float, double, double }, { double, float, double, double }* null, i64 0, i32 2) to i64)
57 ; PLAIN: @f = constant i64 ptrtoint (<{ i16, i128 }>* getelementptr ({ i1, <{ i16, i128 }> }, { i1, <{ i16, i128 }> }* null, i64 0, i32 1) to i64)
58 ; PLAIN: @g = constant i64 ptrtoint ({ double, double }* getelementptr ({ i1, { double, double } }, { i1, { double, double } }* null, i64 0, i32 1) to i64)
59 ; PLAIN: @h = constant i64 ptrtoint (double** getelementptr (double*, double** null, i64 1) to i64)
60 ; PLAIN: @i = constant i64 ptrtoint (double** getelementptr ({ i1, double* }, { i1, double* }* null, i64 0, i32 1) to i64)
61 ; OPT: @a = local_unnamed_addr constant i64 18480
62 ; OPT: @b = local_unnamed_addr constant i64 8
63 ; OPT: @c = local_unnamed_addr constant i64 16
64 ; OPT: @d = local_unnamed_addr constant i64 88
65 ; OPT: @e = local_unnamed_addr constant i64 16
66 ; OPT: @f = local_unnamed_addr constant i64 1
67 ; OPT: @g = local_unnamed_addr constant i64 8
68 ; OPT: @h = local_unnamed_addr constant i64 8
69 ; OPT: @i = local_unnamed_addr constant i64 8
70 ; TO: @a = local_unnamed_addr constant i64 18480
71 ; TO: @b = local_unnamed_addr constant i64 8
72 ; TO: @c = local_unnamed_addr constant i64 16
73 ; TO: @d = local_unnamed_addr constant i64 88
74 ; TO: @e = local_unnamed_addr constant i64 16
75 ; TO: @f = local_unnamed_addr constant i64 1
76 ; TO: @g = local_unnamed_addr constant i64 8
77 ; TO: @h = local_unnamed_addr constant i64 8
78 ; TO: @i = local_unnamed_addr constant i64 8
80 @a = constant i64 mul (i64 3, i64 mul (i64 ptrtoint ({[7 x double], [7 x double]}* getelementptr ({[7 x double], [7 x double]}, {[7 x double], [7 x double]}* null, i64 11) to i64), i64 5))
81 @b = constant i64 ptrtoint ([13 x double]* getelementptr ({i1, [13 x double]}, {i1, [13 x double]}* null, i64 0, i32 1) to i64)
82 @c = constant i64 ptrtoint (double* getelementptr ({double, double, double, double}, {double, double, double, double}* null, i64 0, i32 2) to i64)
83 @d = constant i64 ptrtoint (double* getelementptr ([13 x double], [13 x double]* null, i64 0, i32 11) to i64)
84 @e = constant i64 ptrtoint (double* getelementptr ({double, float, double, double}, {double, float, double, double}* null, i64 0, i32 2) to i64)
85 @f = constant i64 ptrtoint (<{ i16, i128 }>* getelementptr ({i1, <{ i16, i128 }>}, {i1, <{ i16, i128 }>}* null, i64 0, i32 1) to i64)
86 @g = constant i64 ptrtoint ({double, double}* getelementptr ({i1, {double, double}}, {i1, {double, double}}* null, i64 0, i32 1) to i64)
87 @h = constant i64 ptrtoint (double** getelementptr (double*, double** null, i64 1) to i64)
88 @i = constant i64 ptrtoint (double** getelementptr ({i1, double*}, {i1, double*}* null, i64 0, i32 1) to i64)
90 ; The target-dependent folder should cast GEP indices to integer-sized pointers.
92 ; PLAIN: @M = constant i64* getelementptr (i64, i64* null, i32 1)
93 ; PLAIN: @N = constant i64* getelementptr ({ i64, i64 }, { i64, i64 }* null, i32 0, i32 1)
94 ; PLAIN: @O = constant i64* getelementptr ([2 x i64], [2 x i64]* null, i32 0, i32 1)
95 ; OPT: @M = local_unnamed_addr constant i64* inttoptr (i64 8 to i64*)
96 ; OPT: @N = local_unnamed_addr constant i64* inttoptr (i64 8 to i64*)
97 ; OPT: @O = local_unnamed_addr constant i64* inttoptr (i64 8 to i64*)
98 ; TO: @M = local_unnamed_addr constant i64* inttoptr (i64 8 to i64*)
99 ; TO: @N = local_unnamed_addr constant i64* inttoptr (i64 8 to i64*)
100 ; TO: @O = local_unnamed_addr constant i64* inttoptr (i64 8 to i64*)
102 @M = constant i64* getelementptr (i64, i64* null, i32 1)
103 @N = constant i64* getelementptr ({ i64, i64 }, { i64, i64 }* null, i32 0, i32 1)
104 @O = constant i64* getelementptr ([2 x i64], [2 x i64]* null, i32 0, i32 1)
106 ; Fold GEP of a GEP. Very simple cases are folded without targetdata.
108 ; PLAIN: @Y = global [3 x { i32, i32 }]* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 2)
109 ; PLAIN: @Z = global i32* getelementptr inbounds (i32, i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1)
110 ; OPT: @Y = local_unnamed_addr global [3 x { i32, i32 }]* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 2)
111 ; OPT: @Z = local_unnamed_addr global i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
112 ; TO: @Y = local_unnamed_addr global [3 x { i32, i32 }]* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 2)
113 ; TO: @Z = local_unnamed_addr global i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
115 @ext = external global [3 x { i32, i32 }]
116 @Y = global [3 x { i32, i32 }]* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 1), i64 1)
117 @Z = global i32* getelementptr inbounds (i32, i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1)
119 ; Duplicate all of the above as function return values rather than
120 ; global initializers.
122 ; PLAIN: define i8* @goo8() #0 {
123 ; PLAIN: %t = bitcast i8* getelementptr (i8, i8* inttoptr (i32 1 to i8*), i32 -1) to i8*
126 ; PLAIN: define i1* @goo1() #0 {
127 ; PLAIN: %t = bitcast i1* getelementptr (i1, i1* inttoptr (i32 1 to i1*), i32 -1) to i1*
130 ; PLAIN: define i8* @foo8() #0 {
131 ; PLAIN: %t = bitcast i8* getelementptr (i8, i8* inttoptr (i32 1 to i8*), i32 -2) to i8*
134 ; PLAIN: define i1* @foo1() #0 {
135 ; PLAIN: %t = bitcast i1* getelementptr (i1, i1* inttoptr (i32 1 to i1*), i32 -2) to i1*
138 ; PLAIN: define i8* @hoo8() #0 {
139 ; PLAIN: %t = bitcast i8* getelementptr (i8, i8* null, i32 -1) to i8*
142 ; PLAIN: define i1* @hoo1() #0 {
143 ; PLAIN: %t = bitcast i1* getelementptr (i1, i1* null, i32 -1) to i1*
146 ; OPT: define i8* @goo8() local_unnamed_addr #0 {
149 ; OPT: define i1* @goo1() local_unnamed_addr #0 {
152 ; OPT: define i8* @foo8() local_unnamed_addr #0 {
153 ; OPT: ret i8* inttoptr (i64 -1 to i8*)
155 ; OPT: define i1* @foo1() local_unnamed_addr #0 {
156 ; OPT: ret i1* inttoptr (i64 -1 to i1*)
158 ; OPT: define i8* @hoo8() local_unnamed_addr #0 {
159 ; OPT: ret i8* inttoptr (i64 -1 to i8*)
161 ; OPT: define i1* @hoo1() local_unnamed_addr #0 {
162 ; OPT: ret i1* inttoptr (i64 -1 to i1*)
164 ; TO: define i8* @goo8() local_unnamed_addr #0 {
167 ; TO: define i1* @goo1() local_unnamed_addr #0 {
170 ; TO: define i8* @foo8() local_unnamed_addr #0 {
171 ; TO: ret i8* inttoptr (i64 -1 to i8*)
173 ; TO: define i1* @foo1() local_unnamed_addr #0 {
174 ; TO: ret i1* inttoptr (i64 -1 to i1*)
176 ; TO: define i8* @hoo8() local_unnamed_addr #0 {
177 ; TO: ret i8* inttoptr (i64 -1 to i8*)
179 ; TO: define i1* @hoo1() local_unnamed_addr #0 {
180 ; TO: ret i1* inttoptr (i64 -1 to i1*)
182 ; SCEV: Classifying expressions for: @goo8
183 ; SCEV: %t = bitcast i8* getelementptr (i8, i8* inttoptr (i32 1 to i8*), i32 -1) to i8*
184 ; SCEV: --> (-1 + inttoptr (i32 1 to i8*))
185 ; SCEV: Classifying expressions for: @goo1
186 ; SCEV: %t = bitcast i1* getelementptr (i1, i1* inttoptr (i32 1 to i1*), i32 -1) to i1*
187 ; SCEV: --> (-1 + inttoptr (i32 1 to i1*))
188 ; SCEV: Classifying expressions for: @foo8
189 ; SCEV: %t = bitcast i8* getelementptr (i8, i8* inttoptr (i32 1 to i8*), i32 -2) to i8*
190 ; SCEV: --> (-2 + inttoptr (i32 1 to i8*))
191 ; SCEV: Classifying expressions for: @foo1
192 ; SCEV: %t = bitcast i1* getelementptr (i1, i1* inttoptr (i32 1 to i1*), i32 -2) to i1*
193 ; SCEV: --> (-2 + inttoptr (i32 1 to i1*))
194 ; SCEV: Classifying expressions for: @hoo8
195 ; SCEV: --> (-1 + null)<nuw><nsw> U: [-1,0) S: [-1,0)
196 ; SCEV: Classifying expressions for: @hoo1
197 ; SCEV: --> (-1 + null)<nuw><nsw> U: [-1,0) S: [-1,0)
199 define i8* @goo8() nounwind {
200 %t = bitcast i8* getelementptr (i8, i8* inttoptr (i32 1 to i8*), i32 -1) to i8*
203 define i1* @goo1() nounwind {
204 %t = bitcast i1* getelementptr (i1, i1* inttoptr (i32 1 to i1*), i32 -1) to i1*
207 define i8* @foo8() nounwind {
208 %t = bitcast i8* getelementptr (i8, i8* inttoptr (i32 1 to i8*), i32 -2) to i8*
211 define i1* @foo1() nounwind {
212 %t = bitcast i1* getelementptr (i1, i1* inttoptr (i32 1 to i1*), i32 -2) to i1*
215 define i8* @hoo8() nounwind {
216 %t = bitcast i8* getelementptr (i8, i8* inttoptr (i32 0 to i8*), i32 -1) to i8*
219 define i1* @hoo1() nounwind {
220 %t = bitcast i1* getelementptr (i1, i1* inttoptr (i32 0 to i1*), i32 -1) to i1*
224 ; PLAIN: define i64 @fa() #0 {
225 ; PLAIN: %t = bitcast i64 mul (i64 ptrtoint ({ [7 x double], [7 x double] }* getelementptr ({ [7 x double], [7 x double] }, { [7 x double], [7 x double] }* null, i64 11) to i64), i64 15) to i64
228 ; PLAIN: define i64 @fb() #0 {
229 ; PLAIN: %t = bitcast i64 ptrtoint ([13 x double]* getelementptr ({ i1, [13 x double] }, { i1, [13 x double] }* null, i64 0, i32 1) to i64) to i64
232 ; PLAIN: define i64 @fc() #0 {
233 ; PLAIN: %t = bitcast i64 ptrtoint (double* getelementptr ({ double, double, double, double }, { double, double, double, double }* null, i64 0, i32 2) to i64) to i64
236 ; PLAIN: define i64 @fd() #0 {
237 ; PLAIN: %t = bitcast i64 ptrtoint (double* getelementptr ([13 x double], [13 x double]* null, i64 0, i32 11) to i64) to i64
240 ; PLAIN: define i64 @fe() #0 {
241 ; PLAIN: %t = bitcast i64 ptrtoint (double* getelementptr ({ double, float, double, double }, { double, float, double, double }* null, i64 0, i32 2) to i64) to i64
244 ; PLAIN: define i64 @ff() #0 {
245 ; PLAIN: %t = bitcast i64 ptrtoint (<{ i16, i128 }>* getelementptr ({ i1, <{ i16, i128 }> }, { i1, <{ i16, i128 }> }* null, i64 0, i32 1) to i64) to i64
248 ; PLAIN: define i64 @fg() #0 {
249 ; PLAIN: %t = bitcast i64 ptrtoint ({ double, double }* getelementptr ({ i1, { double, double } }, { i1, { double, double } }* null, i64 0, i32 1) to i64) to i64
252 ; PLAIN: define i64 @fh() #0 {
253 ; PLAIN: %t = bitcast i64 ptrtoint (double** getelementptr (double*, double** null, i32 1) to i64) to i64
256 ; PLAIN: define i64 @fi() #0 {
257 ; PLAIN: %t = bitcast i64 ptrtoint (double** getelementptr ({ i1, double* }, { i1, double* }* null, i64 0, i32 1) to i64) to i64
260 ; OPT: define i64 @fa() local_unnamed_addr #0 {
263 ; OPT: define i64 @fb() local_unnamed_addr #0 {
266 ; OPT: define i64 @fc() local_unnamed_addr #0 {
269 ; OPT: define i64 @fd() local_unnamed_addr #0 {
272 ; OPT: define i64 @fe() local_unnamed_addr #0 {
275 ; OPT: define i64 @ff() local_unnamed_addr #0 {
278 ; OPT: define i64 @fg() local_unnamed_addr #0 {
281 ; OPT: define i64 @fh() local_unnamed_addr #0 {
284 ; OPT: define i64 @fi() local_unnamed_addr #0 {
287 ; TO: define i64 @fa() local_unnamed_addr #0 {
290 ; TO: define i64 @fb() local_unnamed_addr #0 {
293 ; TO: define i64 @fc() local_unnamed_addr #0 {
296 ; TO: define i64 @fd() local_unnamed_addr #0 {
299 ; TO: define i64 @fe() local_unnamed_addr #0 {
302 ; TO: define i64 @ff() local_unnamed_addr #0 {
305 ; TO: define i64 @fg() local_unnamed_addr #0 {
308 ; TO: define i64 @fh() local_unnamed_addr #0 {
311 ; TO: define i64 @fi() local_unnamed_addr #0 {
314 ; SCEV-LABEL: Classifying expressions for: @fa
315 ; SCEV: %t = bitcast i64 mul (i64 ptrtoint ({ [7 x double], [7 x double] }* getelementptr ({ [7 x double], [7 x double] }, { [7 x double], [7 x double] }* null, i64 11) to i64), i64 15) to i64
317 ; SCEV-LABEL: Classifying expressions for: @fb
318 ; SCEV: %t = bitcast i64 ptrtoint ([13 x double]* getelementptr ({ i1, [13 x double] }, { i1, [13 x double] }* null, i64 0, i32 1) to i64) to i64
320 ; SCEV-LABEL: Classifying expressions for: @fc
321 ; SCEV: %t = bitcast i64 ptrtoint (double* getelementptr ({ double, double, double, double }, { double, double, double, double }* null, i64 0, i32 2) to i64) to i64
323 ; SCEV-LABEL: Classifying expressions for: @fd
324 ; SCEV: %t = bitcast i64 ptrtoint (double* getelementptr ([13 x double], [13 x double]* null, i64 0, i32 11) to i64) to i64
326 ; SCEV-LABEL: Classifying expressions for: @fe
327 ; SCEV: %t = bitcast i64 ptrtoint (double* getelementptr ({ double, float, double, double }, { double, float, double, double }* null, i64 0, i32 2) to i64) to i64
329 ; SCEV-LABEL: Classifying expressions for: @ff
330 ; SCEV: %t = bitcast i64 ptrtoint (<{ i16, i128 }>* getelementptr ({ i1, <{ i16, i128 }> }, { i1, <{ i16, i128 }> }* null, i64 0, i32 1) to i64) to i64
332 ; SCEV-LABEL: Classifying expressions for: @fg
333 ; SCEV: %t = bitcast i64 ptrtoint ({ double, double }* getelementptr ({ i1, { double, double } }, { i1, { double, double } }* null, i64 0, i32 1) to i64) to i64
335 ; SCEV-LABEL: Classifying expressions for: @fh
336 ; SCEV: %t = bitcast i64 ptrtoint (double** getelementptr (double*, double** null, i32 1) to i64) to i64
338 ; SCEV-LABEL: Classifying expressions for: @fi
339 ; SCEV: %t = bitcast i64 ptrtoint (double** getelementptr ({ i1, double* }, { i1, double* }* null, i64 0, i32 1) to i64) to i64
342 define i64 @fa() nounwind {
343 %t = bitcast i64 mul (i64 3, i64 mul (i64 ptrtoint ({[7 x double], [7 x double]}* getelementptr ({[7 x double], [7 x double]}, {[7 x double], [7 x double]}* null, i64 11) to i64), i64 5)) to i64
346 define i64 @fb() nounwind {
347 %t = bitcast i64 ptrtoint ([13 x double]* getelementptr ({i1, [13 x double]}, {i1, [13 x double]}* null, i64 0, i32 1) to i64) to i64
350 define i64 @fc() nounwind {
351 %t = bitcast i64 ptrtoint (double* getelementptr ({double, double, double, double}, {double, double, double, double}* null, i64 0, i32 2) to i64) to i64
354 define i64 @fd() nounwind {
355 %t = bitcast i64 ptrtoint (double* getelementptr ([13 x double], [13 x double]* null, i64 0, i32 11) to i64) to i64
358 define i64 @fe() nounwind {
359 %t = bitcast i64 ptrtoint (double* getelementptr ({double, float, double, double}, {double, float, double, double}* null, i64 0, i32 2) to i64) to i64
362 define i64 @ff() nounwind {
363 %t = bitcast i64 ptrtoint (<{ i16, i128 }>* getelementptr ({i1, <{ i16, i128 }>}, {i1, <{ i16, i128 }>}* null, i64 0, i32 1) to i64) to i64
366 define i64 @fg() nounwind {
367 %t = bitcast i64 ptrtoint ({double, double}* getelementptr ({i1, {double, double}}, {i1, {double, double}}* null, i64 0, i32 1) to i64) to i64
370 define i64 @fh() nounwind {
371 %t = bitcast i64 ptrtoint (double** getelementptr (double*, double** null, i32 1) to i64) to i64
374 define i64 @fi() nounwind {
375 %t = bitcast i64 ptrtoint (double** getelementptr ({i1, double*}, {i1, double*}* null, i64 0, i32 1) to i64) to i64
379 ; PLAIN: define i64* @fM() #0 {
380 ; PLAIN: %t = bitcast i64* getelementptr (i64, i64* null, i32 1) to i64*
383 ; PLAIN: define i64* @fN() #0 {
384 ; PLAIN: %t = bitcast i64* getelementptr ({ i64, i64 }, { i64, i64 }* null, i32 0, i32 1) to i64*
387 ; PLAIN: define i64* @fO() #0 {
388 ; PLAIN: %t = bitcast i64* getelementptr ([2 x i64], [2 x i64]* null, i32 0, i32 1) to i64*
391 ; OPT: define i64* @fM() local_unnamed_addr #0 {
392 ; OPT: ret i64* inttoptr (i64 8 to i64*)
394 ; OPT: define i64* @fN() local_unnamed_addr #0 {
395 ; OPT: ret i64* inttoptr (i64 8 to i64*)
397 ; OPT: define i64* @fO() local_unnamed_addr #0 {
398 ; OPT: ret i64* inttoptr (i64 8 to i64*)
400 ; TO: define i64* @fM() local_unnamed_addr #0 {
401 ; TO: ret i64* inttoptr (i64 8 to i64*)
403 ; TO: define i64* @fN() local_unnamed_addr #0 {
404 ; TO: ret i64* inttoptr (i64 8 to i64*)
406 ; TO: define i64* @fO() local_unnamed_addr #0 {
407 ; TO: ret i64* inttoptr (i64 8 to i64*)
409 ; SCEV: Classifying expressions for: @fM
410 ; SCEV: %t = bitcast i64* getelementptr (i64, i64* null, i32 1) to i64*
411 ; SCEV: --> (8 + null)<nuw><nsw> U: [8,9) S: [8,9)
412 ; SCEV: Classifying expressions for: @fN
413 ; SCEV: %t = bitcast i64* getelementptr ({ i64, i64 }, { i64, i64 }* null, i32 0, i32 1) to i64*
414 ; SCEV: --> (8 + null)<nuw><nsw> U: [8,9) S: [8,9)
415 ; SCEV: Classifying expressions for: @fO
416 ; SCEV: %t = bitcast i64* getelementptr ([2 x i64], [2 x i64]* null, i32 0, i32 1) to i64*
417 ; SCEV: --> (8 + null)<nuw><nsw> U: [8,9) S: [8,9)
419 define i64* @fM() nounwind {
420 %t = bitcast i64* getelementptr (i64, i64* null, i32 1) to i64*
423 define i64* @fN() nounwind {
424 %t = bitcast i64* getelementptr ({ i64, i64 }, { i64, i64 }* null, i32 0, i32 1) to i64*
427 define i64* @fO() nounwind {
428 %t = bitcast i64* getelementptr ([2 x i64], [2 x i64]* null, i32 0, i32 1) to i64*
432 ; PLAIN: define i32* @fZ() #0 {
433 ; PLAIN: %t = bitcast i32* getelementptr inbounds (i32, i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1) to i32*
436 ; OPT: define i32* @fZ() local_unnamed_addr #0 {
437 ; OPT: ret i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
439 ; TO: define i32* @fZ() local_unnamed_addr #0 {
440 ; TO: ret i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 1)
442 ; SCEV: Classifying expressions for: @fZ
443 ; SCEV: %t = bitcast i32* getelementptr inbounds (i32, i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1) to i32*
444 ; SCEV: --> (12 + @ext)
446 define i32* @fZ() nounwind {
447 %t = bitcast i32* getelementptr inbounds (i32, i32* getelementptr inbounds ([3 x { i32, i32 }], [3 x { i32, i32 }]* @ext, i64 0, i64 1, i32 0), i64 1) to i32*
451 ; PR15262 - Check GEP folding with casts between address spaces.
453 @p0 = global [4 x i8] zeroinitializer, align 1
454 @p12 = addrspace(12) global [4 x i8] zeroinitializer, align 1
456 define i8* @different_addrspace() nounwind noinline {
457 ; OPT: different_addrspace
458 %p = getelementptr inbounds i8, i8* addrspacecast ([4 x i8] addrspace(12)* @p12 to i8*),
461 ; OPT: ret i8* getelementptr ([4 x i8], [4 x i8]* addrspacecast ([4 x i8] addrspace(12)* @p12 to [4 x i8]*), i64 0, i64 2)
464 define i8* @same_addrspace() nounwind noinline {
465 ; OPT: same_addrspace
466 %p = getelementptr inbounds i8, i8* bitcast ([4 x i8] * @p0 to i8*), i32 2
468 ; OPT: ret i8* getelementptr inbounds ([4 x i8], [4 x i8]* @p0, i64 0, i64 2)
471 @gv1 = internal global i32 1
472 @gv2 = internal global [1 x i32] [ i32 2 ]
473 @gv3 = internal global [1 x i32] [ i32 2 ]
475 ; Handled by TI-independent constant folder
476 define i1 @gv_gep_vs_gv() {
477 ret i1 icmp eq (i32* getelementptr inbounds ([1 x i32], [1 x i32]* @gv2, i32 0, i32 0), i32* @gv1)
479 ; PLAIN: gv_gep_vs_gv
480 ; PLAIN: ret i1 false
482 define i1 @gv_gep_vs_gv_gep() {
483 ret i1 icmp eq (i32* getelementptr inbounds ([1 x i32], [1 x i32]* @gv2, i32 0, i32 0), i32* getelementptr inbounds ([1 x i32], [1 x i32]* @gv3, i32 0, i32 0))
485 ; PLAIN: gv_gep_vs_gv_gep
486 ; PLAIN: ret i1 false
488 ; CHECK: attributes #0 = { nounwind }