@@ -216,6 +216,29 @@ void foo9(double a, double b) {
216216// OGCG: store double %[[TMP_A]], ptr %[[C_REAL_PTR]], align 8
217217// OGCG: store double %[[TMP_B]], ptr %[[C_IMAG_PTR]], align 8
218218
219+ void foo12 () {
220+ double _Complex c;
221+ double imag = __imag__ c;
222+ }
223+
224+ // CIR: %[[COMPLEX:.*]] = cir.alloca !cir.complex<!cir.double>, !cir.ptr<!cir.complex<!cir.double>>, ["c"]
225+ // CIR: %[[INIT:.*]] = cir.alloca !cir.double, !cir.ptr<!cir.double>, ["imag", init]
226+ // CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX]] : !cir.ptr<!cir.complex<!cir.double>>, !cir.complex<!cir.double>
227+ // CIR: %[[IMAG:.*]] = cir.complex.imag %[[TMP]] : !cir.complex<!cir.double> -> !cir.double
228+ // CIR: cir.store{{.*}} %[[IMAG]], %[[INIT]] : !cir.double, !cir.ptr<!cir.double>
229+
230+ // LLVM: %[[COMPLEX:.*]] = alloca { double, double }, i64 1, align 8
231+ // LLVM: %[[INIT:.*]] = alloca double, i64 1, align 8
232+ // LLVM: %[[TMP:.*]] = load { double, double }, ptr %[[COMPLEX]], align 8
233+ // LLVM: %[[IMAG:.*]] = extractvalue { double, double } %[[TMP]], 1
234+ // LLVM: store double %[[IMAG]], ptr %[[INIT]], align 8
235+
236+ // OGCG: %[[COMPLEX:.*]] = alloca { double, double }, align 8
237+ // OGCG: %[[INIT:.*]] = alloca double, align 8
238+ // OGCG: %[[IMAG:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[COMPLEX]], i32 0, i32 1
239+ // OGCG: %[[TMP:.*]] = load double, ptr %[[IMAG]], align 8
240+ // OGCG: store double %[[TMP]], ptr %[[INIT]], align 8
241+
219242void foo13 () {
220243 double _Complex c;
221244 double real = __real__ c;
@@ -281,6 +304,39 @@ void foo15() {
281304// OGCG: store i32 %[[A_REAL]], ptr %[[B_REAL_PTR]], align 4
282305// OGCG: store i32 %[[A_IMAG]], ptr %[[B_IMAG_PTR]], align 4
283306
307+ int foo16 (int _Complex a, int _Complex b) {
308+ return __imag__ a + __imag__ b;
309+ }
310+
311+ // CIR: %[[RET:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"]
312+ // CIR: %[[COMPLEX_A:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
313+ // CIR: %[[A_IMAG:.*]] = cir.complex.imag %[[COMPLEX_A]] : !cir.complex<!s32i> -> !s32i
314+ // CIR: %[[COMPLEX_B:.*]] = cir.load{{.*}} {{.*}} : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
315+ // CIR: %[[B_IMAG:.*]] = cir.complex.imag %[[COMPLEX_B]] : !cir.complex<!s32i> -> !s32i
316+ // CIR: %[[ADD:.*]] = cir.binop(add, %[[A_IMAG]], %[[B_IMAG]]) nsw : !s32i
317+ // CIR: cir.store %[[ADD]], %[[RET]] : !s32i, !cir.ptr<!s32i>
318+ // CIR: %[[TMP:.*]] = cir.load %[[RET]] : !cir.ptr<!s32i>, !s32i
319+ // CIR: cir.return %[[TMP]] : !s32i
320+
321+ // LLVM: %[[RET:.*]] = alloca i32, i64 1, align 4
322+ // LLVM: %[[COMPLEX_A:.*]] = load { i32, i32 }, ptr {{.*}}, align 4
323+ // LLVM: %[[A_IMAG:.*]] = extractvalue { i32, i32 } %[[COMPLEX_A]], 1
324+ // LLVM: %[[COMPLEX_B:.*]] = load { i32, i32 }, ptr {{.*}}, align 4
325+ // LLVM: %[[B_IMAG:.*]] = extractvalue { i32, i32 } %[[COMPLEX_B]], 1
326+ // LLVM: %[[ADD:.*]] = add nsw i32 %[[A_IMAG]], %[[B_IMAG]]
327+ // LLVM: store i32 %[[ADD]], ptr %[[RET]], align 4
328+ // LLVM: %[[TMP:.*]] = load i32, ptr %[[RET]], align 4
329+ // LLVM: ret i32 %[[TMP]]
330+
331+ // OGCG: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, align 4
332+ // OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
333+ // OGCG: %[[A_IMAG:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 1
334+ // OGCG: %[[TMP_A:.*]] = load i32, ptr %[[A_IMAG]], align 4
335+ // OGCG: %[[B_IMAG:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 1
336+ // OGCG: %[[TMP_B:.*]] = load i32, ptr %[[B_IMAG]], align 4
337+ // OGCG: %[[ADD:.*]] = add nsw i32 %[[TMP_A]], %[[TMP_B]]
338+ // OGCG: ret i32 %[[ADD]]
339+
284340int foo17 (int _Complex a, int _Complex b) {
285341 return __real__ a + __real__ b;
286342}
@@ -312,4 +368,4 @@ int foo17(int _Complex a, int _Complex b) {
312368// OGCG: %[[B_REAL:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 0
313369// OGCG: %[[TMP_B:.*]] = load i32, ptr %[[B_REAL]], align 4
314370// OGCG: %[[ADD:.*]] = add nsw i32 %[[TMP_A]], %[[TMP_B]]
315- // OGCG: ret i32 %[[ADD]]
371+ // OGCG: ret i32 %[[ADD]]
0 commit comments