Skip to content

Commit 42b0963

Browse files
committed
[clang] Lower non-builtin sincos[f|l] calls to llvm.sincos.* when -fno-math-errno is set
This will allow vectorizing these calls (after a few more patches). This should not change the codegen for targets that enable the use of AA during the codegen (in `TargetSubtargetInfo::useAA()`). This includes targets such as AArch64. This notably does not include x86 but can be worked around by passing `-mllvm -combiner-global-alias-analysis=true` to clang.
1 parent e0e67a6 commit 42b0963

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3377,6 +3377,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
33773377
return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
33783378
*this, E, Intrinsic::sinh, Intrinsic::experimental_constrained_sinh));
33793379

3380+
case Builtin::BIsincos:
3381+
case Builtin::BIsincosf:
3382+
case Builtin::BIsincosl:
33803383
case Builtin::BI__builtin_sincos:
33813384
case Builtin::BI__builtin_sincosf:
33823385
case Builtin::BI__builtin_sincosf16:

clang/test/CodeGen/AArch64/sincos.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - | FileCheck --check-prefix=NO-MATH-ERRNO %s
2-
// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - | FileCheck --check-prefix=MATH-ERRNO %s
1+
// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - -DUSE_BUILTIN | FileCheck --check-prefix=NO-MATH-ERRNO %s
2+
// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - -DUSE_BUILTIN | FileCheck --check-prefix=MATH-ERRNO %s
3+
// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -O1 %s -o - -DUSE_C_DECL | FileCheck --check-prefix=NO-MATH-ERRNO %s
4+
// RUN: %clang_cc1 -triple=aarch64-gnu-linux -emit-llvm -fmath-errno %s -o - -DUSE_C_DECL | FileCheck --check-prefix=MATH-ERRNO %s
5+
6+
#if defined(USE_BUILTIN)
7+
#define sincos __builtin_sincos
8+
#define sincosf __builtin_sincosf
9+
#define sincosl __builtin_sincosl
10+
#elif defined(USE_C_DECL)
11+
void sincos(double, double*, double*);
12+
void sincosf(float, float*, float*);
13+
void sincosl(long double, long double*, long double*);
14+
#else
15+
#error Expected USE_BUILTIN or USE_C_DECL to be defined.
16+
#endif
317

418
// NO-MATH-ERRNO-LABEL: @sincos_f32
519
// NO-MATH-ERRNO: [[SINCOS:%.*]] = tail call { float, float } @llvm.sincos.f32(float {{.*}})
@@ -12,7 +26,7 @@
1226
// MATH-ERRNO: call void @sincosf(
1327
//
1428
void sincos_f32(float x, float* fp0, float* fp1) {
15-
__builtin_sincosf(x, fp0, fp1);
29+
sincosf(x, fp0, fp1);
1630
}
1731

1832
// NO-MATH-ERRNO-LABEL: @sincos_f64
@@ -26,7 +40,7 @@ void sincos_f32(float x, float* fp0, float* fp1) {
2640
// MATH-ERRNO: call void @sincos(
2741
//
2842
void sincos_f64(double x, double* dp0, double* dp1) {
29-
__builtin_sincos(x, dp0, dp1);
43+
sincos(x, dp0, dp1);
3044
}
3145

3246
// NO-MATH-ERRNO-LABEL: @sincos_f128
@@ -40,5 +54,5 @@ void sincos_f64(double x, double* dp0, double* dp1) {
4054
// MATH-ERRNO: call void @sincosl(
4155
//
4256
void sincos_f128(long double x, long double* ldp0, long double* ldp1) {
43-
__builtin_sincosl(x, ldp0, ldp1);
57+
sincosl(x, ldp0, ldp1);
4458
}

0 commit comments

Comments
 (0)