@@ -255,5 +255,24 @@ define void @gep_4d_index_and_gep_chain_mixed() {
255
255
ret void
256
256
}
257
257
258
+ ; This test demonstrates that the collapsing of GEP chains occurs regardless of
259
+ ; the source element type given to the GEP. As long as the root pointer being
260
+ ; indexed to is an aggregate data structure, the GEP will be flattened.
261
+ define void @gep_scalar_flatten () {
262
+ ; CHECK-LABEL: gep_scalar_flatten
263
+ ; CHECK-NEXT: [[ALLOCA:%.*]] = alloca [24 x i32]
264
+ ; CHECK-NEXT: getelementptr inbounds nuw [24 x i32], ptr [[ALLOCA]], i32 0, i32 17
265
+ ; CHECK-NEXT: getelementptr inbounds nuw [24 x i32], ptr [[ALLOCA]], i32 0, i32 17
266
+ ; CHECK-NEXT: getelementptr inbounds nuw [24 x i32], ptr [[ALLOCA]], i32 0, i32 23
267
+ ; CHECK-NEXT: ret void
268
+ %a = alloca [2 x [3 x [4 x i32 ]]], align 4
269
+ %i8root = getelementptr inbounds nuw i8 , [2 x [3 x [4 x i32 ]]]* %a , i32 68 ; %a[1][1][1]
270
+ %i32root = getelementptr inbounds nuw i32 , [2 x [3 x [4 x i32 ]]]* %a , i32 17 ; %a[1][1][1]
271
+ %c0 = getelementptr inbounds nuw [2 x [3 x [4 x i32 ]]], [2 x [3 x [4 x i32 ]]]* %a , i32 0 , i32 1 ; %a[1]
272
+ %c1 = getelementptr inbounds nuw i32 , [3 x [4 x i32 ]]* %c0 , i32 8 ; %a[1][2]
273
+ %c2 = getelementptr inbounds nuw i8 , [4 x i32 ]* %c1 , i32 12 ; %a[1][2][3]
274
+ ret void
275
+ }
276
+
258
277
; Make sure we don't try to walk the body of a function declaration.
259
278
declare void @opaque_function ()
0 commit comments