Skip to content

Commit b7cb348

Browse files
authored
[CIR] Enable floating point casts (#144142)
We already had the code in place to emit CIR floating point cast ops that get lowered to fpext or fptrunc, but we weren't calling the function to emit that cast from ScalarExprEmitter::emitScalarCast. This change adds that call.
1 parent acc58ac commit b7cb348

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
346346
assert(!cir::MissingFeatures::fpConstraints());
347347
castKind = cir::CastKind::float_to_int;
348348
} else if (mlir::isa<cir::CIRFPTypeInterface>(dstTy)) {
349-
cgf.getCIRGenModule().errorNYI("floating point casts");
350-
return cgf.createDummyValue(src.getLoc(), dstType);
349+
// TODO: split this to createFPExt/createFPTrunc
350+
return builder.createFloatingCast(src, fullDstTy);
351351
} else {
352352
llvm_unreachable("Internal error: Cast to unexpected type");
353353
}

clang/test/CIR/CodeGen/cast.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ int cStyleCasts_0(unsigned x1, int x2, float x3, short x4, double x5) {
7373
// LLVM: %{{[0-9]+}} = fcmp une float %{{[0-9]+}}, 0.000000e+00
7474
// LLVM: %{{[0-9]+}} = zext i1 %{{[0-9]+}} to i8
7575

76+
double d2 = f; // float to double
77+
// CIR: %{{[0-9]+}} = cir.cast(floating, %{{[0-9]+}} : !cir.float), !cir.double
78+
// LLVM: %{{[0-9]+}} = fpext float %{{[0-9]+}} to double
79+
80+
f = d2; // double to float
81+
// CIR: %{{[0-9]+}} = cir.cast(floating, %{{[0-9]+}} : !cir.double), !cir.float
82+
// LLVM: %{{[0-9]+}} = fptrunc double %{{[0-9]+}} to float
83+
7684
return 0;
7785
}
7886

0 commit comments

Comments
 (0)