Skip to content

Enable exp10 libcall on linux #68736

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions llvm/lib/Analysis/TargetLibraryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,16 +558,12 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
break;
case Triple::Linux:
// exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
// buggy prior to glibc version 2.18. Until this version is widely deployed
// or we have a reasonable detection strategy, we cannot use exp10 reliably
// on Linux.
//
// Fall through to disable all of them.
[[fallthrough]];
default:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change here caused a quite noisy warning from GCC:

../lib/Analysis/TargetLibraryInfo.cpp: In function ‘void initialize(llvm::TargetLibraryInfoImpl&, const llvm::Triple&, llvm::ArrayRef<llvm::StringLiteral>)’:
../lib/Analysis/TargetLibraryInfo.cpp:533:10: warning: enumeration value ‘UnknownOS’ not handled in switch [-Wswitch]
  533 |   switch (T.getOS()) {
      |          ^
../lib/Analysis/TargetLibraryInfo.cpp:533:10: warning: enumeration value ‘Darwin’ not handled in switch [-Wswitch]
../lib/Analysis/TargetLibraryInfo.cpp:533:10: warning: enumeration value ‘DragonFly’ not handled in switch [-Wswitch]
../lib/Analysis/TargetLibraryInfo.cpp:533:10: warning: enumeration value ‘FreeBSD’ not handled in switch [-Wswitch]
../lib/Analysis/TargetLibraryInfo.cpp:533:10: warning: enumeration value ‘Fuchsia’ not handled in switch [-Wswitch]
../lib/Analysis/TargetLibraryInfo.cpp:533:10: warning: enumeration value ‘KFreeBSD’ not handled in switch [-Wswitch]

(and so on for all OSes known by Triple)

So ideally we'd keep the default case to silence this compiler warning (or not enable -Wswitch, wherever that comes from).

TLI.setUnavailable(LibFunc_exp10);
TLI.setUnavailable(LibFunc_exp10f);
TLI.setUnavailable(LibFunc_exp10l);
// buggy prior to glibc version 2.18. As this version is so old, we
// don't really need to worry about using exp10 on Linux.
TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
TLI.setAvailableWithName(LibFunc_exp10l, "__exp10l");
break;
}

// ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
Expand Down Expand Up @@ -834,6 +830,9 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_strndup);
TLI.setUnavailable(LibFunc_strnlen);
TLI.setUnavailable(LibFunc_toascii);
TLI.setUnavailable(LibFunc_exp10);
TLI.setUnavailable(LibFunc_exp10f);
TLI.setUnavailable(LibFunc_exp10l);
}

// As currently implemented in clang, NVPTX code has no standard library to
Expand Down
19 changes: 14 additions & 5 deletions llvm/test/Transforms/InstCombine/double-float-shrink-1.ll
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,20 @@ define double @expm1_test2(float %f) {
; exp10f() doesn't exist for this triple, so it doesn't shrink.

define float @exp10_test1(float %f) {
; CHECK-LABEL: @exp10_test1(
; CHECK-NEXT: [[CONV:%.*]] = fpext float [[F:%.*]] to double
; CHECK-NEXT: [[CALL:%.*]] = call fast double @exp10(double [[CONV]])
; CHECK-NEXT: [[CONV1:%.*]] = fptrunc double [[CALL]] to float
; CHECK-NEXT: ret float [[CONV1]]
; LINUX-LABEL: define float @exp10_test1(
; LINUX-SAME: float [[F:%.*]]) {
; LINUX-NEXT: [[EXP10F:%.*]] = call fast float @__exp10f(float [[F]])
; LINUX-NEXT: ret float [[EXP10F]]
;
; MS64-LABEL: define float @exp10_test1(
; MS64-SAME: float [[F:%.*]]) {
; MS64-NEXT: [[EXP10F:%.*]] = call fast float @exp10f(float [[F]])
; MS64-NEXT: ret float [[EXP10F]]
;
; MS32-LABEL: define float @exp10_test1(
; MS32-SAME: float [[F:%.*]]) {
; MS32-NEXT: [[EXP10F:%.*]] = call fast float @exp10f(float [[F]])
; MS32-NEXT: ret float [[EXP10F]]
;
%conv = fpext float %f to double
%call = call fast double @exp10(double %conv)
Expand Down
53 changes: 45 additions & 8 deletions llvm/test/Transforms/InstCombine/pow-1.ll
Original file line number Diff line number Diff line change
Expand Up @@ -870,10 +870,30 @@ define float @test_simplify18(float %x) {
; CHECK-EXP10-NEXT: [[__EXP10F:%.*]] = call float @__exp10f(float [[X]])
; CHECK-EXP10-NEXT: ret float [[__EXP10F]]
;
; CHECK-NO-EXP10-LABEL: define float @test_simplify18(
; CHECK-NO-EXP10-SAME: float [[X:%.*]]) {
; CHECK-NO-EXP10-NEXT: [[RETVAL:%.*]] = call float @powf(float 1.000000e+01, float [[X]])
; CHECK-NO-EXP10-NEXT: ret float [[RETVAL]]
; VC32-LABEL: define float @test_simplify18(
; VC32-SAME: float [[X:%.*]]) {
; VC32-NEXT: [[RETVAL:%.*]] = call float @powf(float 1.000000e+01, float [[X]])
; VC32-NEXT: ret float [[RETVAL]]
;
; VC51-LABEL: define float @test_simplify18(
; VC51-SAME: float [[X:%.*]]) {
; VC51-NEXT: [[RETVAL:%.*]] = call float @powf(float 1.000000e+01, float [[X]])
; VC51-NEXT: ret float [[RETVAL]]
;
; VC64-LABEL: define float @test_simplify18(
; VC64-SAME: float [[X:%.*]]) {
; VC64-NEXT: [[EXP10F:%.*]] = call float @exp10f(float [[X]])
; VC64-NEXT: ret float [[EXP10F]]
;
; VC83-LABEL: define float @test_simplify18(
; VC83-SAME: float [[X:%.*]]) {
; VC83-NEXT: [[EXP10F:%.*]] = call float @exp10f(float [[X]])
; VC83-NEXT: ret float [[EXP10F]]
;
; NOLIB-LABEL: define float @test_simplify18(
; NOLIB-SAME: float [[X:%.*]]) {
; NOLIB-NEXT: [[RETVAL:%.*]] = call float @powf(float 1.000000e+01, float [[X]])
; NOLIB-NEXT: ret float [[RETVAL]]
;
%retval = call float @powf(float 10.0, float %x)
ret float %retval
Expand All @@ -885,11 +905,28 @@ define double @test_simplify19(double %x) {
; CHECK-EXP10-NEXT: [[__EXP10:%.*]] = call double @__exp10(double [[X]])
; CHECK-EXP10-NEXT: ret double [[__EXP10]]
;
; CHECK-NO-EXP10-LABEL: define double @test_simplify19(
; CHECK-NO-EXP10-SAME: double [[X:%.*]]) {
; CHECK-NO-EXP10-NEXT: [[RETVAL:%.*]] = call double @pow(double 1.000000e+01, double [[X]])
; CHECK-NO-EXP10-NEXT: ret double [[RETVAL]]
; VC32-LABEL: define double @test_simplify19(
; VC32-SAME: double [[X:%.*]]) {
; VC32-NEXT: [[EXP10:%.*]] = call double @exp10(double [[X]])
; VC32-NEXT: ret double [[EXP10]]
;
; VC19-LABEL: define double @test_simplify19(
; VC19-SAME: double [[X:%.*]]) {
; VC19-NEXT: [[EXP10:%.*]] = call double @exp10(double [[X]])
; VC19-NEXT: ret double [[EXP10]]
;
; VC64-LABEL: define double @test_simplify19(
; VC64-SAME: double [[X:%.*]]) {
; VC64-NEXT: [[EXP10:%.*]] = call double @exp10(double [[X]])
; VC64-NEXT: ret double [[EXP10]]
;
; NOLIB-LABEL: define double @test_simplify19(
; NOLIB-SAME: double [[X:%.*]]) {
; NOLIB-NEXT: [[RETVAL:%.*]] = call double @pow(double 1.000000e+01, double [[X]])
; NOLIB-NEXT: ret double [[RETVAL]]
;
%retval = call double @pow(double 10.0, double %x)
ret double %retval
}
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; CHECK-NO-EXP10: {{.*}}
39 changes: 20 additions & 19 deletions llvm/test/Transforms/InstCombine/pow-exp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,11 @@ define fp128 @powl_exp2l_not_fast(fp128 %x, fp128 %y) {
ret fp128 %pow
}

; TODO: exp10() is not widely enabled by many targets yet.

define float @powf_exp10f(float %x, float %y) {
; CHECK-LABEL: @powf_exp10f(
; CHECK-NEXT: [[CALL:%.*]] = call fast float @exp10f(float [[X:%.*]]) #[[ATTR1:[0-9]+]]
; CHECK-NEXT: [[POW:%.*]] = call fast float @llvm.pow.f32(float [[CALL]], float [[Y:%.*]])
; CHECK-LABEL: define float @powf_exp10f(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
; CHECK-NEXT: [[CALL:%.*]] = call fast float @exp10f(float [[X]]) #[[ATTR1:[0-9]+]]
; CHECK-NEXT: [[POW:%.*]] = call fast float @llvm.pow.f32(float [[CALL]], float [[Y]])
; CHECK-NEXT: ret float [[POW]]
;
%call = call fast float @exp10f(float %x) nounwind readnone
Expand All @@ -150,9 +149,10 @@ define float @powf_exp10f(float %x, float %y) {
}

define double @pow_exp10(double %x, double %y) {
; CHECK-LABEL: @pow_exp10(
; CHECK-NEXT: [[CALL:%.*]] = call fast double @exp10(double [[X:%.*]]) #[[ATTR1]]
; CHECK-NEXT: [[POW:%.*]] = call fast double @llvm.pow.f64(double [[CALL]], double [[Y:%.*]])
; CHECK-LABEL: define double @pow_exp10(
; CHECK-SAME: double [[X:%.*]], double [[Y:%.*]]) {
; CHECK-NEXT: [[CALL:%.*]] = call fast double @exp10(double [[X]]) #[[ATTR1]]
; CHECK-NEXT: [[POW:%.*]] = call fast double @llvm.pow.f64(double [[CALL]], double [[Y]])
; CHECK-NEXT: ret double [[POW]]
;
%call = call fast double @exp10(double %x) nounwind readnone
Expand All @@ -161,9 +161,10 @@ define double @pow_exp10(double %x, double %y) {
}

define fp128 @pow_exp10l(fp128 %x, fp128 %y) {
; CHECK-LABEL: @pow_exp10l(
; CHECK-NEXT: [[CALL:%.*]] = call fast fp128 @exp10l(fp128 [[X:%.*]]) #[[ATTR1]]
; CHECK-NEXT: [[POW:%.*]] = call fast fp128 @llvm.pow.f128(fp128 [[CALL]], fp128 [[Y:%.*]])
; CHECK-LABEL: define fp128 @pow_exp10l(
; CHECK-SAME: fp128 [[X:%.*]], fp128 [[Y:%.*]]) {
; CHECK-NEXT: [[CALL:%.*]] = call fast fp128 @exp10l(fp128 [[X]]) #[[ATTR1]]
; CHECK-NEXT: [[POW:%.*]] = call fast fp128 @llvm.pow.f128(fp128 [[CALL]], fp128 [[Y]])
; CHECK-NEXT: ret fp128 [[POW]]
;
%call = call fast fp128 @exp10l(fp128 %x) nounwind readnone
Expand Down Expand Up @@ -255,10 +256,10 @@ define double @pow_ok_base3(double %e) {
}

define double @pow_ok_ten_base(double %e) {
; CHECK-LABEL: @pow_ok_ten_base(
; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn double [[E:%.*]], 0x400A934F{{.*}}
; CHECK-NEXT: [[EXP2:%.*]] = tail call nnan ninf afn double @exp2(double [[MUL]])
; CHECK-NEXT: ret double [[EXP2]]
; CHECK-LABEL: define double @pow_ok_ten_base(
; CHECK-SAME: double [[E:%.*]]) {
; CHECK-NEXT: [[EXP10:%.*]] = tail call nnan ninf afn double @exp10(double [[E]])
; CHECK-NEXT: ret double [[EXP10]]
;
%call = tail call afn nnan ninf double @pow(double 1.000000e+01, double %e)
ret double %call
Expand Down Expand Up @@ -305,10 +306,10 @@ define float @powf_ok_base3(float %e) {
}

define float @powf_ok_ten_base(float %e) {
; CHECK-LABEL: @powf_ok_ten_base(
; CHECK-NEXT: [[MUL:%.*]] = fmul nnan ninf afn float [[E:%.*]], 0x400A934{{.*}}
; CHECK-NEXT: [[EXP2F:%.*]] = tail call nnan ninf afn float @exp2f(float [[MUL]])
; CHECK-NEXT: ret float [[EXP2F]]
; CHECK-LABEL: define float @powf_ok_ten_base(
; CHECK-SAME: float [[E:%.*]]) {
; CHECK-NEXT: [[EXP10F:%.*]] = tail call nnan ninf afn float @exp10f(float [[E]])
; CHECK-NEXT: ret float [[EXP10F]]
;
%call = tail call afn nnan ninf float @powf(float 1.000000e+01, float %e)
ret float %call
Expand Down