summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis
diff options
context:
space:
mode:
authorClement Courbet <courbet@google.com>2019-03-08 09:07:45 +0000
committerClement Courbet <courbet@google.com>2019-03-08 09:07:45 +0000
commit8e16d73346f8091461319a7dfc4ddd18eedcff13 (patch)
tree834ddc2069d1bcdb9214a794b89c7570156a6046 /llvm/lib/Analysis
parent1a98dc184044768dd672c54b3b9557a05dd082f1 (diff)
downloadbcm5719-llvm-8e16d73346f8091461319a7dfc4ddd18eedcff13.tar.gz
bcm5719-llvm-8e16d73346f8091461319a7dfc4ddd18eedcff13.zip
[SelectionDAG] Allow the user to specify a memeq function.
Summary: Right now, when we encounter a string equality check, e.g. `if (memcmp(a, b, s) == 0)`, we try to expand to a comparison if `s` is a small compile-time constant, and fall back on calling `memcmp()` else. This is sub-optimal because memcmp has to compute much more than equality. This patch replaces `memcmp(a, b, s) == 0` by `bcmp(a, b, s) == 0` on platforms that support `bcmp`. `bcmp` can be made much more efficient than `memcmp` because equality compare is trivially parallel while lexicographic ordering has a chain dependency. Subscribers: fedor.sergeev, jyknight, ckennelly, gchatelet, llvm-commits Differential Revision: https://reviews.llvm.org/D56593 llvm-svn: 355672
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r--llvm/lib/Analysis/TargetLibraryInfo.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 29e460ec785..50a05a897e9 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -49,6 +49,16 @@ static bool hasSinCosPiStret(const Triple &T) {
return true;
}
+static bool hasBcmp(const Triple &TT) {
+ // Posix removed support from bcmp() in 2001, but the glibc and several
+ // implementations of the libc still have it.
+ if (TT.isOSLinux())
+ return TT.isGNUEnvironment() || TT.isMusl();
+ // Both NetBSD and OpenBSD are planning to remove the function. Windows does
+ // not have it.
+ return TT.isOSFreeBSD() || TT.isOSSolaris() || TT.isOSDarwin();
+}
+
/// Initialize the set of available library functions based on the specified
/// target triple. This should be carefully written so that a missing target
/// triple gets a sane set of defaults.
@@ -141,6 +151,9 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_sincospif_stret);
}
+ if (!hasBcmp(T))
+ TLI.setUnavailable(LibFunc_bcmp);
+
if (T.isMacOSX() && T.getArch() == Triple::x86 &&
!T.isMacOSXVersionLT(10, 7)) {
// x86-32 OSX has a scheme where fwrite and fputs (and some other functions
OpenPOWER on IntegriCloud