[llvm] r322010 - [TargetLibraryInfo] fix finite mathlib function availability
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 8 09:38:09 PST 2018
Author: spatel
Date: Mon Jan 8 09:38:09 2018
New Revision: 322010
URL: http://llvm.org/viewvc/llvm-project?rev=322010&view=rev
Log:
[TargetLibraryInfo] fix finite mathlib function availability
This patch was part of:
https://reviews.llvm.org/D41338
...but we can expose the bug in IR via constant propagation
as shown in the test. Unless the triple includes 'linux', we
should not fold these because the functions don't exist on
other platforms (yet?).
Modified:
llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp
llvm/trunk/test/Transforms/ConstProp/calls-math-finite.ll
Modified: llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp?rev=322010&r1=322009&r2=322010&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp Mon Jan 8 09:38:09 2018
@@ -245,50 +245,6 @@ static void initialize(TargetLibraryInfo
TLI.setUnavailable(LibFunc_tanhf);
}
- // These definitions are due to math-finite.h header on Linux
- TLI.setUnavailable(LibFunc_acos_finite);
- TLI.setUnavailable(LibFunc_acosf_finite);
- TLI.setUnavailable(LibFunc_acosl_finite);
- TLI.setUnavailable(LibFunc_acosh_finite);
- TLI.setUnavailable(LibFunc_acoshf_finite);
- TLI.setUnavailable(LibFunc_acoshl_finite);
- TLI.setUnavailable(LibFunc_asin_finite);
- TLI.setUnavailable(LibFunc_asinf_finite);
- TLI.setUnavailable(LibFunc_asinl_finite);
- TLI.setUnavailable(LibFunc_atan2_finite);
- TLI.setUnavailable(LibFunc_atan2f_finite);
- TLI.setUnavailable(LibFunc_atan2l_finite);
- TLI.setUnavailable(LibFunc_atanh_finite);
- TLI.setUnavailable(LibFunc_atanhf_finite);
- TLI.setUnavailable(LibFunc_atanhl_finite);
- TLI.setUnavailable(LibFunc_cosh_finite);
- TLI.setUnavailable(LibFunc_coshf_finite);
- TLI.setUnavailable(LibFunc_coshl_finite);
- TLI.setUnavailable(LibFunc_exp10_finite);
- TLI.setUnavailable(LibFunc_exp10f_finite);
- TLI.setUnavailable(LibFunc_exp10l_finite);
- TLI.setUnavailable(LibFunc_exp2_finite);
- TLI.setUnavailable(LibFunc_exp2f_finite);
- TLI.setUnavailable(LibFunc_exp2l_finite);
- TLI.setUnavailable(LibFunc_exp_finite);
- TLI.setUnavailable(LibFunc_expf_finite);
- TLI.setUnavailable(LibFunc_expl_finite);
- TLI.setUnavailable(LibFunc_log10_finite);
- TLI.setUnavailable(LibFunc_log10f_finite);
- TLI.setUnavailable(LibFunc_log10l_finite);
- TLI.setUnavailable(LibFunc_log2_finite);
- TLI.setUnavailable(LibFunc_log2f_finite);
- TLI.setUnavailable(LibFunc_log2l_finite);
- TLI.setUnavailable(LibFunc_log_finite);
- TLI.setUnavailable(LibFunc_logf_finite);
- TLI.setUnavailable(LibFunc_logl_finite);
- TLI.setUnavailable(LibFunc_pow_finite);
- TLI.setUnavailable(LibFunc_powf_finite);
- TLI.setUnavailable(LibFunc_powl_finite);
- TLI.setUnavailable(LibFunc_sinh_finite);
- TLI.setUnavailable(LibFunc_sinhf_finite);
- TLI.setUnavailable(LibFunc_sinhl_finite);
-
// Win32 does *not* provide provide these functions, but they are
// generally available on POSIX-compliant systems:
TLI.setUnavailable(LibFunc_access);
@@ -460,6 +416,50 @@ static void initialize(TargetLibraryInfo
TLI.setUnavailable(LibFunc_stat64);
TLI.setUnavailable(LibFunc_statvfs64);
TLI.setUnavailable(LibFunc_tmpfile64);
+
+ // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
+ TLI.setUnavailable(LibFunc_acos_finite);
+ TLI.setUnavailable(LibFunc_acosf_finite);
+ TLI.setUnavailable(LibFunc_acosl_finite);
+ TLI.setUnavailable(LibFunc_acosh_finite);
+ TLI.setUnavailable(LibFunc_acoshf_finite);
+ TLI.setUnavailable(LibFunc_acoshl_finite);
+ TLI.setUnavailable(LibFunc_asin_finite);
+ TLI.setUnavailable(LibFunc_asinf_finite);
+ TLI.setUnavailable(LibFunc_asinl_finite);
+ TLI.setUnavailable(LibFunc_atan2_finite);
+ TLI.setUnavailable(LibFunc_atan2f_finite);
+ TLI.setUnavailable(LibFunc_atan2l_finite);
+ TLI.setUnavailable(LibFunc_atanh_finite);
+ TLI.setUnavailable(LibFunc_atanhf_finite);
+ TLI.setUnavailable(LibFunc_atanhl_finite);
+ TLI.setUnavailable(LibFunc_cosh_finite);
+ TLI.setUnavailable(LibFunc_coshf_finite);
+ TLI.setUnavailable(LibFunc_coshl_finite);
+ TLI.setUnavailable(LibFunc_exp10_finite);
+ TLI.setUnavailable(LibFunc_exp10f_finite);
+ TLI.setUnavailable(LibFunc_exp10l_finite);
+ TLI.setUnavailable(LibFunc_exp2_finite);
+ TLI.setUnavailable(LibFunc_exp2f_finite);
+ TLI.setUnavailable(LibFunc_exp2l_finite);
+ TLI.setUnavailable(LibFunc_exp_finite);
+ TLI.setUnavailable(LibFunc_expf_finite);
+ TLI.setUnavailable(LibFunc_expl_finite);
+ TLI.setUnavailable(LibFunc_log10_finite);
+ TLI.setUnavailable(LibFunc_log10f_finite);
+ TLI.setUnavailable(LibFunc_log10l_finite);
+ TLI.setUnavailable(LibFunc_log2_finite);
+ TLI.setUnavailable(LibFunc_log2f_finite);
+ TLI.setUnavailable(LibFunc_log2l_finite);
+ TLI.setUnavailable(LibFunc_log_finite);
+ TLI.setUnavailable(LibFunc_logf_finite);
+ TLI.setUnavailable(LibFunc_logl_finite);
+ TLI.setUnavailable(LibFunc_pow_finite);
+ TLI.setUnavailable(LibFunc_powf_finite);
+ TLI.setUnavailable(LibFunc_powl_finite);
+ TLI.setUnavailable(LibFunc_sinh_finite);
+ TLI.setUnavailable(LibFunc_sinhf_finite);
+ TLI.setUnavailable(LibFunc_sinhl_finite);
}
// As currently implemented in clang, NVPTX code has no standard library to
Modified: llvm/trunk/test/Transforms/ConstProp/calls-math-finite.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ConstProp/calls-math-finite.ll?rev=322010&r1=322009&r2=322010&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ConstProp/calls-math-finite.ll (original)
+++ llvm/trunk/test/Transforms/ConstProp/calls-math-finite.ll Mon Jan 8 09:38:09 2018
@@ -1,10 +1,12 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -constprop -S | FileCheck %s
-; Test to verify constant folding can occur when math
-; routines are mapped to the __<func>_finite versions
-; of functions due to __FINITE_MATH_ONLY__ being
-; enabled on headers. All calls should constant
-; fold away in this test.
+; Test to verify constant folding can occur when math routines are mapped
+; to the __<func>_finite versions of functions due to __FINITE_MATH_ONLY__
+; being enabled on headers on Linux. All calls should constant fold away
+; in this test.
+
+target triple = "unknown-unknown-linux-gnu"
declare double @__acos_finite(double) #0
declare float @__acosf_finite(float) #0
@@ -31,19 +33,39 @@ attributes #0 = { nounwind readnone }
define void @T() {
; CHECK-LABEL: @T(
-
-; CHECK-NOT: call
-; CHECK: ret
-
+; CHECK-NEXT: [[SLOT:%.*]] = alloca double
+; CHECK-NEXT: [[SLOTF:%.*]] = alloca float
+; CHECK-NEXT: store double 0.000000e+00, double* [[SLOT]]
+; CHECK-NEXT: store double 0x3FF921FB54442D18, double* [[SLOT]]
+; CHECK-NEXT: store double 0x3FE4978FA3269EE1, double* [[SLOT]]
+; CHECK-NEXT: store double 0x402422A497D6185E, double* [[SLOT]]
+; CHECK-NEXT: store double 0x403415E5BF6FB106, double* [[SLOT]]
+; CHECK-NEXT: store double 8.000000e+00, double* [[SLOT]]
+; CHECK-NEXT: store double 0x3FF193EA7AAD030B, double* [[SLOT]]
+; CHECK-NEXT: store double 0x3FDE8927964FD5FD, double* [[SLOT]]
+; CHECK-NEXT: store double 1.000000e+00, double* [[SLOT]]
+; CHECK-NEXT: store double 0x40240926E70949AE, double* [[SLOT]]
+; CHECK-NEXT: store float 0.000000e+00, float* [[SLOTF]]
+; CHECK-NEXT: store float 0x3FF921FB60000000, float* [[SLOTF]]
+; CHECK-NEXT: store float 0x3FE4978FA0000000, float* [[SLOTF]]
+; CHECK-NEXT: store float 0x402422A4A0000000, float* [[SLOTF]]
+; CHECK-NEXT: store float 0x403415E5C0000000, float* [[SLOTF]]
+; CHECK-NEXT: store float 8.000000e+00, float* [[SLOTF]]
+; CHECK-NEXT: store float 0x3FF193EA80000000, float* [[SLOTF]]
+; CHECK-NEXT: store float 0x3FDE8927A0000000, float* [[SLOTF]]
+; CHECK-NEXT: store float 8.100000e+01, float* [[SLOTF]]
+; CHECK-NEXT: store float 0x40240926E0000000, float* [[SLOTF]]
+; CHECK-NEXT: ret void
+;
%slot = alloca double
%slotf = alloca float
-
+
%ACOS = call fast double @__acos_finite(double 1.000000e+00)
store double %ACOS, double* %slot
%ASIN = call fast double @__asin_finite(double 1.000000e+00)
store double %ASIN, double* %slot
%ATAN2 = call fast double @__atan2_finite(double 3.000000e+00, double 4.000000e+00)
- store double %ATAN2, double* %slot
+ store double %ATAN2, double* %slot
%COSH = call fast double @__cosh_finite(double 3.000000e+00)
store double %COSH, double* %slot
%EXP = call fast double @__exp_finite(double 3.000000e+00)
@@ -53,18 +75,18 @@ define void @T() {
%LOG = call fast double @__log_finite(double 3.000000e+00)
store double %LOG, double* %slot
%LOG10 = call fast double @__log10_finite(double 3.000000e+00)
- store double %LOG10, double* %slot
+ store double %LOG10, double* %slot
%POW = call fast double @__pow_finite(double 1.000000e+00, double 4.000000e+00)
store double %POW, double* %slot
%SINH = call fast double @__sinh_finite(double 3.000000e+00)
- store double %SINH, double* %slot
-
+ store double %SINH, double* %slot
+
%ACOSF = call fast float @__acosf_finite(float 1.000000e+00)
store float %ACOSF, float* %slotf
%ASINF = call fast float @__asinf_finite(float 1.000000e+00)
store float %ASINF, float* %slotf
%ATAN2F = call fast float @__atan2f_finite(float 3.000000e+00, float 4.000000e+00)
- store float %ATAN2F, float* %slotf
+ store float %ATAN2F, float* %slotf
%COSHF = call fast float @__coshf_finite(float 3.000000e+00)
store float %COSHF, float* %slotf
%EXPF = call fast float @__expf_finite(float 3.000000e+00)
@@ -74,10 +96,11 @@ define void @T() {
%LOGF = call fast float @__logf_finite(float 3.000000e+00)
store float %LOGF, float* %slotf
%LOG10F = call fast float @__log10f_finite(float 3.000000e+00)
- store float %LOG10F, float* %slotf
+ store float %LOG10F, float* %slotf
%POWF = call fast float @__powf_finite(float 3.000000e+00, float 4.000000e+00)
store float %POWF, float* %slotf
%SINHF = call fast float @__sinhf_finite(float 3.000000e+00)
store float %SINHF, float* %slotf
ret void
}
+
More information about the llvm-commits
mailing list