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

Sirui Mu via cfe-commits cfe-commits at lists.llvm.org
Sun Sep 20 07:24:47 PDT 2026


================
@@ -905,14 +887,46 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
     return builder.createOrFold<cir::MinusOp>(loc, operand, nsw);
   }
 
-  mlir::Value emitIncOrDec(const UnaryOperator *e, mlir::Value input,
-                           bool nsw = false) {
+  mlir::Value emitIntIncOrDec(const UnaryOperator *e, mlir::Value input,
+                              bool nsw = false) {
     mlir::Location loc = cgf.getLoc(e->getSourceRange().getBegin());
     return e->isIncrementOp()
                ? builder.createOrFold<cir::IncOp>(loc, input, nsw)
                : builder.createOrFold<cir::DecOp>(loc, input, nsw);
   }
 
+  mlir::Value emitFloatIncOrDec(const UnaryOperator *e, mlir::Value input) {
+    assert(cir::isFPOrVectorOfFPType(input.getType()) &&
+           "Expect floating-point operand");
+    mlir::Location loc = cgf.getLoc(e->getSourceRange().getBegin());
+
+    if (auto vecType = mlir::dyn_cast<cir::VectorType>(input.getType())) {
+      mlir::Type fpScalarType = vecType.getElementType();
+      auto fpInterface = mlir::cast<cir::FPTypeInterface>(fpScalarType);
+      auto amount = llvm::APFloat::getOne(fpInterface.getFloatSemantics(),
+                                          /*Negative=*/e->isDecrementOp());
+      mlir::Value amtValue = builder.getConstFP(loc, fpScalarType, amount);
+      amtValue = cir::VecSplatOp::create(builder, loc, vecType, amtValue);
+      return builder.createFAdd(loc, input, amtValue);
+    } else {
----------------
Lancern wrote:

We could just omit this `else` branch since the true branch would return.

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


More information about the cfe-commits mailing list