Skip to content

Commit f205e35

Browse files
authored
[CIR] Upstream GenericSelectionExpr for ComplexType (#146265)
Upstream the GenericSelectionExpr for ComplexType #141365
1 parent 81c9a1a commit f205e35

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
4343
mlir::Value VisitCallExpr(const CallExpr *e);
4444
mlir::Value VisitChooseExpr(ChooseExpr *e);
4545
mlir::Value VisitDeclRefExpr(DeclRefExpr *e);
46+
mlir::Value VisitGenericSelectionExpr(GenericSelectionExpr *e);
4647
mlir::Value VisitImplicitCastExpr(ImplicitCastExpr *e);
4748
mlir::Value VisitInitListExpr(const InitListExpr *e);
4849
mlir::Value VisitImaginaryLiteral(const ImaginaryLiteral *il);
@@ -151,6 +152,11 @@ mlir::Value ComplexExprEmitter::VisitDeclRefExpr(DeclRefExpr *e) {
151152
return emitLoadOfLValue(e);
152153
}
153154

155+
mlir::Value
156+
ComplexExprEmitter::VisitGenericSelectionExpr(GenericSelectionExpr *e) {
157+
return Visit(e->getResultExpr());
158+
}
159+
154160
mlir::Value ComplexExprEmitter::VisitImplicitCastExpr(ImplicitCastExpr *e) {
155161
// Unlike for scalars, we don't have to worry about function->ptr demotion
156162
// here.

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,34 @@ bool foo19(double _Complex a, double _Complex b) {
442442
// OGCG: %[[CMP_IMAG:.*]] = fcmp oeq double %[[A_IMAG]], %[[B_IMAG]]
443443
// OGCG: %[[RESULT:.*]] = and i1 %[[CMP_REAL]], %[[CMP_IMAG]]
444444

445+
void foo23(int _Complex a, int _Complex b) {
446+
float _Complex f;
447+
int _Complex c = _Generic(a, int _Complex: b, default: f);
448+
}
449+
450+
// CIR: %[[COMPLEX_A:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a", init]
451+
// CIR: %[[COMPLEX_B:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["b", init]
452+
// CIR: %[[COMPLEX_F:.*]] = cir.alloca !cir.complex<!cir.float>, !cir.ptr<!cir.complex<!cir.float>>, ["f"]
453+
// CIR: %[[RESULT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c", init]
454+
// CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX_B]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
455+
// CIR: cir.store{{.*}} %[[TMP]], %[[RESULT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
456+
457+
// LLVM: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, i64 1, align 4
458+
// LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4
459+
// LLVM: %[[COMPLEX_F:.*]] = alloca { float, float }, i64 1, align 4
460+
// LLVM: %[[RESULT:.*]] = alloca { i32, i32 }, i64 1, align 4
461+
// LLVM: %[[TMP:.*]] = load { i32, i32 }, ptr %[[COMPLEX_B]], align 4
462+
// LLVM: store { i32, i32 } %[[TMP]], ptr %[[RESULT]], align 4
463+
464+
// OGCG: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, align 4
465+
// OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
466+
// OGCG: %[[COMPLEX_F:.*]] = alloca { float, float }, align 4
467+
// OGCG: %[[RESULT:.*]] = alloca { i32, i32 }, align 4
468+
// OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 0
469+
// OGCG: %[[B_REAL:.*]] = load i32, ptr %[[B_REAL_PTR]], align 4
470+
// OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 1
471+
// OGCG: %[[B_IMAG:.*]] = load i32, ptr %[[B_IMAG_PTR]], align 4
472+
// OGCG: %[[RESULT_REAL_PT:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 0
473+
// OGCG: %[[RESULT_IMAG_PT:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 1
474+
// OGCG: store i32 %[[B_REAL]], ptr %[[RESULT_REAL_PT]], align 4
475+
// OGCG: store i32 %[[B_IMAG]], ptr %[[RESULT_IMAG_PT]], align 4

0 commit comments

Comments
 (0)