Skip to content

Commit 097b756

Browse files
authored
[CIR][CIRGen][Builtin] add __builtin_tan (#1502)
Closes #1354.
1 parent fffcd5a commit 097b756

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4752,6 +4752,7 @@ def RoundOp : UnaryFPToFPBuiltinOp<"round", "RoundOp">;
47524752
def RoundEvenOp : UnaryFPToFPBuiltinOp<"roundeven", "RoundEvenOp">;
47534753
def SinOp : UnaryFPToFPBuiltinOp<"sin", "SinOp">;
47544754
def SqrtOp : UnaryFPToFPBuiltinOp<"sqrt", "SqrtOp">;
4755+
def TanOp : UnaryFPToFPBuiltinOp<"tan", "TanOp">;
47554756
def TruncOp : UnaryFPToFPBuiltinOp<"trunc", "FTruncOp">;
47564757

47574758
def AbsOp : CIR_Op<"abs", [Pure, SameOperandsAndResultType]> {

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,8 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
896896
case Builtin::BI__builtin_tanf16:
897897
case Builtin::BI__builtin_tanl:
898898
case Builtin::BI__builtin_tanf128:
899-
llvm_unreachable("Builtin::BItan like NYI");
899+
assert(!cir::MissingFeatures::fastMathFlags());
900+
return emitUnaryMaybeConstrainedFPBuiltin<cir::TanOp>(*this, *E);
900901

901902
case Builtin::BItanh:
902903
case Builtin::BItanhf:

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

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,74 @@ long double call_sqrtl(long double f) {
11591159
// LLVM: }
11601160
}
11611161

1162+
// tan
1163+
1164+
float my_tanf(float f) {
1165+
return __builtin_tanf(f);
1166+
// CHECK: cir.func @my_tanf
1167+
// CHECK: {{.+}} = cir.tan {{.+}} : !cir.float
1168+
1169+
// LLVM: define dso_local float @my_tanf(float %0)
1170+
// LLVM: %{{.+}} = call float @llvm.tan.f32(float %{{.+}})
1171+
// LLVM: }
1172+
}
1173+
1174+
double my_tan(double f) {
1175+
return __builtin_tan(f);
1176+
// CHECK: cir.func @my_tan
1177+
// CHECK: {{.+}} = cir.tan {{.+}} : !cir.double
1178+
1179+
// LLVM: define dso_local double @my_tan(double %0)
1180+
// LLVM: %{{.+}} = call double @llvm.tan.f64(double %{{.+}})
1181+
// LLVM: }
1182+
}
1183+
1184+
long double my_tanl(long double f) {
1185+
return __builtin_tanl(f);
1186+
// CHECK: cir.func @my_tanl
1187+
// CHECK: {{.+}} = cir.tan {{.+}} : !cir.long_double<!cir.f80>
1188+
// AARCH64: {{.+}} = cir.tan {{.+}} : !cir.long_double<!cir.double>
1189+
1190+
// LLVM: define dso_local x86_fp80 @my_tanl(x86_fp80 %0)
1191+
// LLVM: %{{.+}} = call x86_fp80 @llvm.tan.f80(x86_fp80 %{{.+}})
1192+
// LLVM: }
1193+
}
1194+
1195+
float tanf(float);
1196+
double tan(double);
1197+
long double tanl(long double);
1198+
1199+
float call_tanf(float f) {
1200+
return tanf(f);
1201+
// CHECK: cir.func @call_tanf
1202+
// CHECK: {{.+}} = cir.tan {{.+}} : !cir.float
1203+
1204+
// LLVM: define dso_local float @call_tanf(float %0)
1205+
// LLVM: %{{.+}} = call float @llvm.tan.f32(float %{{.+}})
1206+
// LLVM: }
1207+
}
1208+
1209+
double call_tan(double f) {
1210+
return tan(f);
1211+
// CHECK: cir.func @call_tan
1212+
// CHECK: {{.+}} = cir.tan {{.+}} : !cir.double
1213+
1214+
// LLVM: define dso_local double @call_tan(double %0)
1215+
// LLVM: %{{.+}} = call double @llvm.tan.f64(double %{{.+}})
1216+
// LLVM: }
1217+
}
1218+
1219+
long double call_tanl(long double f) {
1220+
return tanl(f);
1221+
// CHECK: cir.func @call_tanl
1222+
// CHECK: {{.+}} = cir.tan {{.+}} : !cir.long_double<!cir.f80>
1223+
// AARCH64: {{.+}} = cir.tan {{.+}} : !cir.long_double<!cir.double>
1224+
1225+
// LLVM: define dso_local x86_fp80 @call_tanl(x86_fp80 %0)
1226+
// LLVM: %{{.+}} = call x86_fp80 @llvm.tan.f80(x86_fp80 %{{.+}})
1227+
// LLVM: }
1228+
}
1229+
11621230
// trunc
11631231

11641232
float my_truncf(float f) {

0 commit comments

Comments
 (0)