Skip to content

Commit 2de5a17

Browse files
authored
[CIR] Upstream FPToFP Builtin CeilOp (llvm#166052)
Upstream the FPToFP Builtin CeilOp
1 parent 10349ca commit 2de5a17

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4171,6 +4171,16 @@ def CIR_ATanOp : CIR_UnaryFPToFPBuiltinOp<"atan", "ATanOp"> {
41714171
}];
41724172
}
41734173

4174+
def CIR_CeilOp : CIR_UnaryFPToFPBuiltinOp<"ceil", "FCeilOp"> {
4175+
let summary = "Computes the ceiling of the specified value";
4176+
let description = [{
4177+
`cir.ceil` computes the ceiling of a given value and returns a result
4178+
of the same type.
4179+
4180+
Floating-point exceptions are ignored, and it does not set `errno`.
4181+
}];
4182+
}
4183+
41744184
def CIR_CosOp : CIR_UnaryFPToFPBuiltinOp<"cos", "CosOp"> {
41754185
let summary = "Computes the floating-point cosine value";
41764186
let description = [{

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,17 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
211211
assert(!cir::MissingFeatures::fastMathFlags());
212212
return emitUnaryMaybeConstrainedFPBuiltin<cir::CosOp>(*this, *e);
213213

214+
case Builtin::BIceil:
215+
case Builtin::BIceilf:
216+
case Builtin::BIceill:
217+
case Builtin::BI__builtin_ceil:
218+
case Builtin::BI__builtin_ceilf:
219+
case Builtin::BI__builtin_ceilf16:
220+
case Builtin::BI__builtin_ceill:
221+
case Builtin::BI__builtin_ceilf128:
222+
assert(!cir::MissingFeatures::fastMathFlags());
223+
return emitUnaryMaybeConstrainedFPBuiltin<cir::CeilOp>(*this, *e);
224+
214225
case Builtin::BIfabs:
215226
case Builtin::BIfabsf:
216227
case Builtin::BIfabsl:

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,14 @@ mlir::LogicalResult CIRToLLVMATanOpLowering::matchAndRewrite(
13361336
return mlir::success();
13371337
}
13381338

1339+
mlir::LogicalResult CIRToLLVMCeilOpLowering::matchAndRewrite(
1340+
cir::CeilOp op, OpAdaptor adaptor,
1341+
mlir::ConversionPatternRewriter &rewriter) const {
1342+
mlir::Type resTy = typeConverter->convertType(op.getType());
1343+
rewriter.replaceOpWithNewOp<mlir::LLVM::FCeilOp>(op, resTy, adaptor.getSrc());
1344+
return mlir::success();
1345+
}
1346+
13391347
mlir::LogicalResult CIRToLLVMAllocaOpLowering::matchAndRewrite(
13401348
cir::AllocaOp op, OpAdaptor adaptor,
13411349
mlir::ConversionPatternRewriter &rewriter) const {

clang/test/CIR/CodeGen/builtins-floating-point.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@
77

88
float cosf(float f) {
99
return __builtin_cosf(f);
10-
// CHECK: %{{.*}} = cir.cos {{.*}} : !cir.float
10+
// CIR: %{{.*}} = cir.cos %{{.*}} : !cir.float
1111
// LLVM: %{{.*}} = call float @llvm.cos.f32(float %{{.*}})
1212
// OGCG: %{{.*}} = call float @llvm.cos.f32(float %{{.*}})
1313
}
1414

1515
double cos(double f) {
1616
return __builtin_cos(f);
17-
// CIR: {{.+}} = cir.cos {{.+}} : !cir.double
17+
// CIR: %{{.*}} = cir.cos %{{.*}} : !cir.double
1818
// LLVM: %{{.*}} = call double @llvm.cos.f64(double %{{.*}})
1919
// OGCG: %{{.*}} = call double @llvm.cos.f64(double %{{.*}})
2020
}
21+
22+
float ceil(float f) {
23+
return __builtin_ceilf(f);
24+
// CIR: %{{.*}} = cir.ceil %{{.*}} : !cir.float
25+
// LLVM: %{{.*}} = call float @llvm.ceil.f32(float %{{.*}})
26+
// OGCG: %{{.*}} = call float @llvm.ceil.f32(float %{{.*}})
27+
}

0 commit comments

Comments
 (0)