Skip to content

Commit dbd0122

Browse files
authored
[CIR] Add support the ChooseExpr for scalar (#171882)
Add support the ChooseExpr for scalar expr
1 parent 4dbd16b commit dbd0122

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,8 +1352,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
13521352
}
13531353

13541354
mlir::Value VisitChooseExpr(ChooseExpr *e) {
1355-
cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: choose");
1356-
return {};
1355+
return Visit(e->getChosenSubExpr());
13571356
}
13581357

13591358
mlir::Value VisitObjCStringLiteral(const ObjCStringLiteral *e) {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: %clang_cc1 -std=c++20 -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 -std=c++20 -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 -std=c++20 -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 choose_expr() {
9+
int a = __builtin_choose_expr(1, 2, 3);
10+
}
11+
12+
// CIR: %[[A_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["a", init]
13+
// CIR: %[[CONST_2:.*]] = cir.const #cir.int<2> : !s32i
14+
// CIR: cir.store {{.*}} %[[CONST_2]], %[[A_ADDR]] : !s32i, !cir.ptr<!s32i>
15+
16+
// LLVM: %[[A_ADDR:.*]] = alloca i32, i64 1, align 4
17+
// LLVM: store i32 2, ptr %[[A_ADDR]], align 4
18+
19+
// OGCG: %[[A_ADDR:.*]] = alloca i32, align 4
20+
// OGCG: store i32 2, ptr %[[A_ADDR]], align 4
21+
22+
void choose_expr_non_constant() {
23+
int a;
24+
int b;
25+
int c = __builtin_choose_expr(1, a, b);
26+
}
27+
28+
// CIR: %[[A_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["a"]
29+
// CIR: %[[B_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["b"]
30+
// CIR: %[[C_ADDR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["c", init]
31+
// CIR: %[[TMP_A:.*]] = cir.load {{.*}} %[[A_ADDR]] : !cir.ptr<!s32i>, !s32i
32+
// CIR: cir.store {{.*}} %[[TMP_A]], %[[C_ADDR]] : !s32i, !cir.ptr<!s32i>
33+
34+
// LLVM: %[[A_ADDR:.*]] = alloca i32, i64 1, align 4
35+
// LLVM: %[[B_ADDR:.*]] = alloca i32, i64 1, align 4
36+
// LLVM: %[[C_ADDR:.*]] = alloca i32, i64 1, align 4
37+
// LLVM: %[[TMP_A:.*]] = load i32, ptr %[[A_ADDR]], align 4
38+
// LLVM: store i32 %[[TMP_A]], ptr %[[C_ADDR]], align 4
39+
40+
// OGCG: %[[A_ADDR:.*]] = alloca i32, align 4
41+
// OGCG: %[[B_ADDR:.*]] = alloca i32, align 4
42+
// OGCG: %[[C_ADDR:.*]] = alloca i32, align 4
43+
// OGCG: %[[TMP_A:.*]] = load i32, ptr %[[A_ADDR]], align 4
44+
// OGCG: store i32 %[[TMP_A]], ptr %[[C_ADDR]], align 4

0 commit comments

Comments
 (0)