-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[CIR] Upstream FPToFP Builtin CeilOp #166052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
+38
−2
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-clangir @llvm/pr-subscribers-clang Author: Amr Hesham (AmrDeveloper) ChangesUpstream the FPToFP Builtin CeilOp Full diff: https://github.com/llvm/llvm-project/pull/166052.diff 4 Files Affected:
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 %{{.*}})
+}
|
xlauko
approved these changes
Nov 2, 2025
Contributor
xlauko
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Upstream the FPToFP Builtin CeilOp