Skip to content

Commit 1aa3969

Browse files
authored
[CIR] Upstream UnaryDeref support for ComplexType (#146757)
Upstream UnaryDeref support for ComplexType #141365
1 parent a695d6b commit 1aa3969

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
5252
mlir::Value VisitParenExpr(ParenExpr *e);
5353
mlir::Value
5454
VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *e);
55+
mlir::Value VisitUnaryDeref(const Expr *e);
5556
};
5657
} // namespace
5758

@@ -238,6 +239,10 @@ mlir::Value ComplexExprEmitter::VisitSubstNonTypeTemplateParmExpr(
238239
return Visit(e->getReplacement());
239240
}
240241

242+
mlir::Value ComplexExprEmitter::VisitUnaryDeref(const Expr *e) {
243+
return emitLoadOfLValue(e);
244+
}
245+
241246
LValue CIRGenFunction::emitComplexAssignmentLValue(const BinaryOperator *e) {
242247
assert(e->getOpcode() == BO_Assign && "Expected assign op");
243248

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,31 @@ void foo25() {
626626
// OGCG: %[[INIT_IMAG_PTR:.*]] = getelementptr inbounds nuw { double, double }, ptr %[[INIT]], i32 0, i32 1
627627
// OGCG: store double 1.000000e+00, ptr %[[INIT_REAL_PTR]], align 8
628628
// OGCG: store double 2.000000e+00, ptr %[[INIT_IMAG_PTR]], align 8
629+
630+
void foo26(int _Complex* a) {
631+
int _Complex b = *a;
632+
}
633+
634+
// CIR: %[[COMPLEX_A_PTR:.*]] = cir.alloca !cir.ptr<!cir.complex<!s32i>>, !cir.ptr<!cir.ptr<!cir.complex<!s32i>>>, ["a", init]
635+
// CIR: %[[COMPLEX_B:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["b", init]
636+
// CIR: %[[COMPLEX_A:.*]] = cir.load deref {{.*}} %[[COMPLEX_A_PTR]] : !cir.ptr<!cir.ptr<!cir.complex<!s32i>>>, !cir.ptr<!cir.complex<!s32i>>
637+
// CIR: %[[TMP:.*]] = cir.load{{.*}} %[[COMPLEX_A]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
638+
// CIR: cir.store{{.*}} %[[TMP]], %[[COMPLEX_B]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
639+
640+
// LLVM: %[[COMPLEX_A_PTR:.*]] = alloca ptr, i64 1, align 8
641+
// LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4
642+
// LLVM: %[[COMPLEX_A:.*]] = load ptr, ptr %[[COMPLEX_A_PTR]], align 8
643+
// LLVM: %[[TMP:.*]] = load { i32, i32 }, ptr %[[COMPLEX_A]], align 4
644+
// LLVM: store { i32, i32 } %[[TMP]], ptr %[[COMPLEX_B]], align 4
645+
646+
// OGCG: %[[COMPLEX_A_PTR:.*]] = alloca ptr, align 8
647+
// OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
648+
// OGCG: %[[COMPLEX_A:.*]] = load ptr, ptr %[[COMPLEX_A_PTR]], align 8
649+
// OGCG: %[[A_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 0
650+
// OGCG: %[[A_REAL:.*]] = load i32, ptr %[[A_REAL_PTR]], align 4
651+
// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_A]], i32 0, i32 1
652+
// OGCG: %[[A_IMAG:.*]] = load i32, ptr %[[A_IMAG_PTR]], align 4
653+
// OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 0
654+
// OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 1
655+
// OGCG: store i32 %[[A_REAL]], ptr %[[B_REAL_PTR]], align 4
656+
// OGCG: store i32 %[[A_IMAG]], ptr %[[B_IMAG_PTR]], align 4

0 commit comments

Comments
 (0)