Skip to content

Commit 761fa58

Browse files
authored
[TLI] Add support for the ilogb libcall. (#112725)
This patch adds the `ilogb` libcall. Constant folding will be handled in subsequent patches.
1 parent 9d469b5 commit 761fa58

File tree

7 files changed

+58
-13
lines changed

7 files changed

+58
-13
lines changed

clang/test/CodeGen/math-libcalls-tbaa-indirect-args.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,39 +153,39 @@ _Complex long double test_cargl(_Complex long double cld) {
153153
int ilogbl(long double a);
154154

155155
// CHECK-LABEL: define dso_local i32 @test_ilogb(
156-
// CHECK-SAME: x86_fp80 noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
156+
// CHECK-SAME: x86_fp80 noundef [[A:%.*]]) local_unnamed_addr #[[ATTR0]] {
157157
// CHECK: [[CALL:%.*]] = tail call i32 @ilogbl(x86_fp80 noundef [[A]]) #[[ATTR5]], !tbaa [[TBAA2]]
158158
//
159159
// CHECK-WIN64-LABEL: define dso_local i32 @test_ilogb(
160-
// CHECK-WIN64-SAME: x86_fp80 noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
160+
// CHECK-WIN64-SAME: x86_fp80 noundef [[A:%.*]]) local_unnamed_addr #[[ATTR0]] {
161161
// CHECK-WIN64: [[CALL:%.*]] = tail call i32 @ilogbl(x86_fp80 noundef [[A]]) #[[ATTR5]], !tbaa [[TBAA2]]
162162
//
163163
// CHECK-I686-LABEL: define dso_local i32 @test_ilogb(
164-
// CHECK-I686-SAME: x86_fp80 noundef [[A:%.*]]) local_unnamed_addr #[[ATTR2]] {
164+
// CHECK-I686-SAME: x86_fp80 noundef [[A:%.*]]) local_unnamed_addr #[[ATTR0]] {
165165
// CHECK-I686: [[CALL:%.*]] = tail call i32 @ilogbl(x86_fp80 noundef [[A]]) #[[ATTR5]], !tbaa [[TBAA3]]
166166
//
167167
// CHECK-PPC-LABEL: define dso_local i32 @test_ilogb(
168-
// CHECK-PPC-SAME: ppc_fp128 noundef [[A:%.*]]) local_unnamed_addr #[[ATTR1]] {
168+
// CHECK-PPC-SAME: ppc_fp128 noundef [[A:%.*]]) local_unnamed_addr #[[ATTR0]] {
169169
// CHECK-PPC: [[CALL:%.*]] = tail call i32 @ilogbl(ppc_fp128 noundef [[A]]) #[[ATTR3]], !tbaa [[TBAA2]]
170170
//
171171
// CHECK-ARM-LABEL: define dso_local i32 @test_ilogb(
172-
// CHECK-ARM-SAME: double noundef [[A:%.*]]) local_unnamed_addr #[[ATTR1]] {
172+
// CHECK-ARM-SAME: double noundef [[A:%.*]]) local_unnamed_addr #[[ATTR0]] {
173173
// CHECK-ARM: [[CALL:%.*]] = tail call i32 @ilogbl(double noundef [[A]]) #[[ATTR2]], !tbaa [[TBAA3]]
174174
//
175175
// CHECK-ARM-HF-LABEL: define dso_local i32 @test_ilogb(
176-
// CHECK-ARM-HF-SAME: double noundef [[A:%.*]]) local_unnamed_addr #[[ATTR1]] {
176+
// CHECK-ARM-HF-SAME: double noundef [[A:%.*]]) local_unnamed_addr #[[ATTR0]] {
177177
// CHECK-ARM-HF: [[CALL:%.*]] = tail call i32 @ilogbl(double noundef [[A]]) #[[ATTR2]], !tbaa [[TBAA3]]
178178
//
179179
// CHECK-THUMB-LABEL: define i32 @test_ilogb(
180-
// CHECK-THUMB-SAME: double noundef [[A:%.*]]) local_unnamed_addr #[[ATTR1]] {
180+
// CHECK-THUMB-SAME: double noundef [[A:%.*]]) local_unnamed_addr #[[ATTR0]] {
181181
// CHECK-THUMB: [[CALL:%.*]] = tail call i32 @ilogbl(double noundef [[A]]) #[[ATTR2]], !tbaa [[TBAA3]]
182182
//
183183
// CHECK-AARCH-LABEL: define dso_local i32 @test_ilogb(
184-
// CHECK-AARCH-SAME: fp128 noundef [[A:%.*]]) local_unnamed_addr #[[ATTR1]] {
184+
// CHECK-AARCH-SAME: fp128 noundef [[A:%.*]]) local_unnamed_addr #[[ATTR0]] {
185185
// CHECK-AARCH: [[CALL:%.*]] = tail call i32 @ilogbl(fp128 noundef [[A]]) #[[ATTR2]], !tbaa [[TBAA2]]
186186
//
187187
// CHECK-SPIR-LABEL: define dso_local spir_func i32 @test_ilogb(
188-
// CHECK-SPIR-SAME: double noundef [[A:%.*]]) local_unnamed_addr #[[ATTR1]] {
188+
// CHECK-SPIR-SAME: double noundef [[A:%.*]]) local_unnamed_addr #[[ATTR0]] {
189189
// CHECK-SPIR: [[CALL:%.*]] = tail call spir_func i32 @ilogbl(double noundef [[A]]) #[[ATTR3]], !tbaa [[TBAA2]]
190190
//
191191
// CHECK-MINGW32-LABEL: define dso_local i32 @test_ilogb(

llvm/include/llvm/Analysis/TargetLibraryInfo.def

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,21 @@ TLI_DEFINE_ENUM_INTERNAL(log2l)
17511751
TLI_DEFINE_STRING_INTERNAL("log2l")
17521752
TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl)
17531753

1754+
/// int ilogb(double x);
1755+
TLI_DEFINE_ENUM_INTERNAL(ilogb)
1756+
TLI_DEFINE_STRING_INTERNAL("ilogb")
1757+
TLI_DEFINE_SIG_INTERNAL(Int, Dbl)
1758+
1759+
/// int ilogbf(float x);
1760+
TLI_DEFINE_ENUM_INTERNAL(ilogbf)
1761+
TLI_DEFINE_STRING_INTERNAL("ilogbf")
1762+
TLI_DEFINE_SIG_INTERNAL(Int, Flt)
1763+
1764+
/// int ilogbl(long double x);
1765+
TLI_DEFINE_ENUM_INTERNAL(ilogbl)
1766+
TLI_DEFINE_STRING_INTERNAL("ilogbl")
1767+
TLI_DEFINE_SIG_INTERNAL(Int, LDbl)
1768+
17541769
/// double logb(double x);
17551770
TLI_DEFINE_ENUM_INTERNAL(logb)
17561771
TLI_DEFINE_STRING_INTERNAL("logb")

llvm/lib/Analysis/TargetLibraryInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
372372
TLI.setUnavailable(LibFunc_log2);
373373
TLI.setUnavailable(LibFunc_log2f);
374374
TLI.setAvailableWithName(LibFunc_logb, "_logb");
375+
TLI.setUnavailable(LibFunc_ilogb);
376+
TLI.setUnavailable(LibFunc_ilogbf);
375377
if (hasPartialFloat)
376378
TLI.setAvailableWithName(LibFunc_logbf, "_logbf");
377379
else
@@ -398,6 +400,7 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, const Triple &T,
398400
TLI.setUnavailable(LibFunc_log1pl);
399401
TLI.setUnavailable(LibFunc_log2l);
400402
TLI.setUnavailable(LibFunc_logbl);
403+
TLI.setUnavailable(LibFunc_ilogbl);
401404
TLI.setUnavailable(LibFunc_nearbyintl);
402405
TLI.setUnavailable(LibFunc_rintl);
403406
TLI.setUnavailable(LibFunc_roundl);

llvm/lib/Transforms/Utils/BuildLibCalls.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
12291229
case LibFunc_logb:
12301230
case LibFunc_logbf:
12311231
case LibFunc_logbl:
1232+
case LibFunc_ilogb:
1233+
case LibFunc_ilogbf:
1234+
case LibFunc_ilogbl:
12321235
case LibFunc_logf:
12331236
case LibFunc_logl:
12341237
case LibFunc_nearbyint:

llvm/test/Transforms/InferFunctionAttrs/annotate.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,15 @@ declare float @log2f(float)
643643
; CHECK: declare x86_fp80 @log2l(x86_fp80) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
644644
declare x86_fp80 @log2l(x86_fp80)
645645

646+
; CHECK: declare i32 @ilogb(double) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
647+
declare i32 @ilogb(double)
648+
649+
; CHECK: declare i32 @ilogbf(float) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
650+
declare i32 @ilogbf(float)
651+
652+
; CHECK: declare i32 @ilogbl(x86_fp80) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
653+
declare i32 @ilogbl(x86_fp80)
654+
646655
; CHECK: declare double @logb(double) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]]
647656
declare double @logb(double)
648657

llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#
3535
# CHECK: << Total TLI yes SDK no: 18
3636
# CHECK: >> Total TLI no SDK yes: 0
37-
# CHECK: == Total TLI yes SDK yes: 256
37+
# CHECK: == Total TLI yes SDK yes: 259
3838
#
3939
# WRONG_DETAIL: << TLI yes SDK no : '_ZdaPv' aka operator delete[](void*)
4040
# WRONG_DETAIL: >> TLI no SDK yes: '_ZdaPvj' aka operator delete[](void*, unsigned int)
@@ -48,14 +48,14 @@
4848
# WRONG_DETAIL: << TLI yes SDK no : 'fminimum_numl'
4949
# WRONG_SUMMARY: << Total TLI yes SDK no: 19{{$}}
5050
# WRONG_SUMMARY: >> Total TLI no SDK yes: 1{{$}}
51-
# WRONG_SUMMARY: == Total TLI yes SDK yes: 255
51+
# WRONG_SUMMARY: == Total TLI yes SDK yes: 258
5252
#
5353
## The -COUNT suffix doesn't care if there are too many matches, so check
5454
## the exact count first; the two directives should add up to that.
5555
## Yes, this means additions to TLI will fail this test, but the argument
5656
## to -COUNT can't be an expression.
57-
# AVAIL: TLI knows 507 symbols, 274 available
58-
# AVAIL-COUNT-274: {{^}} available
57+
# AVAIL: TLI knows 510 symbols, 277 available
58+
# AVAIL-COUNT-277: {{^}} available
5959
# AVAIL-NOT: {{^}} available
6060
# UNAVAIL-COUNT-233: not available
6161
# UNAVAIL-NOT: not available
@@ -654,6 +654,18 @@ DynamicSymbols:
654654
Type: STT_FUNC
655655
Section: .text
656656
Binding: STB_GLOBAL
657+
- Name: ilogb
658+
Type: STT_FUNC
659+
Section: .text
660+
Binding: STB_GLOBAL
661+
- Name: ilogbf
662+
Type: STT_FUNC
663+
Section: .text
664+
Binding: STB_GLOBAL
665+
- Name: ilogbl
666+
Type: STT_FUNC
667+
Section: .text
668+
Binding: STB_GLOBAL
657669
- Name: logb
658670
Type: STT_FUNC
659671
Section: .text

llvm/unittests/Analysis/TargetLibraryInfoTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ TEST_F(TargetLibraryInfoTest, ValidProto) {
266266
"declare double @log2(double)\n"
267267
"declare float @log2f(float)\n"
268268
"declare x86_fp80 @log2l(x86_fp80)\n"
269+
"declare i32 @ilogb(double)\n"
270+
"declare i32 @ilogbf(float)\n"
271+
"declare i32 @ilogbl(x86_fp80)\n"
269272
"declare double @logb(double)\n"
270273
"declare float @logbf(float)\n"
271274
"declare x86_fp80 @logbl(x86_fp80)\n"

0 commit comments

Comments
 (0)