Skip to content

Commit 70bedc7

Browse files
authored
[CIR] Upstream ChooseExpr for ComplexType (#145163)
This change adds support for ChooseExpr for ComplexType #141365
1 parent b3c5302 commit 70bedc7

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
4141

4242
mlir::Value VisitBinAssign(const BinaryOperator *e);
4343
mlir::Value VisitCallExpr(const CallExpr *e);
44+
mlir::Value VisitChooseExpr(ChooseExpr *e);
4445
mlir::Value VisitDeclRefExpr(DeclRefExpr *e);
4546
mlir::Value VisitImplicitCastExpr(ImplicitCastExpr *e);
4647
mlir::Value VisitInitListExpr(const InitListExpr *e);
@@ -140,6 +141,10 @@ mlir::Value ComplexExprEmitter::VisitCallExpr(const CallExpr *e) {
140141
return cgf.emitCallExpr(e).getValue();
141142
}
142143

144+
mlir::Value ComplexExprEmitter::VisitChooseExpr(ChooseExpr *e) {
145+
return Visit(e->getChosenSubExpr());
146+
}
147+
143148
mlir::Value ComplexExprEmitter::VisitDeclRefExpr(DeclRefExpr *e) {
144149
if (CIRGenFunction::ConstantEmission constant = cgf.tryEmitAsConstant(e))
145150
return emitConstant(constant, e);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
4+
// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
5+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll
6+
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
7+
8+
void foo() {
9+
int _Complex a;
10+
int _Complex b;
11+
int _Complex r = __builtin_choose_expr(true, a, b);
12+
}
13+
14+
// CIR: %[[COMPLEX_A:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a"]
15+
// CIR: %[[COMPLEX_R:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["r", init]
16+
// CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[COMPLEX_A]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
17+
// CIR: cir.store{{.*}} %[[TMP_A]], %[[COMPLEX_R]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
18+
19+
// LLVM: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, i64 1, align 4
20+
// LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4
21+
// LLVM: %[[COMPLEX_R:.*]] = alloca { i32, i32 }, i64 1, align 4
22+
// LLVM: %[[TMP_A:.*]] = load { i32, i32 }, ptr %[[COMPLEX_A]], align 4
23+
// LLVM: store { i32, i32 } %[[TMP_A]], ptr %[[COMPLEX_R]], align 4
24+
25+
// OGCG: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, align 4
26+
// OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
27+
// OGCG: %[[COMPLEX_R:.*]] = alloca { i32, i32 }, align 4
28+
// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 0
29+
// OGCG: %[[A_REAL:.*]] = load i32, ptr %[[A_REAL_PTR]], align 4
30+
// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 1
31+
// OGCG: %[[A_IMAG:.*]] = load i32, ptr %[[A_IMAG_PTR]], align 4
32+
// OGCG: %[[R_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_R]], i32 0, i32 0
33+
// OGCG: %[[R_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_R]], i32 0, i32 1
34+
// OGCG: store i32 %[[A_REAL]], ptr %[[R_REAL_PTR]], align 4
35+
// OGCG: store i32 %[[A_IMAG]], ptr %[[R_IMAG_PTR]], align 4

0 commit comments

Comments
 (0)