Math builtin definition tweaks.

There were missed optimizations when the system headers didn't have attributes
in place, specifically:

- Add copysign, exp2, log2, nearbyint, rint and trunc to the list.
  These are functions that get inlined by LLVM's optimizer, but only when they
  have the right attributes.
- Mark copysign, fabs, fmax, fmin and trunc const unconditionally.
  Previously these were only const with -fno-math-errno, but they never set
  errno per POSIX.

For ceil/floor/nearbyint/round I'm not aware of any implementation that sets
errno, but POSIX says it may signal overflow so I left them alone for now.

llvm-svn: 162375
This commit is contained in:
Benjamin Kramer 2012-08-22 18:16:02 +00:00
parent bfda9f75d6
commit 6f0bf8049a
2 changed files with 209 additions and 9 deletions

View File

@ -830,6 +830,10 @@ LIBBUILTIN(ceil, "dd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(ceill, "LdLd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(ceilf, "ff", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(copysign, "ddd", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(copysignl, "LdLdLd", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(copysignf, "fff", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(cos, "dd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(cosl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(cosf, "ff", "fe", "math.h", ALL_LANGUAGES)
@ -838,9 +842,13 @@ LIBBUILTIN(exp, "dd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(expl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(expf, "ff", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fabs, "dd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fabsl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fabsf, "ff", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(exp2, "dd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(exp2l, "LdLd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(exp2f, "ff", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fabs, "dd", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fabsl, "LdLd", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fabsf, "ff", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(floor, "dd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(floorl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
@ -850,22 +858,34 @@ LIBBUILTIN(fma, "dddd", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fmal, "LdLdLdLd", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fmaf, "ffff", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fmax, "ddd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fmaxl, "LdLdLd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fmaxf, "fff", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fmax, "ddd", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fmaxl, "LdLdLd", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fmaxf, "fff", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fmin, "ddd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fminl, "LdLdLd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fminf, "fff", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fmin, "ddd", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fminl, "LdLdLd", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(fminf, "fff", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(log, "dd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(logl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(logf, "ff", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(log2, "dd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(log2l, "LdLd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(log2f, "ff", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(nearbyint, "dd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(nearbyintl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(nearbyintf, "ff", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(pow, "ddd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(powl, "LdLdLd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(powf, "fff", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(rint, "dd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(rintl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(rintf, "ff", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(round, "dd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(roundl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(roundf, "ff", "fe", "math.h", ALL_LANGUAGES)
@ -882,6 +902,10 @@ LIBBUILTIN(tan, "dd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(tanl, "LdLd", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(tanf, "ff", "fe", "math.h", ALL_LANGUAGES)
LIBBUILTIN(trunc, "dd", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(truncl, "LdLd", "fc", "math.h", ALL_LANGUAGES)
LIBBUILTIN(truncf, "ff", "fc", "math.h", ALL_LANGUAGES)
// Blocks runtime Builtin math library functions
LIBBUILTIN(_Block_object_assign, "vv*vC*iC", "f", "Blocks.h", ALL_LANGUAGES)
LIBBUILTIN(_Block_object_dispose, "vvC*iC", "f", "Blocks.h", ALL_LANGUAGES)

View File

@ -0,0 +1,176 @@
// RUN: %clang_cc1 -triple x86_64-apple-darwin12 -S -o - -emit-llvm %s | FileCheck %s -check-prefix=CHECK-NOERRNO
// RUN: %clang_cc1 -triple x86_64-linux-gnu -S -o - -emit-llvm %s | FileCheck %s -check-prefix=CHECK-ERRNO
// Prototypes.
double acos(double);
long double acosl(long double);
float acosf(float);
double asin(double);
long double asinl(long double);
float asinf(float);
double atan(double);
long double atanl(long double);
float atanf(float);
double atan2(double, double);
long double atan2l(long double, long double);
float atan2f(float, float);
double ceil(double);
long double ceill(long double);
float ceilf(float);
double copysign(double, double);
long double copysignl(long double, long double);
float copysignf(float, float);
double cos(double);
long double cosl(long double);
float cosf(float);
double exp(double);
long double expl(long double);
float expf(float);
double exp2(double);
long double exp2l(long double);
float exp2f(float);
double fabs(double);
long double fabsl(long double);
float fabsf(float);
double floor(double);
long double floorl(long double);
float floorf(float);
double fma(double, double, double);
long double fmal(long double, long double, long double);
float fmaf(float, float, float);
double fmax(double, double);
long double fmaxl(long double, long double);
float fmaxf(float, float);
double fmin(double, double);
long double fminl(long double, long double);
float fminf(float, float);
double log(double);
long double logl(long double);
float logf(float);
double log2(double);
long double log2l(long double);
float log2f(float);
double nearbyint(double);
long double nearbyintl(long double);
float nearbyintf(float);
double pow(double, double);
long double powl(long double, long double);
float powf(float, float);
double rint(double);
long double rintl(long double);
float rintf(float);
double round(double);
long double roundl(long double);
float roundf(float);
double sin(double);
long double sinl(long double);
float sinf(float);
double sqrt(double);
long double sqrtl(long double);
float sqrtf(float);
double tan(double);
long double tanl(long double);
float tanf(float);
double trunc(double);
long double truncl(long double);
float truncf(float);
// Force emission of the declare statements.
void *use[] = {
acos, acosl, acosf, asin, asinl, asinf, atan, atanl, atanf, atan2, atan2l,
atan2f, ceil, ceill, ceilf, copysign, copysignl, copysignf, cos, cosl, cosf,
exp, expl, expf, exp2, exp2l, exp2f, fabs, fabsl, fabsf, floor, floorl,
floorf, fma, fmal, fmaf, fmax, fmaxl, fmaxf, fmin, fminl, fminf, log, logl,
logf, log2, log2l, log2f, nearbyint, nearbyintl, nearbyintf, pow, powl, powf,
rint, rintl, rintf, round, roundl, roundf, sin, sinl, sinf, sqrt, sqrtl,
sqrtf, tan, tanl, tanf, trunc, truncl, truncf
};
// CHECK-NOERRNO: declare double @acos(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @acosl(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @acosf(float) nounwind readnone
// CHECK-NOERRNO: declare double @asin(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @asinl(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @asinf(float) nounwind readnone
// CHECK-NOERRNO: declare double @atan(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @atanl(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @atanf(float) nounwind readnone
// CHECK-NOERRNO: declare double @atan2(double, double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @atan2l(x86_fp80, x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @atan2f(float, float) nounwind readnone
// CHECK-NOERRNO: declare double @ceil(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @ceill(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @ceilf(float) nounwind readnone
// CHECK-NOERRNO: declare double @copysign(double, double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @copysignl(x86_fp80, x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @copysignf(float, float) nounwind readnone
// CHECK-NOERRNO: declare double @cos(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @cosl(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @cosf(float) nounwind readnone
// CHECK-NOERRNO: declare double @exp(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @expl(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @expf(float) nounwind readnone
// CHECK-NOERRNO: declare double @exp2(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @exp2l(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @exp2f(float) nounwind readnone
// CHECK-NOERRNO: declare double @fabs(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @fabsl(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @fabsf(float) nounwind readnone
// CHECK-NOERRNO: declare double @floor(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @floorl(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @floorf(float) nounwind readnone
// CHECK-NOERRNO: declare double @fma(double, double, double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @fmal(x86_fp80, x86_fp80, x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @fmaf(float, float, float) nounwind readnone
// CHECK-NOERRNO: declare double @fmax(double, double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @fmaxl(x86_fp80, x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @fmaxf(float, float) nounwind readnone
// CHECK-NOERRNO: declare double @fmin(double, double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @fminl(x86_fp80, x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @fminf(float, float) nounwind readnone
// CHECK-NOERRNO: declare double @log(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @logl(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @logf(float) nounwind readnone
// CHECK-NOERRNO: declare double @log2(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @log2l(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @log2f(float) nounwind readnone
// CHECK-NOERRNO: declare double @nearbyint(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @nearbyintl(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @nearbyintf(float) nounwind readnone
// CHECK-NOERRNO: declare double @pow(double, double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @powl(x86_fp80, x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @powf(float, float) nounwind readnone
// CHECK-NOERRNO: declare double @rint(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @rintl(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @rintf(float) nounwind readnone
// CHECK-NOERRNO: declare double @round(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @roundl(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @roundf(float) nounwind readnone
// CHECK-NOERRNO: declare double @sin(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @sinl(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @sinf(float) nounwind readnone
// CHECK-NOERRNO: declare double @sqrt(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @sqrtl(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @sqrtf(float) nounwind readnone
// CHECK-NOERRNO: declare double @tan(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @tanl(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @tanf(float) nounwind readnone
// CHECK-NOERRNO: declare double @trunc(double) nounwind readnone
// CHECK-NOERRNO: declare x86_fp80 @truncl(x86_fp80) nounwind readnone
// CHECK-NOERRNO: declare float @truncf(float) nounwind readnone
// CHECK-ERRNO: declare double @copysign(double, double) nounwind readnone
// CHECK-ERRNO: declare x86_fp80 @copysignl(x86_fp80, x86_fp80) nounwind readnone
// CHECK-ERRNO: declare float @copysignf(float, float) nounwind readnone
// CHECK-ERRNO: declare double @fabs(double) nounwind readnone
// CHECK-ERRNO: declare x86_fp80 @fabsl(x86_fp80) nounwind readnone
// CHECK-ERRNO: declare float @fabsf(float) nounwind readnone
// CHECK-ERRNO: declare double @fmax(double, double) nounwind readnone
// CHECK-ERRNO: declare x86_fp80 @fmaxl(x86_fp80, x86_fp80) nounwind readnone
// CHECK-ERRNO: declare float @fmaxf(float, float) nounwind readnone
// CHECK-ERRNO: declare double @fmin(double, double) nounwind readnone
// CHECK-ERRNO: declare x86_fp80 @fminl(x86_fp80, x86_fp80) nounwind readnone
// CHECK-ERRNO: declare float @fminf(float, float) nounwind readnone
// CHECK-ERRNO: declare double @trunc(double) nounwind readnone
// CHECK-ERRNO: declare x86_fp80 @truncl(x86_fp80) nounwind readnone
// CHECK-ERRNO: declare float @truncf(float) nounwind readnone