15ac624c8SFarzon Lotfi 25ac624c8SFarzon Lotfi; RUN: opt -S -dxil-flatten-arrays %s | FileCheck %s 35ac624c8SFarzon Lotfi 45ac624c8SFarzon Lotfi; CHECK-LABEL: alloca_2d_test 55ac624c8SFarzon Lotfidefine void @alloca_2d_test () { 65ac624c8SFarzon Lotfi; CHECK-NEXT: alloca [9 x i32], align 4 75ac624c8SFarzon Lotfi; CHECK-NEXT: ret void 85ac624c8SFarzon Lotfi; 95ac624c8SFarzon Lotfi %1 = alloca [3 x [3 x i32]], align 4 105ac624c8SFarzon Lotfi ret void 115ac624c8SFarzon Lotfi} 125ac624c8SFarzon Lotfi 135ac624c8SFarzon Lotfi; CHECK-LABEL: alloca_3d_test 145ac624c8SFarzon Lotfidefine void @alloca_3d_test () { 155ac624c8SFarzon Lotfi; CHECK-NEXT: alloca [8 x i32], align 4 165ac624c8SFarzon Lotfi; CHECK-NEXT: ret void 175ac624c8SFarzon Lotfi; 185ac624c8SFarzon Lotfi %1 = alloca [2 x[2 x [2 x i32]]], align 4 195ac624c8SFarzon Lotfi ret void 205ac624c8SFarzon Lotfi} 215ac624c8SFarzon Lotfi 225ac624c8SFarzon Lotfi; CHECK-LABEL: alloca_4d_test 235ac624c8SFarzon Lotfidefine void @alloca_4d_test () { 245ac624c8SFarzon Lotfi; CHECK-NEXT: alloca [16 x i32], align 4 255ac624c8SFarzon Lotfi; CHECK-NEXT: ret void 265ac624c8SFarzon Lotfi; 275ac624c8SFarzon Lotfi %1 = alloca [2x[2 x[2 x [2 x i32]]]], align 4 285ac624c8SFarzon Lotfi ret void 295ac624c8SFarzon Lotfi} 305ac624c8SFarzon Lotfi 315ac624c8SFarzon Lotfi; CHECK-LABEL: gep_2d_test 325ac624c8SFarzon Lotfidefine void @gep_2d_test () { 335ac624c8SFarzon Lotfi ; CHECK: [[a:%.*]] = alloca [9 x i32], align 4 345ac624c8SFarzon Lotfi ; CHECK-COUNT-9: getelementptr inbounds [9 x i32], ptr [[a]], i32 {{[0-8]}} 355ac624c8SFarzon Lotfi ; CHECK-NEXT: ret void 365ac624c8SFarzon Lotfi %1 = alloca [3 x [3 x i32]], align 4 375ac624c8SFarzon Lotfi %g2d0 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %1, i32 0, i32 0 385ac624c8SFarzon Lotfi %g1d_1 = getelementptr inbounds [3 x i32], [3 x i32]* %g2d0, i32 0, i32 0 395ac624c8SFarzon Lotfi %g1d_2 = getelementptr inbounds [3 x i32], [3 x i32]* %g2d0, i32 0, i32 1 405ac624c8SFarzon Lotfi %g1d_3 = getelementptr inbounds [3 x i32], [3 x i32]* %g2d0, i32 0, i32 2 415ac624c8SFarzon Lotfi %g2d1 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %1, i32 0, i32 1 425ac624c8SFarzon Lotfi %g1d1_1 = getelementptr inbounds [3 x i32], [3 x i32]* %g2d1, i32 0, i32 0 435ac624c8SFarzon Lotfi %g1d1_2 = getelementptr inbounds [3 x i32], [3 x i32]* %g2d1, i32 0, i32 1 445ac624c8SFarzon Lotfi %g1d1_3 = getelementptr inbounds [3 x i32], [3 x i32]* %g2d1, i32 0, i32 2 455ac624c8SFarzon Lotfi %g2d2 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %1, i32 0, i32 2 465ac624c8SFarzon Lotfi %g1d2_1 = getelementptr inbounds [3 x i32], [3 x i32]* %g2d2, i32 0, i32 0 475ac624c8SFarzon Lotfi %g1d2_2 = getelementptr inbounds [3 x i32], [3 x i32]* %g2d2, i32 0, i32 1 485ac624c8SFarzon Lotfi %g1d2_3 = getelementptr inbounds [3 x i32], [3 x i32]* %g2d2, i32 0, i32 2 495ac624c8SFarzon Lotfi 505ac624c8SFarzon Lotfi ret void 515ac624c8SFarzon Lotfi} 525ac624c8SFarzon Lotfi 535ac624c8SFarzon Lotfi; CHECK-LABEL: gep_3d_test 545ac624c8SFarzon Lotfidefine void @gep_3d_test () { 555ac624c8SFarzon Lotfi ; CHECK: [[a:%.*]] = alloca [8 x i32], align 4 565ac624c8SFarzon Lotfi ; CHECK-COUNT-8: getelementptr inbounds [8 x i32], ptr [[a]], i32 {{[0-7]}} 575ac624c8SFarzon Lotfi ; CHECK-NEXT: ret void 585ac624c8SFarzon Lotfi %1 = alloca [2 x[2 x [2 x i32]]], align 4 595ac624c8SFarzon Lotfi %g3d0 = getelementptr inbounds [2 x[2 x [2 x i32]]], [2 x[2 x [2 x i32]]]* %1, i32 0, i32 0 605ac624c8SFarzon Lotfi %g2d0 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %g3d0, i32 0, i32 0 615ac624c8SFarzon Lotfi %g1d_1 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d0, i32 0, i32 0 625ac624c8SFarzon Lotfi %g1d_2 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d0, i32 0, i32 1 635ac624c8SFarzon Lotfi %g2d1 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %g3d0, i32 0, i32 1 645ac624c8SFarzon Lotfi %g1d1_1 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d1, i32 0, i32 0 655ac624c8SFarzon Lotfi %g1d1_2 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d1, i32 0, i32 1 665ac624c8SFarzon Lotfi %g3d1 = getelementptr inbounds [2 x[2 x [2 x i32]]], [2 x[2 x [2 x i32]]]* %1, i32 0, i32 1 675ac624c8SFarzon Lotfi %g2d2 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %g3d1, i32 0, i32 0 685ac624c8SFarzon Lotfi %g1d2_1 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d2, i32 0, i32 0 695ac624c8SFarzon Lotfi %g1d2_2 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d2, i32 0, i32 1 705ac624c8SFarzon Lotfi %g2d3 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %g3d1, i32 0, i32 1 715ac624c8SFarzon Lotfi %g1d3_1 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d3, i32 0, i32 0 725ac624c8SFarzon Lotfi %g1d3_2 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d3, i32 0, i32 1 735ac624c8SFarzon Lotfi ret void 745ac624c8SFarzon Lotfi} 755ac624c8SFarzon Lotfi 765ac624c8SFarzon Lotfi; CHECK-LABEL: gep_4d_test 775ac624c8SFarzon Lotfidefine void @gep_4d_test () { 785ac624c8SFarzon Lotfi ; CHECK: [[a:%.*]] = alloca [16 x i32], align 4 795ac624c8SFarzon Lotfi ; CHECK-COUNT-16: getelementptr inbounds [16 x i32], ptr [[a]], i32 {{[0-9]|1[0-5]}} 805ac624c8SFarzon Lotfi ; CHECK-NEXT: ret void 815ac624c8SFarzon Lotfi %1 = alloca [2x[2 x[2 x [2 x i32]]]], align 4 825ac624c8SFarzon Lotfi %g4d0 = getelementptr inbounds [2x[2 x[2 x [2 x i32]]]], [2x[2 x[2 x [2 x i32]]]]* %1, i32 0, i32 0 835ac624c8SFarzon Lotfi %g3d0 = getelementptr inbounds [2 x[2 x [2 x i32]]], [2 x[2 x [2 x i32]]]* %g4d0, i32 0, i32 0 845ac624c8SFarzon Lotfi %g2d0_0 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %g3d0, i32 0, i32 0 855ac624c8SFarzon Lotfi %g1d_0 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d0_0, i32 0, i32 0 865ac624c8SFarzon Lotfi %g1d_1 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d0_0, i32 0, i32 1 875ac624c8SFarzon Lotfi %g2d0_1 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %g3d0, i32 0, i32 1 885ac624c8SFarzon Lotfi %g1d_2 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d0_1, i32 0, i32 0 895ac624c8SFarzon Lotfi %g1d_3 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d0_1, i32 0, i32 1 905ac624c8SFarzon Lotfi %g3d1 = getelementptr inbounds [2 x[2 x [2 x i32]]], [2 x[2 x [2 x i32]]]* %g4d0, i32 0, i32 1 915ac624c8SFarzon Lotfi %g2d0_2 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %g3d1, i32 0, i32 0 925ac624c8SFarzon Lotfi %g1d_4 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d0_2, i32 0, i32 0 935ac624c8SFarzon Lotfi %g1d_5 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d0_2, i32 0, i32 1 945ac624c8SFarzon Lotfi %g2d1_2 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %g3d1, i32 0, i32 1 955ac624c8SFarzon Lotfi %g1d_6 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d1_2, i32 0, i32 0 965ac624c8SFarzon Lotfi %g1d_7 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d1_2, i32 0, i32 1 975ac624c8SFarzon Lotfi %g4d1 = getelementptr inbounds [2x[2 x[2 x [2 x i32]]]], [2x[2 x[2 x [2 x i32]]]]* %1, i32 0, i32 1 985ac624c8SFarzon Lotfi %g3d0_1 = getelementptr inbounds [2 x[2 x [2 x i32]]], [2 x[2 x [2 x i32]]]* %g4d1, i32 0, i32 0 995ac624c8SFarzon Lotfi %g2d0_3 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %g3d0_1, i32 0, i32 0 1005ac624c8SFarzon Lotfi %g1d_8 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d0_3, i32 0, i32 0 1015ac624c8SFarzon Lotfi %g1d_9 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d0_3, i32 0, i32 1 1025ac624c8SFarzon Lotfi %g2d0_4 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %g3d0_1, i32 0, i32 1 1035ac624c8SFarzon Lotfi %g1d_10 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d0_4, i32 0, i32 0 1045ac624c8SFarzon Lotfi %g1d_11 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d0_4, i32 0, i32 1 1055ac624c8SFarzon Lotfi %g3d1_1 = getelementptr inbounds [2 x[2 x [2 x i32]]], [2 x[2 x [2 x i32]]]* %g4d1, i32 0, i32 1 1065ac624c8SFarzon Lotfi %g2d0_5 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %g3d1_1, i32 0, i32 0 1075ac624c8SFarzon Lotfi %g1d_12 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d0_5, i32 0, i32 0 1085ac624c8SFarzon Lotfi %g1d_13 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d0_5, i32 0, i32 1 1095ac624c8SFarzon Lotfi %g2d1_3 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %g3d1_1, i32 0, i32 1 1105ac624c8SFarzon Lotfi %g1d_14 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d1_3, i32 0, i32 0 1115ac624c8SFarzon Lotfi %g1d_15 = getelementptr inbounds [2 x i32], [2 x i32]* %g2d1_3, i32 0, i32 1 1125ac624c8SFarzon Lotfi ret void 1135ac624c8SFarzon Lotfi} 1145ac624c8SFarzon Lotfi 1155ac624c8SFarzon Lotfi 1165ac624c8SFarzon Lotfi@a = internal global [2 x [3 x [4 x i32]]] [[3 x [4 x i32]] [[4 x i32] [i32 0, i32 1, i32 2, i32 3], 1175ac624c8SFarzon Lotfi [4 x i32] [i32 4, i32 5, i32 6, i32 7], 1185ac624c8SFarzon Lotfi [4 x i32] [i32 8, i32 9, i32 10, i32 11]], 1195ac624c8SFarzon Lotfi [3 x [4 x i32]] [[4 x i32] [i32 12, i32 13, i32 14, i32 15], 1205ac624c8SFarzon Lotfi [4 x i32] [i32 16, i32 17, i32 18, i32 19], 1215ac624c8SFarzon Lotfi [4 x i32] [i32 20, i32 21, i32 22, i32 23]]], align 4 1225ac624c8SFarzon Lotfi 1235ac624c8SFarzon Lotfi@b = internal global [2 x [3 x [4 x i32]]] zeroinitializer, align 16 1245ac624c8SFarzon Lotfi 1255ac624c8SFarzon Lotfidefine void @global_gep_load() { 1265ac624c8SFarzon Lotfi ; CHECK: [[GEP_PTR:%.*]] = getelementptr inbounds [24 x i32], ptr @a.1dim, i32 6 1275ac624c8SFarzon Lotfi ; CHECK: load i32, ptr [[GEP_PTR]], align 4 1285ac624c8SFarzon Lotfi ; CHECK-NEXT: ret void 1295ac624c8SFarzon Lotfi %1 = getelementptr inbounds [2 x [3 x [4 x i32]]], [2 x [3 x [4 x i32]]]* @a, i32 0, i32 0 1305ac624c8SFarzon Lotfi %2 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i32 0, i32 1 1315ac624c8SFarzon Lotfi %3 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i32 0, i32 2 1325ac624c8SFarzon Lotfi %4 = load i32, i32* %3, align 4 1335ac624c8SFarzon Lotfi ret void 1345ac624c8SFarzon Lotfi} 1355ac624c8SFarzon Lotfi 1365ac624c8SFarzon Lotfidefine void @global_gep_load_index(i32 %row, i32 %col, i32 %timeIndex) { 1375ac624c8SFarzon Lotfi; CHECK-LABEL: define void @global_gep_load_index( 1385ac624c8SFarzon Lotfi; CHECK-SAME: i32 [[ROW:%.*]], i32 [[COL:%.*]], i32 [[TIMEINDEX:%.*]]) { 1395ac624c8SFarzon Lotfi; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[TIMEINDEX]], 1 1405ac624c8SFarzon Lotfi; CHECK-NEXT: [[TMP2:%.*]] = add i32 0, [[TMP1]] 1415ac624c8SFarzon Lotfi; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[COL]], 4 1425ac624c8SFarzon Lotfi; CHECK-NEXT: [[TMP4:%.*]] = add i32 [[TMP2]], [[TMP3]] 1435ac624c8SFarzon Lotfi; CHECK-NEXT: [[TMP5:%.*]] = mul i32 [[ROW]], 12 1445ac624c8SFarzon Lotfi; CHECK-NEXT: [[TMP6:%.*]] = add i32 [[TMP4]], [[TMP5]] 1455ac624c8SFarzon Lotfi; CHECK-NEXT: [[DOTFLAT:%.*]] = getelementptr inbounds [24 x i32], ptr @a.1dim, i32 [[TMP6]] 1465ac624c8SFarzon Lotfi; CHECK-NOT: getelementptr inbounds [2 x [3 x [4 x i32]]]{{.*}} 1475ac624c8SFarzon Lotfi; CHECK-NOT: getelementptr inbounds [3 x [4 x i32]]{{.*}} 1485ac624c8SFarzon Lotfi; CHECK-NOT: getelementptr inbounds [4 x i32]{{.*}} 1495ac624c8SFarzon Lotfi; CHECK-NEXT: [[TMP7:%.*]] = load i32, ptr [[DOTFLAT]], align 4 1505ac624c8SFarzon Lotfi; CHECK-NEXT: ret void 1515ac624c8SFarzon Lotfi; 1525ac624c8SFarzon Lotfi %1 = getelementptr inbounds [2 x [3 x [4 x i32]]], [2 x [3 x [4 x i32]]]* @a, i32 0, i32 %row 1535ac624c8SFarzon Lotfi %2 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i32 0, i32 %col 1545ac624c8SFarzon Lotfi %3 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i32 0, i32 %timeIndex 1555ac624c8SFarzon Lotfi %4 = load i32, i32* %3, align 4 1565ac624c8SFarzon Lotfi ret void 1575ac624c8SFarzon Lotfi} 1585ac624c8SFarzon Lotfi 1595ac624c8SFarzon Lotfidefine void @global_incomplete_gep_chain(i32 %row, i32 %col) { 1605ac624c8SFarzon Lotfi; CHECK-LABEL: define void @global_incomplete_gep_chain( 1615ac624c8SFarzon Lotfi; CHECK-SAME: i32 [[ROW:%.*]], i32 [[COL:%.*]]) { 1625ac624c8SFarzon Lotfi; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[COL]], 1 1635ac624c8SFarzon Lotfi; CHECK-NEXT: [[TMP2:%.*]] = add i32 0, [[TMP1]] 1645ac624c8SFarzon Lotfi; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[ROW]], 3 1655ac624c8SFarzon Lotfi; CHECK-NEXT: [[TMP4:%.*]] = add i32 [[TMP2]], [[TMP3]] 1665ac624c8SFarzon Lotfi; CHECK-NEXT: [[DOTFLAT:%.*]] = getelementptr inbounds [24 x i32], ptr @a.1dim, i32 [[TMP4]] 1675ac624c8SFarzon Lotfi; CHECK-NOT: getelementptr inbounds [2 x [3 x [4 x i32]]]{{.*}} 1685ac624c8SFarzon Lotfi; CHECK-NOT: getelementptr inbounds [3 x [4 x i32]]{{.*}} 1695ac624c8SFarzon Lotfi; CHECK-NOT: getelementptr inbounds [4 x i32]{{.*}} 1705ac624c8SFarzon Lotfi; CHECK-NEXT: [[TMP5:%.*]] = load i32, ptr [[DOTFLAT]], align 4 1715ac624c8SFarzon Lotfi; CHECK-NEXT: ret void 1725ac624c8SFarzon Lotfi; 1735ac624c8SFarzon Lotfi %1 = getelementptr inbounds [2 x [3 x [4 x i32]]], [2 x [3 x [4 x i32]]]* @a, i32 0, i32 %row 1745ac624c8SFarzon Lotfi %2 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i32 0, i32 %col 1755ac624c8SFarzon Lotfi %4 = load i32, i32* %2, align 4 1765ac624c8SFarzon Lotfi ret void 1775ac624c8SFarzon Lotfi} 1785ac624c8SFarzon Lotfi 1795ac624c8SFarzon Lotfidefine void @global_gep_store() { 1805ac624c8SFarzon Lotfi ; CHECK: [[GEP_PTR:%.*]] = getelementptr inbounds [24 x i32], ptr @b.1dim, i32 13 1815ac624c8SFarzon Lotfi ; CHECK: store i32 1, ptr [[GEP_PTR]], align 4 1825ac624c8SFarzon Lotfi ; CHECK-NEXT: ret void 1835ac624c8SFarzon Lotfi %1 = getelementptr inbounds [2 x [3 x [4 x i32]]], [2 x [3 x [4 x i32]]]* @b, i32 0, i32 1 1845ac624c8SFarzon Lotfi %2 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i32 0, i32 0 1855ac624c8SFarzon Lotfi %3 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i32 0, i32 1 1865ac624c8SFarzon Lotfi store i32 1, i32* %3, align 4 1875ac624c8SFarzon Lotfi ret void 1885ac624c8SFarzon Lotfi} 189*e0b522ddSJustin Bogner 190*e0b522ddSJustin Bogner; Make sure we don't try to walk the body of a function declaration. 191*e0b522ddSJustin Bognerdeclare void @opaque_function() 192