[clang] [CIR] Upstream missing support for floating point unary operator (PR #193215)
Haocong Lu via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 9 00:35:10 PDT 2026
================
@@ -828,14 +810,48 @@ 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);
+ mlir::Value amount = builder.getConstFP(
+ loc, fpScalarType, llvm::APFloat(fpInterface.getFloatSemantics(), 1));
+ amount = cir::VecSplatOp::create(builder, loc, vecType, amount);
+ return e->isIncrementOp() ? builder.createFAdd(loc, input, amount)
----------------
Luhaocong wrote:
By the way:
1. Is there any advantages of `fadd -1` compared to `fsub 1` in the subsequent LLVM processing ?
2. And `CIR_DecOp` is lowered to `sub 1` now, does this need to be aligned to OGCG ?
https://github.com/llvm/llvm-project/pull/193215
More information about the cfe-commits
mailing list