[clang] [CIR] Upstream missing support for floating point unary operator (PR #193215)

Haocong Lu via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 27 22:10:26 PDT 2026


================
@@ -690,18 +690,27 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
 
       if (type->isHalfType() &&
           !cgf.getContext().getLangOpts().NativeHalfType) {
-        cgf.cgm.errorNYI(e->getSourceRange(), "Unary inc/dec half");
-        return {};
+        // Another special case: half FP increment should be done via float
+        if (cgf.getContext().getTargetInfo().useFP16ConversionIntrinsics()) {
+          mlir::Location loc = cgf.getLoc(e->getSourceRange());
+          cgf.cgm.errorNYI(loc, "cast via llvm.convert.from.fp16");
+        } else {
+          value = builder.createFloatingCast(input, builder.getSingleTy());
+        }
       }
 
-      if (mlir::isa<cir::SingleType, cir::DoubleType, cir::LongDoubleType>(
-              value.getType())) {
-        // Create the inc/dec operation.
-        // NOTE(CIR): clang calls CreateAdd but folds this to a unary op
-        value = emitIncOrDec(e, value);
-      } else {
-        cgf.cgm.errorNYI(e->getSourceRange(), "Unary inc/dec other fp type");
-        return {};
+      // Create the inc/dec operation.
+      // NOTE(CIR): clang calls CreateAdd but folds this to a unary op
+      value = emitIncOrDec(e, value);
----------------
Luhaocong wrote:

I have added tests for `__float128`  and `long double(x86-fp80)`

https://github.com/llvm/llvm-project/pull/193215


More information about the cfe-commits mailing list