Skip to content

Commit dee77e9

Browse files
committed
Add test demonstrating the flattening of scalar GEPs, including i8
1 parent 1a09803 commit dee77e9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

llvm/test/CodeGen/DirectX/flatten-array.ll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,5 +255,24 @@ define void @gep_4d_index_and_gep_chain_mixed() {
255255
ret void
256256
}
257257

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+
258277
; Make sure we don't try to walk the body of a function declaration.
259278
declare void @opaque_function()

0 commit comments

Comments
 (0)