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 4 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
18 changes: 7 additions & 11 deletions llvm/lib/Analysis/TargetLibraryInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,17 +557,10 @@ 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.
//
Copy link
Contributor

Choose a reason for hiding this comment

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

I would leave some kind of historical note

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh okay, thanks again!

Copy link
Contributor

Choose a reason for hiding this comment

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

Just update the "Until this version is widely deployed or we have a reasonable detection strategy, we cannot use exp10 reliably" part to something about how this is so old it doesn't matter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"As this version is so old, we don't really need to worry about using exp10 until we find more good ways to detect it."

Does this look fine?

Copy link
Contributor

Choose a reason for hiding this comment

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

The "until we find more good ways to detect it." reads off. Can drop it or rephrase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I will drop this.

// 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);
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 +827,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
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