aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/TargetLibraryInfo.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-01-18Add parameter extension attributes in various instrumentation passes.Jonas Paulsson1-19/+4
For the targets that have in their ABI the requirement that arguments and return values are extended to the full register bitwidth, it is important that calls when built also take care of this detail. The OMPIRBuilder, AddressSanitizer, GCOVProfiling, MemorySanitizer and ThreadSanitizer passes are with this patch hopefully now doing this properly. Reviewed By: Eli Friedman, Ulrich Weigand, Johannes Doerfert Differential Revision: https://reviews.llvm.org/D133949
2022-12-20[BuildLibCalls][RISCV] Sign extend return value of bcmp on riscv64.Craig Topper1-1/+11
riscv64 wants callees to sign extend signed and unsigned int returns. The caller can use this to avoid a sign extend if the result is used by a comparison since riscv64 only has 64-bit compares. InstCombine/SimplifyLibCalls aggressively turn memcmps that are only used by an icmp eq 0 into bcmp, but we lose the signext attribute that would have been present on the memcmp. This causes an unneeded sext.w in the generated assembly. This looks even sillier if bcmp is implemented alias to memcmp. In that case, not only did we not get any savings by using bcmp, we added an instruction. This probably applies to other functions, this just happens to be the one I noticed so far. See also the discussion here https://discourse.llvm.org/t/can-we-preserve-signext-return-attribute-when-converting-memcmp-to-bcmp/67126 Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D139901
2022-12-12[RISCV] Set ShouldSignExtI32Param in TargetLibraryInfo for riscv64.Craig Topper1-3/+3
riscv64 sign extends signed and unsigned i32 arguments like Mips. Based on discussion here https://discourse.llvm.org/t/can-we-preserve-signext-return-attribute-when-converting-memcmp-to-bcmp/67126 I'll work on returns next. Differential Revision: https://reviews.llvm.org/D139893
2022-10-03[Analysis][SimplifyLibCalls] Refactor code related to size_t in lib func ↵Bjorn Pettersson1-5/+17
signatures. NFC Added a helper in TargetLibraryInfo to get size of "size_t" in bits, given a Module reference. The new getSizeTSize helper is using the same strategy as for example isValidProtoForLibFunc has been using in the past, assuming that the size can be derived by asking DataLayout about the size/type of a pointer to int. FortifiedLibCallSimplifier::optimizeStrpCpyChk was changed to use the new getSizeTSize helper instead of assuming that sizeof(size_t) is equal to sizeof(int*) by itself (that is the assumption used in TargetLibraryInfoImpl::getSizeTSize so the result will be the same). Having a common helper for this ensure that we use the same strategy when deriving the size of "size_t" in different parts of the code. One bonus with this refactoring (basing it on Module instead of just DataLayout) is that it makes it easier to override this for a specific target triple, in case the assumption of using getPointerSizeInBits wouldn't hold. Differential Revision: https://reviews.llvm.org/D110585
2022-09-20[TargetLibraryInfo] Mark memrchr as unavailable on WindowsMateusz Mikuła1-0/+1
Otherwise LLVM will optimise strrchr into memrchr on Windows resulting in linker error: ``` $ cat memrchr_test.c int main(int argc, char **argv) { return (long)strrchr("KkMm", argv[argc-1][0]); } $ clang memrchr_test.c -O memrchr_test.c:3:12: warning: cast to smaller integer type 'long' from 'char *' [-Wpointer-to-int-cast] return (long)strrchr("KkMm", argv[argc-1][0]); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. ld.lld: error: undefined symbol: memrchr >>> referenced by D:/msys64/tmp/memrchr_test-e7aabd.o:(main) clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` Example taken from MSYS2 Discord and tested with windows-gnu target. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D134134
2022-08-10[InstCombine] Tighten up known library function signature tests (PR #56463)Martin Sebor1-867/+167
Replace a switch statement used to validate arguments to known library functions with a more consistent table-driven approach and tighten it up.
2022-08-08[llvm] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song1-10/+10
With C++17 there is no Clang pedantic warning or MSVC C5051.
2022-06-14[PS5] Make library function availability match PS4Paul Robinson1-4/+4
2022-03-14[TLI] Check that malloc argument has type size_tNikita Popov1-1/+3
DSE assumes that this is the case when forming a calloc from a malloc + memset pair. For tests, either update the malloc signature or change the data layout.
2021-12-07Revert "Revert "Use VersionTuple for parsing versions in Triple, fixing ↵James Farrell1-3/+2
issues that caused the original change to be reverted. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible."" This reverts commit 63a6348cad6caccf285c1661bc60d8ba5a40c972. Differential Revision: https://reviews.llvm.org/D115254
2021-12-06Revert "Use VersionTuple for parsing versions in Triple, fixing issues that ↵James Farrell1-2/+3
caused the original change to be reverted. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible." This reverts commit 50324670342d9391f62671685f4d6b4880a4ea9a.
2021-12-06Use VersionTuple for parsing versions in Triple, fixing issues that caused ↵James Farrell1-3/+2
the original change to be reverted. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible. This reverts commit 40d5eeac6cd89a2360c3ba997cbaa816abca828c. Differential Revision: https://reviews.llvm.org/D114885
2021-12-01[TLI] Add memset_pattern4, memset_pattern8 lib functions.Florian Hahn1-4/+14
Similar to memset_pattern16, memset_pattern4, memset_pattern8 are available on Darwin platforms. https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/memset_pattern4.3.html Reviewed By: ab Differential Revision: https://reviews.llvm.org/D114881
2021-11-30Revert "Use VersionTuple for parsing versions in Triple. This makes it ↵Nikita Popov1-2/+3
possible to distinguish between "16" and "16.0" after parsing, which previously was not possible." This reverts commit 1e8286467036d8ef1a972de723f805a4981b2692. llvm/test/Transforms/LoopStrengthReduce/X86/2009-11-10-LSRCrash.ll fails with assertion failure: llc: /home/nikic/llvm-project/llvm/include/llvm/ADT/Optional.h:196: T& llvm::optional_detail::OptionalStorage<T, true>::getValue() & [with T = unsigned int]: Assertion `hasVal' failed. ... #8 0x00005633843af5cb llvm::MCStreamer::emitVersionForTarget(llvm::Triple const&, llvm::VersionTuple const&) #9 0x0000563383b47f14 llvm::AsmPrinter::doInitialization(llvm::Module&)
2021-11-30Use VersionTuple for parsing versions in Triple. This makes it possible to ↵James Farrell1-3/+2
distinguish between "16" and "16.0" after parsing, which previously was not possible. See also https://github.com/android/ndk/issues/1455. Differential Revision: https://reviews.llvm.org/D114163
2021-11-23[PS4][TLI] Remove redundant linePaul Robinson1-1/+0
2021-10-23[llvm] Use StringRef::contains (NFC)Kazu Hirata1-1/+1
2021-10-07[PS4][TargetLibraryInfo] Set TLI info correctly for PS4Paul Robinson1-0/+124
2021-10-04[TargetLibraryInfo] Refactor size_t checks in isValidProtoForLibFunc. NFCBjorn Pettersson1-37/+36
In TargetLibraryInfoImpl::isValidProtoForLibFunc we no longer need the IsSizeTTy lambda function and the SizeTTy object. Instead we just follow the regular structure of checking for integer types given an exepected number of bits.
2021-09-28[TargetLibraryInfo] Pick new/delete calls by targetPaul Robinson1-0/+59
There are two sets of new/delete functions, one with Windows/MSVC mangling and one with Itanium mangling. Mark one set or the other as unavailable depending on the target. Split the test malloc-free-delete.ll into three parts: malloc-free.dll for the C API tests, new-delete-itanium.ll and new-delete-msvc.ll for the target-specific new/delete tests. Differential Revision: https://reviews.llvm.org/D110419
2021-09-28[Analysis] Be defensive when matching size_t in lib call signaturesBjorn Pettersson1-12/+6
When TargetLibraryInfoImpl::isValidProtoForLibFunc is checking function signatures to detect lib calls it may check that a parameter or return value matches with the "size_t" type. For this to work it has to derive the IR type matching with "size_t". Depending on if a DataLayout is provided or not, this has been done in two different way. Either a more strict check being based on IntPtrType (which is given by the DataLayout) or a more relaxed check assuming that any integer type matches with "size_t". Given that the stricter approach exist it seems like we do not want to trigger rewrites etc if we aren't sure that a function calls actually match with the library function. Therefore it was questioned why we actually have the more relaxed approach when not being able to derive an IR type for "size_t". This patch will take a more defensive approach, requiring that a DataLayout is passed to isValidProtoForLibFunc. Differential Revision: https://reviews.llvm.org/D110584
2021-09-28[Analysis] Add FIXME:s related to size_t type checksBjorn Pettersson1-1/+11
Differential Revision: https://reviews.llvm.org/D110583
2021-09-24[TargetLibraryInfo] Correctly handle sqrt*_finitePaul Robinson1-0/+3
Other <math>_finite calls are marked as unavailable except on GNU/Linux; it looks like the sqrt set was just overlooked. Differential Revision: https://reviews.llvm.org/D110418
2021-09-24[TargetLibraryInfo][AMDGPU] Minor cleanup, NFCPaul Robinson1-8/+3
2021-09-22[Analysis] improve function matching for strlen libcallSanjay Patel1-2/+2
The return type of strlen is size_t, not just any integer. This is a partial fix for an example based on: https://llvm.org/PR50836 There's another bug here because we can still crash processing a real strlen or something that looks like it.
2021-08-16[PS4] stp[n]cpy not available on PS4Paul Robinson1-0/+5
2021-08-15[Analysis][SimplifyLibCalls] improve function signature check for memcmpSanjay Patel1-3/+3
This would assert/crash as shown in: https://llvm.org/PR50850 The matching for bcmp/bcopy should probably also be updated, but that's another patch.
2021-08-05Mark getc_unlocked as unavailable by defaultRyan Prichard1-0/+1
Before D45736, getc_unlocked was available by default, but turned off for non-Cygwin/non-MinGW Windows. D45736 then added 9 more unlocked functions, which were unavailable by default, but it also: * left getc_unlocked enabled by default, * removed the disabling line for Windows, and * added code to enable getc_unlocked for GNU, Android, and OSX. For consistency, make getc_unlocked unavailable by default. Maybe this was the intent of D45736 anyway. Reviewed By: MaskRay, efriedma Differential Revision: https://reviews.llvm.org/D107527
2021-08-04Disable LibFuncs for stpcpy and stpncpy for Android < 21Nathan Lanza1-0/+5
These functions don't exist in android API levels < 21. A change in llvm-12 (rG6dbf0cfcf789) caused Oz builds to emit this symbol assuming it's available and thus is causing link errors. Simply disable it here. Differential Revision: https://reviews.llvm.org/D107509
2021-07-31[Analysis] improve function signature checking for snprintfSanjay Patel1-3/+4
The check for size_t parameter 1 was already here for snprintf_chk, but it wasn't applied to regular snprintf. This could lead to mismatching and eventually crashing as shown in: https://llvm.org/PR50885
2021-07-21[OpenMP] Change `__kmpc_free_shared` to include the paired allocation sizeJoseph Huber1-1/+3
This patch changes `__kmpc_free_shared` to take an additional argument corresponding to the associated allocation's size. This makes it easier to implement the allocator in the runtime. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D106496
2021-06-27[Analysis] improve function signature checking for callocSanjay Patel1-1/+2
This would crash later if we thought the parameters were valid for the standard library call as shown in: https://llvm.org/PR50846
2021-06-22[OpenMP] Add new OpenMP globalization functions to library infoJoseph Huber1-0/+6
Summary: The changes to globalization introduced in D97680 created two new functions to push / pop shareably memory on the GPU, __kmpc_alloc_shared and __kmpc_free_shared. This patch adds these new runtime functions to the library info so they can be used by the HeapToStack attributor interface. This optimization replaces malloc / free pairs with stack memory if legal. Reviewed By: tianshilei1992 Differential Revision: https://reviews.llvm.org/D102087
2021-06-02[SimplifyLibCalls] Take size of int into consideration when emitting ↵Bjorn Pettersson1-3/+12
ldexp/ldexpf When rewriting powf(2.0, itofp(x)) -> ldexpf(1.0, x) exp2(sitofp(x)) -> ldexp(1.0, sext(x)) exp2(uitofp(x)) -> ldexp(1.0, zext(x)) the wrong type was used for the second argument in the ldexp/ldexpf libc call, for target architectures with 16 bit "int" type. The transform incorrectly used a bitcasted function pointer with a 32-bit argument when emitting the ldexp/ldexpf call for such targets. The fault is solved by using the correct function prototype in the call, by asking TargetLibraryInfo about the size of "int". TargetLibraryInfo by default derives the size of the int type by assuming that it is 16 bits for 16-bit architectures, and 32 bits otherwise. If this isn't true for a target it should be possible to override that default in the TargetLibraryInfo initializer. Differential Revision: https://reviews.llvm.org/D99438
2021-05-22[MinGW] Mark a number of library functions unavailable for mingw targetsMartin Storsjö1-22/+26
These functions were marked unavailable for MSVC targets before, within an "T.isOSWindows() && !T.isOSCygMing()" block, but these ones are unavailable on MinGW targets too. This avoids generating calls to stpcpy for MinGW targets, which has been happening since 6dbf0cfcf789365493f70ae69df8a7a59be41c75 (in some cases). This fixes https://github.com/mstorsjo/llvm-mingw/issues/201. Differential Revision: https://reviews.llvm.org/D102946
2021-05-10[VecLib] Add support for vector fns from Darwin's libsystem.Florian Hahn1-0/+10
This patch adds support for Darwin's libsystem math vector functions to TLI. Darwin's libsystem provides a range of vector functions for libm functions. This initial patch only adds the 2 x double and 4 x float versions, which are available on both X86 and ARM64. On X86, wider vector versions are supported as well. Reviewed By: jroelofs Differential Revision: https://reviews.llvm.org/D101856
2021-04-12Reland "Revert "[InstCombine] when calling conventions are compatible, don't ↵Yuanfang Chen1-0/+43
convert the call to undef idiom"" This reverts commit a3fabc79ae9d7dd76545b2abc2a3bfb66c6d3175 (relands f4d682d6ce6c5b3a41a0acf297507c82f5c21eef with fix for the compile-time regression issue).
2021-04-12Revert "[InstCombine] when calling conventions are compatible, don't convert ↵Nikita Popov1-43/+0
the call to undef idiom" This reverts commit f4d682d6ce6c5b3a41a0acf297507c82f5c21eef. This caused a significant compile-time regression: https://llvm-compile-time-tracker.com/compare.php?from=4b7bad9eaea2233521a94f6b096aaa88dc584e23&to=f4d682d6ce6c5b3a41a0acf297507c82f5c21eef&stat=instructions Possibly this is due to overeager parsing of target triples.
2021-04-12[InstCombine] when calling conventions are compatible, don't convert the ↵Yuanfang Chen1-0/+43
call to undef idiom D24453 enabled libcalls simplication for ARM PCS. This may cause caller/callee calling conventions mismatch in some situations such as LTO. This patch makes instcombine aware that the compatible calling conventions differences are benign (not emitting undef idom). Differential Revision: https://reviews.llvm.org/D99773
2021-03-15[NVPTX] CUDA does provide malloc/free since compute capability 2.XJohannes Doerfert1-0/+11
https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#dynamic-global-memory-allocation-and-operations Reviewed By: tra Differential Revision: https://reviews.llvm.org/D98606
2021-03-10[SLC] Simplify strcpy and friends with non-zero address spacesAlex Richardson1-8/+7
The current logic in TargetLibraryInfoImpl::getLibFunc() was only treating strcpy, etc. with i8* arguments in address space zero as a valid library function. However, in the CHERI and Morello targets we expect all libc functions to use address space 200 arguments. This commit updates isValidProtoForLibFunc() to check that the argument is a pointer type. This also drops the check for i8* since we should not be checking the pointee type any more. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D95142
2021-02-12[NFC][Analysis] Change struct VecDesc to use ElementCountDavid Sherwood1-8/+15
This patch changes the VecDesc struct to use ElementCount instead of an unsigned VF value, in preparation for future work that adds support for vectorized versions of math functions using scalable vectors. Since all I'm doing in this patch is switching the type I believe it's a non-functional change. I changed getWidestVF to now return both the widest fixed-width and scalable VF values, but currently the widest scalable value will be zero. Differential Revision: https://reviews.llvm.org/D96011
2021-02-08[Analysis] Remove unused functions from TargetLibraryInfoDavid Sherwood1-18/+0
A simple clean-up to remove dead code. Differential Revision: https://reviews.llvm.org/D95934
2021-01-22[Analysis] Support AIX vec_malloc routinesShimin Cui1-0/+12
This is to support the memory routines vec_malloc, vec_calloc, vec_realloc, and vec_free. These routines manage memory that is 16-byte aligned. And they are only available on AIX. Differential Revision: https://reviews.llvm.org/D94710
2020-12-29[Analysis] Use llvm::append_range (NFC)Kazu Hirata1-2/+2
2020-10-22Initial support for vectorization using Libmvec (GLIBC vector math library)Venkataramanan Kumar1-0/+10
Differential Revision: https://reviews.llvm.org/D88154
2020-10-06[SimplifyLibCalls] Optimize mempcpy_chk to mempcpyDávid Bolvanský1-0/+1
2020-10-05Revert "[SLC] Optimize mempcpy_chk to mempcpy"Dávid Bolvanský1-1/+0
This reverts commit 3f1fd59de3002e3d5a4eca98cd49c45755ab0110.
2020-10-05[SLC] Optimize mempcpy_chk to mempcpyDávid Bolvanský1-0/+1
As reported in PR46735: void* f(void *d, const void *s, size_t l) { return __builtin___mempcpy_chk(d, s, l, __builtin_object_size(d, 0)); } This can be optimized to `return mempcpy(d, s, l);`. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D86019
2020-09-19Fix some clang-tidy bugprone-argument-comment issuesFangrui Song1-1/+1