aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorFranklin Zhang <zhangfenglei@huawei.com>2024-05-03 12:24:38 +0800
committerGitHub <noreply@github.com>2024-05-03 13:24:38 +0900
commit6b948705a05261a2ff31cd7e6ea8319d1852ddfc (patch)
treeafdb2b733186a3bb583d505dc48675c241cca78f /llvm/lib/Analysis/ValueTracking.cpp
parentb62c45cfe514237f71a7f461ba283dd13a92bfe0 (diff)
downloadllvm-6b948705a05261a2ff31cd7e6ea8319d1852ddfc.zip
llvm-6b948705a05261a2ff31cd7e6ea8319d1852ddfc.tar.gz
llvm-6b948705a05261a2ff31cd7e6ea8319d1852ddfc.tar.bz2
[AggressiveInstCombine] Inline strcmp/strncmp (#89371)
Inline calls to strcmp(s1, s2) and strncmp(s1, s2, N), where N and exactly one of s1 and s2 are constant. For example: ```c int res = strcmp(s, "ab"); ``` is converted to ```c int res = (int)s[0] - (int)'a'; if (res != 0) goto END; res = (int)s[1] - (int)'b'; if (res != 0) goto END; res = (int)s[2] - (int)'\0'; END: ``` Ported from a similar gcc feature [Inline strcmp with small constant strings](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78809).
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index fed2061..0dbb39d 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -252,6 +252,13 @@ bool llvm::haveNoCommonBitsSet(const WithCache<const Value *> &LHSCache,
RHSCache.getKnownBits(SQ));
}
+bool llvm::isOnlyUsedInZeroComparison(const Instruction *I) {
+ return !I->user_empty() && all_of(I->users(), [](const User *U) {
+ ICmpInst::Predicate P;
+ return match(U, m_ICmp(P, m_Value(), m_Zero()));
+ });
+}
+
bool llvm::isOnlyUsedInZeroEqualityComparison(const Instruction *I) {
return !I->user_empty() && all_of(I->users(), [](const User *U) {
ICmpInst::Predicate P;