[clang] [CIR] Upstream FPToFP Builtin CeilOp (PR #166052)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 2 01:33:45 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Amr Hesham (AmrDeveloper)
<details>
<summary>Changes</summary>
Upstream the FPToFP Builtin CeilOp
---
Full diff: https://github.com/llvm/llvm-project/pull/166052.diff
4 Files Affected:
- (modified) clang/include/clang/CIR/Dialect/IR/CIROps.td (+10)
- (modified) clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp (+11)
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+8)
- (modified) clang/test/CIR/CodeGen/builtins-floating-point.c (+9-2)
``````````diff
diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 2b361ed0982c6..dc56db1bbd4ea 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -4171,6 +4171,16 @@ def CIR_ATanOp : CIR_UnaryFPToFPBuiltinOp<"atan", "ATanOp"> {
}];
}
+def CIR_CeilOp : CIR_UnaryFPToFPBuiltinOp<"ceil", "FCeilOp"> {
+ let summary = "Computes the ceiling of the specified value";
+ let description = [{
+ `cir.ceil` computes the ceiling of a given value and returns a result
+ of the same type.
+
+ Floating-point exceptions are ignored, and it does not set `errno`.
+ }];
+}
+
def CIR_CosOp : CIR_UnaryFPToFPBuiltinOp<"cos", "CosOp"> {
let summary = "Computes the floating-point cosine value";
let description = [{
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index e35100ffe4b6b..d9b9e3b877b50 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -211,6 +211,17 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
assert(!cir::MissingFeatures::fastMathFlags());
return emitUnaryMaybeConstrainedFPBuiltin<cir::CosOp>(*this, *e);
+ case Builtin::BIceil:
+ case Builtin::BIceilf:
+ case Builtin::BIceill:
+ case Builtin::BI__builtin_ceil:
+ case Builtin::BI__builtin_ceilf:
+ case Builtin::BI__builtin_ceilf16:
+ case Builtin::BI__builtin_ceill:
+ case Builtin::BI__builtin_ceilf128:
+ assert(!cir::MissingFeatures::fastMathFlags());
+ return emitUnaryMaybeConstrainedFPBuiltin<cir::CeilOp>(*this, *e);
+
case Builtin::BIfabs:
case Builtin::BIfabsf:
case Builtin::BIfabsl:
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index 5a6193fa8d840..d94108294a9a3 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -1336,6 +1336,14 @@ mlir::LogicalResult CIRToLLVMATanOpLowering::matchAndRewrite(
return mlir::success();
}
+mlir::LogicalResult CIRToLLVMCeilOpLowering::matchAndRewrite(
+ cir::CeilOp op, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const {
+ mlir::Type resTy = typeConverter->convertType(op.getType());
+ rewriter.replaceOpWithNewOp<mlir::LLVM::FCeilOp>(op, resTy, adaptor.getSrc());
+ return mlir::success();
+}
+
mlir::LogicalResult CIRToLLVMAllocaOpLowering::matchAndRewrite(
cir::AllocaOp op, OpAdaptor adaptor,
mlir::ConversionPatternRewriter &rewriter) const {
diff --git a/clang/test/CIR/CodeGen/builtins-floating-point.c b/clang/test/CIR/CodeGen/builtins-floating-point.c
index 193cc172d37d2..8bdc43c59dc6f 100644
--- a/clang/test/CIR/CodeGen/builtins-floating-point.c
+++ b/clang/test/CIR/CodeGen/builtins-floating-point.c
@@ -7,14 +7,21 @@
float cosf(float f) {
return __builtin_cosf(f);
- // CHECK: %{{.*}} = cir.cos {{.*}} : !cir.float
+ // CIR: %{{.*}} = cir.cos %{{.*}} : !cir.float
// LLVM: %{{.*}} = call float @llvm.cos.f32(float %{{.*}})
// OGCG: %{{.*}} = call float @llvm.cos.f32(float %{{.*}})
}
double cos(double f) {
return __builtin_cos(f);
- // CIR: {{.+}} = cir.cos {{.+}} : !cir.double
+ // CIR: %{{.*}} = cir.cos %{{.*}} : !cir.double
// LLVM: %{{.*}} = call double @llvm.cos.f64(double %{{.*}})
// OGCG: %{{.*}} = call double @llvm.cos.f64(double %{{.*}})
}
+
+float ceil(float f) {
+ return __builtin_ceilf(f);
+ // CIR: %{{.*}} = cir.ceil %{{.*}} : !cir.float
+ // LLVM: %{{.*}} = call float @llvm.ceil.f32(float %{{.*}})
+ // OGCG: %{{.*}} = call float @llvm.ceil.f32(float %{{.*}})
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/166052
More information about the cfe-commits
mailing list