diff options
author | Yingwei Zheng <dtcxzyw2333@gmail.com> | 2024-08-01 01:49:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-01 01:49:38 +0800 |
commit | 6aa723daa9d9c54c597788d384b41dd735359316 (patch) | |
tree | a671e3565bbab540bac083310730ceb456abce64 | |
parent | 055893f164f595e5d4115db17dd479ed3401bf00 (diff) | |
download | llvm-6aa723daa9d9c54c597788d384b41dd735359316.zip llvm-6aa723daa9d9c54c597788d384b41dd735359316.tar.gz llvm-6aa723daa9d9c54c597788d384b41dd735359316.tar.bz2 |
[TLI] Add support for nan libfunc (#101356)
Reference: https://en.cppreference.com/w/cpp/numeric/math/nan
-rw-r--r-- | llvm/include/llvm/Analysis/TargetLibraryInfo.def | 15 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/BuildLibCalls.cpp | 3 | ||||
-rw-r--r-- | llvm/test/Transforms/InferFunctionAttrs/annotate.ll | 11 | ||||
-rw-r--r-- | llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml | 20 | ||||
-rw-r--r-- | llvm/unittests/Analysis/TargetLibraryInfoTest.cpp | 3 |
5 files changed, 47 insertions, 5 deletions
diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.def b/llvm/include/llvm/Analysis/TargetLibraryInfo.def index e9f3b7f..754f09c 100644 --- a/llvm/include/llvm/Analysis/TargetLibraryInfo.def +++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.def @@ -1807,6 +1807,21 @@ TLI_DEFINE_ENUM_INTERNAL(modfl) TLI_DEFINE_STRING_INTERNAL("modfl") TLI_DEFINE_SIG_INTERNAL(LDbl, LDbl, Ptr) +/// double nan(const char *arg); +TLI_DEFINE_ENUM_INTERNAL(nan) +TLI_DEFINE_STRING_INTERNAL("nan") +TLI_DEFINE_SIG_INTERNAL(Dbl, Ptr) + +/// float nanf(const char *arg); +TLI_DEFINE_ENUM_INTERNAL(nanf) +TLI_DEFINE_STRING_INTERNAL("nanf") +TLI_DEFINE_SIG_INTERNAL(Flt, Ptr) + +/// long double nanl(const char *arg); +TLI_DEFINE_ENUM_INTERNAL(nanl) +TLI_DEFINE_STRING_INTERNAL("nanl") +TLI_DEFINE_SIG_INTERNAL(LDbl, Ptr) + /// double nearbyint(double x); TLI_DEFINE_ENUM_INTERNAL(nearbyint) TLI_DEFINE_STRING_INTERNAL("nearbyint") diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp index 898e5b0..30a343b 100644 --- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp @@ -279,6 +279,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F, Changed |= setNonLazyBind(F); switch (TheLibFunc) { + case LibFunc_nan: + case LibFunc_nanf: + case LibFunc_nanl: case LibFunc_strlen: case LibFunc_strnlen: case LibFunc_wcslen: diff --git a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll index d54290fd..3b914dc2 100644 --- a/llvm/test/Transforms/InferFunctionAttrs/annotate.ll +++ b/llvm/test/Transforms/InferFunctionAttrs/annotate.ll @@ -717,6 +717,15 @@ declare float @modff(float, ptr) ; CHECK: declare x86_fp80 @modfl(x86_fp80, ptr nocapture) [[ARGMEMONLY_NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]] declare x86_fp80 @modfl(x86_fp80, ptr) +; CHECK: declare double @nan(ptr nocapture) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY_WILLRETURN:#[0-9]+]] +declare double @nan(ptr) + +; CHECK: declare float @nanf(ptr nocapture) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY_WILLRETURN]] +declare float @nanf(ptr) + +; CHECK: declare x86_fp80 @nanl(ptr nocapture) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY_WILLRETURN]] +declare x86_fp80 @nanl(ptr) + ; CHECK: declare double @nearbyint(double) [[NOFREE_NOUNWIND_WILLRETURN_WRITEONLY]] declare double @nearbyint(double) @@ -956,7 +965,7 @@ declare ptr @strncpy(ptr, ptr, i64) ; CHECK: declare noalias ptr @strndup(ptr nocapture readonly, i64 noundef) [[INACCESSIBLEMEMORARGONLY_NOFREE_NOUNWIND_WILLRETURN_FAMILY_MALLOC]] declare ptr @strndup(ptr, i64) -; CHECK: declare i64 @strnlen(ptr nocapture, i64) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY_WILLRETURN:#[0-9]+]] +; CHECK: declare i64 @strnlen(ptr nocapture, i64) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY_WILLRETURN]] declare i64 @strnlen(ptr, i64) ; CHECK: declare ptr @strpbrk(ptr, ptr nocapture) [[ARGMEMONLY_NOFREE_NOUNWIND_READONLY_WILLRETURN]] diff --git a/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml b/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml index 19e18e0..81f2c9c 100644 --- a/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml +++ b/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml @@ -34,21 +34,21 @@ # # CHECK: << Total TLI yes SDK no: 8 # CHECK: >> Total TLI no SDK yes: 0 -# CHECK: == Total TLI yes SDK yes: 245 +# CHECK: == Total TLI yes SDK yes: 248 # # WRONG_DETAIL: << TLI yes SDK no : '_ZdaPv' aka operator delete[](void*) # WRONG_DETAIL: >> TLI no SDK yes: '_ZdaPvj' aka operator delete[](void*, unsigned int) # WRONG_DETAIL-COUNT-8: << TLI yes SDK no : {{.*}}__hot_cold_t # WRONG_SUMMARY: << Total TLI yes SDK no: 9{{$}} # WRONG_SUMMARY: >> Total TLI no SDK yes: 1{{$}} -# WRONG_SUMMARY: == Total TLI yes SDK yes: 244 +# WRONG_SUMMARY: == Total TLI yes SDK yes: 247 # ## The -COUNT suffix doesn't care if there are too many matches, so check ## the exact count first; the two directives should add up to that. ## Yes, this means additions to TLI will fail this test, but the argument ## to -COUNT can't be an expression. -# AVAIL: TLI knows 486 symbols, 253 available -# AVAIL-COUNT-253: {{^}} available +# AVAIL: TLI knows 489 symbols, 256 available +# AVAIL-COUNT-256: {{^}} available # AVAIL-NOT: {{^}} available # UNAVAIL-COUNT-233: not available # UNAVAIL-NOT: not available @@ -703,6 +703,18 @@ DynamicSymbols: Type: STT_FUNC Section: .text Binding: STB_GLOBAL + - Name: nan + Type: STT_FUNC + Section: .text + Binding: STB_GLOBAL + - Name: nanf + Type: STT_FUNC + Section: .text + Binding: STB_GLOBAL + - Name: nanl + Type: STT_FUNC + Section: .text + Binding: STB_GLOBAL - Name: nearbyint Type: STT_FUNC Section: .text diff --git a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp index b8125b0..d344ebe 100644 --- a/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp +++ b/llvm/unittests/Analysis/TargetLibraryInfoTest.cpp @@ -255,6 +255,9 @@ TEST_F(TargetLibraryInfoTest, ValidProto) { "declare double @modf(double, double*)\n" "declare float @modff(float, float*)\n" "declare x86_fp80 @modfl(x86_fp80, x86_fp80*)\n" + "declare double @nan(ptr)\n" + "declare float @nanf(ptr)\n" + "declare x86_fp80 @nanl(ptr)\n" "declare double @nearbyint(double)\n" "declare float @nearbyintf(float)\n" "declare x86_fp80 @nearbyintl(x86_fp80)\n" |