From d9b46ba99a30358690ff3b3f1fae59a17556914a Mon Sep 17 00:00:00 2001 From: Iris Shi <0.0@owo.li> Date: Wed, 19 Mar 2025 11:44:11 +0800 Subject: [PATCH 1/2] add test --- .../test/CIR/CodeGen/builtin-floating-point.c | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/clang/test/CIR/CodeGen/builtin-floating-point.c b/clang/test/CIR/CodeGen/builtin-floating-point.c index 2e9b18c51a33..8af6fd7b4ed4 100644 --- a/clang/test/CIR/CodeGen/builtin-floating-point.c +++ b/clang/test/CIR/CodeGen/builtin-floating-point.c @@ -1159,6 +1159,74 @@ long double call_sqrtl(long double f) { // LLVM: } } +// tan + +float my_tanf(float f) { + return __builtin_tanf(f); + // CHECK: cir.func @my_tanf + // CHECK: {{.+}} = cir.tan {{.+}} : !cir.float + + // LLVM: define dso_local float @my_tanf(float %0) + // LLVM: %{{.+}} = call float @llvm.tan.f32(float %{{.+}}) + // LLVM: } +} + +double my_tan(double f) { + return __builtin_tan(f); + // CHECK: cir.func @my_tan + // CHECK: {{.+}} = cir.tan {{.+}} : !cir.double + + // LLVM: define dso_local double @my_tan(double %0) + // LLVM: %{{.+}} = call double @llvm.tan.f64(double %{{.+}}) + // LLVM: } +} + +long double my_tanl(long double f) { + return __builtin_tanl(f); + // CHECK: cir.func @my_tanl + // CHECK: {{.+}} = cir.tan {{.+}} : !cir.long_double + // AARCH64: {{.+}} = cir.tan {{.+}} : !cir.long_double + + // LLVM: define dso_local x86_fp80 @my_tanl(x86_fp80 %0) + // LLVM: %{{.+}} = call x86_fp80 @llvm.tan.f80(x86_fp80 %{{.+}}) + // LLVM: } +} + +float tanf(float); +double tan(double); +long double tanl(long double); + +float call_tanf(float f) { + return tanf(f); + // CHECK: cir.func @call_tanf + // CHECK: {{.+}} = cir.tan {{.+}} : !cir.float + + // LLVM: define dso_local float @call_tanf(float %0) + // LLVM: %{{.+}} = call float @llvm.tan.f32(float %{{.+}}) + // LLVM: } +} + +double call_tan(double f) { + return tan(f); + // CHECK: cir.func @call_tan + // CHECK: {{.+}} = cir.tan {{.+}} : !cir.double + + // LLVM: define dso_local double @call_tan(double %0) + // LLVM: %{{.+}} = call double @llvm.tan.f64(double %{{.+}}) + // LLVM: } +} + +long double call_tanl(long double f) { + return tanl(f); + // CHECK: cir.func @call_tanl + // CHECK: {{.+}} = cir.tan {{.+}} : !cir.long_double + // AARCH64: {{.+}} = cir.tan {{.+}} : !cir.long_double + + // LLVM: define dso_local x86_fp80 @call_tanl(x86_fp80 %0) + // LLVM: %{{.+}} = call x86_fp80 @llvm.tan.f80(x86_fp80 %{{.+}}) + // LLVM: } +} + // trunc float my_truncf(float f) { From 7aad710dd2389ccb9f09898ce013b124ba2f8efb Mon Sep 17 00:00:00 2001 From: Iris Shi <0.0@owo.li> Date: Wed, 19 Mar 2025 11:51:14 +0800 Subject: [PATCH 2/2] [CIR][CIRGen][Builtin] add `__builtin_tan` --- clang/include/clang/CIR/Dialect/IR/CIROps.td | 1 + clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index 75fcdb4d360b..d7e623510824 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -4814,6 +4814,7 @@ def RoundOp : UnaryFPToFPBuiltinOp<"round", "RoundOp">; def RoundEvenOp : UnaryFPToFPBuiltinOp<"roundeven", "RoundEvenOp">; def SinOp : UnaryFPToFPBuiltinOp<"sin", "SinOp">; def SqrtOp : UnaryFPToFPBuiltinOp<"sqrt", "SqrtOp">; +def TanOp : UnaryFPToFPBuiltinOp<"tan", "TanOp">; def TruncOp : UnaryFPToFPBuiltinOp<"trunc", "FTruncOp">; def AbsOp : CIR_Op<"abs", [Pure, SameOperandsAndResultType]> { diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp index 78d96c39396b..075c951f1086 100644 --- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp @@ -896,7 +896,8 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_tanf16: case Builtin::BI__builtin_tanl: case Builtin::BI__builtin_tanf128: - llvm_unreachable("Builtin::BItan like NYI"); + assert(!cir::MissingFeatures::fastMathFlags()); + return emitUnaryMaybeConstrainedFPBuiltin(*this, *E); case Builtin::BItanh: case Builtin::BItanhf: