[llvm] Enable exp10 libcall on linux (PR #68736)
Krishna Narayanan via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 27 00:22:58 PST 2024
https://github.com/Krishna-13-cyber updated https://github.com/llvm/llvm-project/pull/68736
>From 673d2eb0ecac779f7052c46d68b78a04218c70e2 Mon Sep 17 00:00:00 2001
From: Krishna-13-cyber <krishnanarayanan132002 at gmail.com>
Date: Mon, 15 Jan 2024 19:48:12 +0530
Subject: [PATCH 1/3] Update with test-cases
---
llvm/lib/Analysis/TargetLibraryInfo.cpp | 12 +++---
.../InstCombine/double-float-shrink-1.ll | 19 +++++++---
llvm/test/Transforms/InstCombine/pow-exp.ll | 37 ++++++++++---------
3 files changed, 40 insertions(+), 28 deletions(-)
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index bbb7c86d21856d..7ec4d3438c85d1 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -562,12 +562,9 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
// or we have a reasonable detection strategy, we cannot use exp10 reliably
// on Linux.
//
- // Fall through to disable all of them.
- [[fallthrough]];
- default:
- TLI.setUnavailable(LibFunc_exp10);
- TLI.setUnavailable(LibFunc_exp10f);
- TLI.setUnavailable(LibFunc_exp10l);
+ TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
+ TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
+ break;
}
// ffsl is available on at least Darwin, Mac OS X, iOS, FreeBSD, and
@@ -834,6 +831,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
diff --git a/llvm/test/Transforms/InstCombine/double-float-shrink-1.ll b/llvm/test/Transforms/InstCombine/double-float-shrink-1.ll
index 85c9a01e5fabab..693730256b6b0c 100644
--- a/llvm/test/Transforms/InstCombine/double-float-shrink-1.ll
+++ b/llvm/test/Transforms/InstCombine/double-float-shrink-1.ll
@@ -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)
diff --git a/llvm/test/Transforms/InstCombine/pow-exp.ll b/llvm/test/Transforms/InstCombine/pow-exp.ll
index 9d91ad2402eb1d..1271f02a67cc7d 100644
--- a/llvm/test/Transforms/InstCombine/pow-exp.ll
+++ b/llvm/test/Transforms/InstCombine/pow-exp.ll
@@ -139,9 +139,10 @@ define fp128 @powl_exp2l_not_fast(fp128 %x, fp128 %y) {
; 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
@@ -150,9 +151,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
@@ -161,9 +163,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
@@ -255,10 +258,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
@@ -305,10 +308,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
>From ffb411aea00fb10167174e2204ecee463328c37e Mon Sep 17 00:00:00 2001
From: Krishna Narayanan <krishnanarayanan132002 at gmail.com>
Date: Wed, 17 Jan 2024 22:26:03 +0530
Subject: [PATCH 2/3] Remove stale TODO
---
llvm/test/Transforms/InstCombine/pow-exp.ll | 2 --
1 file changed, 2 deletions(-)
diff --git a/llvm/test/Transforms/InstCombine/pow-exp.ll b/llvm/test/Transforms/InstCombine/pow-exp.ll
index 1271f02a67cc7d..177dd9885827f5 100644
--- a/llvm/test/Transforms/InstCombine/pow-exp.ll
+++ b/llvm/test/Transforms/InstCombine/pow-exp.ll
@@ -136,8 +136,6 @@ 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: define float @powf_exp10f(
; CHECK-SAME: float [[X:%.*]], float [[Y:%.*]]) {
>From ed38fb5aecc51f06aefc2b28cbae8f45d915724e Mon Sep 17 00:00:00 2001
From: Krishna-13-cyber <krishnanarayanan132002 at gmail.com>
Date: Sat, 27 Jan 2024 13:52:08 +0530
Subject: [PATCH 3/3] Update with exp10l
---
llvm/lib/Analysis/TargetLibraryInfo.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 7ec4d3438c85d1..5b8024e6b350bd 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -564,6 +564,7 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
//
TLI.setAvailableWithName(LibFunc_exp10, "__exp10");
TLI.setAvailableWithName(LibFunc_exp10f, "__exp10f");
+ TLI.setAvailableWithName(LibFunc_exp10l, "__exp10l");
break;
}
More information about the llvm-commits
mailing list