Skip to content

Commit 74aa2b7

Browse files
authored
[CIR] Implement UO real on result from imag with type promotion (llvm#160996)
Implement UO real on the result from imag with type promotion Issue: llvm#141365
1 parent 7de73c4 commit 74aa2b7

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,9 +1278,6 @@ mlir::Value ScalarExprEmitter::emitPromoted(const Expr *e,
12781278
} else if (const auto *uo = dyn_cast<UnaryOperator>(e)) {
12791279
switch (uo->getOpcode()) {
12801280
case UO_Imag:
1281-
cgf.cgm.errorNYI(e->getSourceRange(),
1282-
"ScalarExprEmitter::emitPromoted unary imag");
1283-
return {};
12841281
case UO_Real:
12851282
return VisitRealImag(uo, promotionType);
12861283
case UO_Minus:

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,3 +1270,40 @@ void real_on_scalar_from_real_with_type_promotion() {
12701270
// OGCG: %[[A_REAL_F32:.*]] = fpext half %[[A_REAL]] to float
12711271
// OGCG: %[[A_REAL_F16:.*]] = fptrunc float %[[A_REAL_F32]] to half
12721272
// OGCG: store half %[[A_REAL_F16]], ptr %[[B_ADDR]], align 2
1273+
1274+
void real_on_scalar_from_imag_with_type_promotion() {
1275+
_Float16 _Complex a;
1276+
_Float16 b = __real__(__imag__ a);
1277+
}
1278+
1279+
// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.complex<!cir.f16>, !cir.ptr<!cir.complex<!cir.f16>>, ["a"]
1280+
// CIR: %[[B_ADDR:.*]] = cir.alloca !cir.f16, !cir.ptr<!cir.f16>, ["b", init]
1281+
// CIR: %[[TMP_A:.*]] = cir.load{{.*}} %[[A_ADDR]] : !cir.ptr<!cir.complex<!cir.f16>>, !cir.complex<!cir.f16>
1282+
// CIR: %[[A_REAL:.*]] = cir.complex.real %[[TMP_A]] : !cir.complex<!cir.f16> -> !cir.f16
1283+
// CIR: %[[A_IMAG:.*]] = cir.complex.imag %[[TMP_A]] : !cir.complex<!cir.f16> -> !cir.f16
1284+
// CIR: %[[A_REAL_F32:.*]] = cir.cast(floating, %[[A_REAL]] : !cir.f16), !cir.float
1285+
// CIR: %[[A_IMAG_F32:.*]] = cir.cast(floating, %[[A_IMAG]] : !cir.f16), !cir.float
1286+
// CIR: %[[A_COMPLEX_F32:.*]] = cir.complex.create %[[A_REAL_F32]], %[[A_IMAG_F32]] : !cir.float -> !cir.complex<!cir.float>
1287+
// CIR: %[[A_IMAG_F32:.*]] = cir.complex.imag %[[A_COMPLEX_F32]] : !cir.complex<!cir.float> -> !cir.float
1288+
// CIR: %[[A_IMAG_F16:.*]] = cir.cast(floating, %[[A_IMAG_F32]] : !cir.float), !cir.f16
1289+
// CIR: cir.store{{.*}} %[[A_IMAG_F16]], %[[B_ADDR]] : !cir.f16, !cir.ptr<!cir.f16>
1290+
1291+
// LLVM: %[[A_ADDR:.*]] = alloca { half, half }, i64 1, align 2
1292+
// LLVM: %[[B_ADDR]] = alloca half, i64 1, align 2
1293+
// LLVM: %[[TMP_A:.*]] = load { half, half }, ptr %[[A_ADDR]], align 2
1294+
// LLVM: %[[A_REAL:.*]] = extractvalue { half, half } %[[TMP_A]], 0
1295+
// LLVM: %[[A_IMAG:.*]] = extractvalue { half, half } %[[TMP_A]], 1
1296+
// LLVM: %[[A_REAL_F32:.*]] = fpext half %[[A_REAL]] to float
1297+
// LLVM: %[[A_IMAG_F32:.*]] = fpext half %[[A_IMAG]] to float
1298+
// LLVM: %[[TMP_A_COMPLEX_F32:.*]] = insertvalue { float, float } {{.*}}, float %[[A_REAL_F32]], 0
1299+
// LLVM: %[[A_COMPLEX_F32:.*]] = insertvalue { float, float } %[[TMP_A_COMPLEX_F32]], float %[[A_IMAG_F32]], 1
1300+
// LLVM: %[[A_IMAG_F16:.*]] = fptrunc float %[[A_IMAG_F32]] to half
1301+
// LLVM: store half %[[A_IMAG_F16]], ptr %[[B_ADDR]], align 2
1302+
1303+
// OGCG: %[[A_ADDR:.*]] = alloca { half, half }, align 2
1304+
// OGCG: %[[B_ADDR:.*]] = alloca half, align 2
1305+
// OGCG: %[[A_IMAG_PTR:.*]] = getelementptr inbounds nuw { half, half }, ptr %[[A_ADDR]], i32 0, i32 1
1306+
// OGCG: %[[A_IMAG:.*]] = load half, ptr %[[A_IMAG_PTR]], align 2
1307+
// OGCG: %[[A_IMAG_F32:.*]] = fpext half %[[A_IMAG]] to float
1308+
// OGCG: %[[A_IMAG_F16:.*]] = fptrunc float %[[A_IMAG_F32]] to half
1309+
// OGCG: store half %[[A_IMAG_F16]], ptr %[[B_ADDR]], align 2

0 commit comments

Comments
 (0)