aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Value.cpp
diff options
context:
space:
mode:
authorRoman Lebedev <lebedev.ri@gmail.com>2020-08-26 17:06:03 +0300
committerRoman Lebedev <lebedev.ri@gmail.com>2020-08-26 20:20:41 +0300
commit95848ea101274b8bd774c63bad55f21a08080705 (patch)
treea2c6a519a7a0d9bfb3a8ca94ac581e7f334bb762 /llvm/lib/IR/Value.cpp
parentc07a430bd39cccb64712ddcba85254a5bb1cd89b (diff)
downloadllvm-95848ea101274b8bd774c63bad55f21a08080705.zip
llvm-95848ea101274b8bd774c63bad55f21a08080705.tar.gz
llvm-95848ea101274b8bd774c63bad55f21a08080705.tar.bz2
[Value][InstCombine] Fix one-use checks in PHI-of-op -> Op-of-PHI[s] transforms to be one-user checks
As FIXME said, they really should be checking for a single user, not use, so let's do that. It is not *that* unusual to have the same value as incoming value in a PHI node, not unlike how a PHI may have the same incoming basic block more than once. There isn't a nice way to do that, Value::users() isn't uniqified, and Value only tracks it's uses, not Users, so the check is potentially costly since it does indeed potentially involes traversing the entire use list of a value.
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r--llvm/lib/IR/Value.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index 26a9835..3e5dd8f 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -147,6 +147,14 @@ bool Value::hasNUsesOrMore(unsigned N) const {
return hasNItemsOrMore(use_begin(), use_end(), N);
}
+bool Value::hasOneUser() const {
+ if (use_empty())
+ return false;
+ if (hasOneUse())
+ return true;
+ return std::equal(++user_begin(), user_end(), user_begin());
+}
+
static bool isUnDroppableUser(const User *U) { return !U->isDroppable(); }
Use *Value::getSingleUndroppableUse() {