@@ -151,26 +151,55 @@ void func2() {
151
151
152
152
void func3 () {
153
153
int arr[2 ] = {5 , 6 };
154
+
155
+ int idx = 1 ;
156
+ int e = arr[idx];
154
157
}
155
158
156
- // CIR: %[[ARR3:.*]] = cir.alloca !cir.array<!s32i x 2>, !cir.ptr<!cir.array<!s32i x 2>>, ["arr", init]
157
- // CIR: %[[ARR_3_PTR:.*]] = cir.cast(array_to_ptrdecay, %[[ARR3]] : !cir.ptr<!cir.array<!s32i x 2>>), !cir.ptr<!s32i>
159
+ // CIR: %[[ARR:.*]] = cir.alloca !cir.array<!s32i x 2>, !cir.ptr<!cir.array<!s32i x 2>>, ["arr", init]
160
+ // CIR: %[[IDX:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["idx", init]
161
+ // CIR: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init]
162
+ // CIR: %[[ARR_PTR:.*]] = cir.cast(array_to_ptrdecay, %[[ARR]] : !cir.ptr<!cir.array<!s32i x 2>>), !cir.ptr<!s32i>
158
163
// CIR: %[[V0:.*]] = cir.const #cir.int<5> : !s32i
159
- // CIR: cir.store %[[V0]], %[[ARR_3_PTR ]] : !s32i, !cir.ptr<!s32i>
164
+ // CIR: cir.store %[[V0]], %[[ARR_PTR ]] : !s32i, !cir.ptr<!s32i>
160
165
// CIR: %[[OFFSET_0:.*]] = cir.const #cir.int<1> : !s64i
161
- // CIR: %[[ELE_1_PTR:.*]] = cir.ptr_stride(%[[ARR_3_PTR ]] : !cir.ptr<!s32i>, %[[OFFSET_0]] : !s64i), !cir.ptr<!s32i>
166
+ // CIR: %[[ELE_1_PTR:.*]] = cir.ptr_stride(%[[ARR_PTR ]] : !cir.ptr<!s32i>, %[[OFFSET_0]] : !s64i), !cir.ptr<!s32i>
162
167
// CIR: %[[V1:.*]] = cir.const #cir.int<6> : !s32i
163
168
// CIR: cir.store %[[V1]], %[[ELE_1_PTR]] : !s32i, !cir.ptr<!s32i>
169
+ // CIR: %[[IDX_V:.*]] = cir.const #cir.int<1> : !s32i
170
+ // CIR: cir.store %[[IDX_V]], %[[IDX]] : !s32i, !cir.ptr<!s32i>
171
+ // CIR: %[[TMP_IDX:.*]] = cir.load %[[IDX]] : !cir.ptr<!s32i>, !s32i
172
+ // CIR: %[[ARR_PTR:.*]] = cir.cast(array_to_ptrdecay, %[[ARR]] : !cir.ptr<!cir.array<!s32i x 2>>), !cir.ptr<!s32i>
173
+ // CIR: %[[ELE_PTR:.*]] = cir.ptr_stride(%[[ARR_PTR]] : !cir.ptr<!s32i>, %[[TMP_IDX]] : !s32i), !cir.ptr<!s32i>
174
+ // CIR: %[[ELE_TMP:.*]] = cir.load %[[ELE_PTR]] : !cir.ptr<!s32i>, !s32i
175
+ // CIR: cir.store %[[ELE_TMP]], %[[INIT]] : !s32i, !cir.ptr<!s32i>
164
176
165
177
// LLVM: define void @func3()
166
178
// LLVM: %[[ARR_ALLOCA:.*]] = alloca [2 x i32], i64 1, align 4
179
+ // LLVM: %[[IDX:.*]] = alloca i32, i64 1, align 4
180
+ // LLVM: %[[INIT:.*]] = alloca i32, i64 1, align 4
167
181
// LLVM: %[[ARR_PTR:.*]] = getelementptr i32, ptr %[[ARR_ALLOCA]], i32 0
168
182
// LLVM: store i32 5, ptr %[[ARR_PTR]], align 4
169
183
// LLVM: %[[ELE_1_PTR:.*]] = getelementptr i32, ptr %[[ARR_PTR]], i64 1
170
184
// LLVM: store i32 6, ptr %[[ELE_1_PTR]], align 4
185
+ // LLVM: store i32 1, ptr %[[IDX]], align 4
186
+ // LLVM: %[[TMP1:.*]] = load i32, ptr %[[IDX]], align 4
187
+ // LLVM: %[[ARR_PTR:.*]] = getelementptr i32, ptr %[[ARR_ALLOCA]], i32 0
188
+ // LLVM: %[[IDX_I64:.*]] = sext i32 %[[TMP1]] to i64
189
+ // LLVM: %[[ELE:.*]] = getelementptr i32, ptr %[[ARR_PTR]], i64 %[[IDX_I64]]
190
+ // LLVM: %[[TMP2:.*]] = load i32, ptr %[[ELE]], align 4
191
+ // LLVM: store i32 %[[TMP2]], ptr %[[INIT]], align 4
171
192
172
- // OGCG: %arr = alloca [2 x i32], align 4
173
- // OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %arr, ptr align 4 @[[FUN3_ARR]], i64 8, i1 false)
193
+ // OGCG: %arr = alloca [2 x i32], align 4
194
+ // OGCG: %idx = alloca i32, align 4
195
+ // OGCG: %e = alloca i32, align 4
196
+ // OGCG: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %arr, ptr align 4 @[[FUN3_ARR]], i64 8, i1 false)
197
+ // OGCG: store i32 1, ptr %idx, align 4
198
+ // OGCG: %0 = load i32, ptr %idx, align 4
199
+ // OGCG: %idxprom = sext i32 %0 to i64
200
+ // OGCG: %arrayidx = getelementptr inbounds [2 x i32], ptr %arr, i64 0, i64 %idxprom
201
+ // OGCG: %1 = load i32, ptr %arrayidx, align 4
202
+ // OGCG: store i32 %1, ptr %e, align 4
174
203
175
204
void func4 () {
176
205
int arr[2 ][1 ] = {{5 }, {6 }};
0 commit comments