|  | 
| 4 | 4 | @zeroinit = constant {} zeroinitializer | 
| 5 | 5 | @poison = constant {} poison | 
| 6 | 6 | 
 | 
|  | 7 | +@constzeroarray = internal constant [4 x i32] zeroinitializer | 
|  | 8 | + | 
|  | 9 | +@constarray = internal constant [4 x i32] [i32 1, i32 1, i32 1, i32 1] | 
|  | 10 | +@constarrayi8 = internal constant [2 x i8] [i8 1, i8 1] | 
|  | 11 | + | 
| 7 | 12 | define i32 @crash_on_zeroinit() { | 
| 8 | 13 | ; CHECK-LABEL: @crash_on_zeroinit( | 
| 9 | 14 | ; CHECK-NEXT:    ret i32 poison | 
| @@ -40,3 +45,51 @@ define <3 x float> @load_vec3() { | 
| 40 | 45 |   %1 = load <3 x float>, ptr getelementptr inbounds (<3 x float>, ptr @constvec, i64 1) | 
| 41 | 46 |   ret <3 x float> %1 | 
| 42 | 47 | } | 
|  | 48 | + | 
|  | 49 | +define i32 @load_gep_const_zero_array(i64 %idx) { | 
|  | 50 | +; CHECK-LABEL: @load_gep_const_zero_array( | 
|  | 51 | +; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [4 x i32], ptr @constzeroarray, i64 0, i64 [[IDX:%.*]] | 
|  | 52 | +; CHECK-NEXT:    [[LOAD:%.*]] = load i32, ptr [[GEP]], align 4 | 
|  | 53 | +; CHECK-NEXT:    ret i32 [[LOAD]] | 
|  | 54 | +; | 
|  | 55 | +  %gep = getelementptr inbounds [4 x i32], ptr @constzeroarray, i64 0, i64 %idx | 
|  | 56 | +  %load = load i32, ptr %gep | 
|  | 57 | +  ret i32 %load | 
|  | 58 | +} | 
|  | 59 | + | 
|  | 60 | +define i8 @load_i8_multi_gep_const_zero_array(i64 %idx1, i64 %idx2) { | 
|  | 61 | +; CHECK-LABEL: @load_i8_multi_gep_const_zero_array( | 
|  | 62 | +; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr inbounds i8, ptr @constzeroarray, i64 [[IDX1:%.*]] | 
|  | 63 | +; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds i8, ptr [[GEP1]], i64 [[IDX2:%.*]] | 
|  | 64 | +; CHECK-NEXT:    [[LOAD:%.*]] = load i8, ptr [[GEP]], align 1 | 
|  | 65 | +; CHECK-NEXT:    ret i8 [[LOAD]] | 
|  | 66 | +; | 
|  | 67 | +  %gep1 = getelementptr inbounds i8, ptr @constzeroarray, i64 %idx1 | 
|  | 68 | +  %gep = getelementptr inbounds i8, ptr %gep1, i64 %idx2 | 
|  | 69 | +  %load = load i8, ptr %gep | 
|  | 70 | +  ret i8 %load | 
|  | 71 | +} | 
|  | 72 | + | 
|  | 73 | +define i32 @load_gep_const_array(i64 %idx) { | 
|  | 74 | +; CHECK-LABEL: @load_gep_const_array( | 
|  | 75 | +; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [4 x i32], ptr @constarray, i64 0, i64 [[IDX:%.*]] | 
|  | 76 | +; CHECK-NEXT:    [[LOAD:%.*]] = load i32, ptr [[GEP]], align 4 | 
|  | 77 | +; CHECK-NEXT:    ret i32 [[LOAD]] | 
|  | 78 | +; | 
|  | 79 | +  %gep = getelementptr inbounds [4 x i32], ptr @constarray, i64 0, i64 %idx | 
|  | 80 | +  %load = load i32, ptr %gep | 
|  | 81 | +  ret i32 %load | 
|  | 82 | +} | 
|  | 83 | + | 
|  | 84 | +define i8 @load_i8_multi_gep_const_array(i64 %idx1, i64 %idx2) { | 
|  | 85 | +; CHECK-LABEL: @load_i8_multi_gep_const_array( | 
|  | 86 | +; CHECK-NEXT:    [[GEP1:%.*]] = getelementptr inbounds i8, ptr @constarrayi8, i64 [[IDX1:%.*]] | 
|  | 87 | +; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds i8, ptr [[GEP1]], i64 [[IDX2:%.*]] | 
|  | 88 | +; CHECK-NEXT:    [[LOAD:%.*]] = load i8, ptr [[GEP]], align 1 | 
|  | 89 | +; CHECK-NEXT:    ret i8 [[LOAD]] | 
|  | 90 | +; | 
|  | 91 | +  %gep1 = getelementptr inbounds i8, ptr @constarrayi8, i64 %idx1 | 
|  | 92 | +  %gep = getelementptr inbounds i8, ptr %gep1, i64 %idx2 | 
|  | 93 | +  %load = load i8, ptr %gep | 
|  | 94 | +  ret i8 %load | 
|  | 95 | +} | 
0 commit comments