-
Notifications
You must be signed in to change notification settings - Fork 16.1k
[VPlanValue] Introduce hasOneUser(). nfc #170826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-vectorizers @llvm/pr-subscribers-llvm-transforms Author: Mel Chen (Mel-Chen) ChangesSmallVector Users may contain duplicate users, so relying on hasOneUse() does not guarantee a single unique user. This patch introduces hasOneUser() to check for exactly only one user, and updates getSingleUser() and VPWidenCastRecipe::computeCost() to use it. Full diff: https://github.com/llvm/llvm-project/pull/170826.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
index 1b1308c78c76e..17adcafd18044 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp
@@ -2259,9 +2259,8 @@ InstructionCost VPWidenCastRecipe::computeCost(ElementCount VF,
VPValue *Operand = getOperand(0);
TTI::CastContextHint CCH = TTI::CastContextHint::None;
// For Trunc/FPTrunc, get the context from the only user.
- if ((Opcode == Instruction::Trunc || Opcode == Instruction::FPTrunc) &&
- !hasMoreThanOneUniqueUser() && getNumUsers() > 0) {
- if (auto *StoreRecipe = dyn_cast<VPRecipeBase>(*user_begin()))
+ if (Opcode == Instruction::Trunc || Opcode == Instruction::FPTrunc) {
+ if (auto *StoreRecipe = dyn_cast_or_null<VPRecipeBase>(getSingleUser()))
CCH = ComputeCCH(StoreRecipe);
}
// For Z/Sext, get the context from the operand.
diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h
index b9f5847ec731c..db48fe5ed73bf 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanValue.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h
@@ -150,11 +150,21 @@ class LLVM_ABI_FOR_TEST VPValue {
bool hasOneUse() const { return getNumUsers() == 1; }
+ /// Returns true if the value has exactly one unique user, ignoring multiple
+ /// uses by the same user.
+ bool hasOneUser() const {
+ if (getNumUsers() == 0)
+ return false;
+ if (hasOneUse())
+ return true;
+ return std::equal(std::next(user_begin()), user_end(), user_begin());
+ }
+
/// Return the single user of this value, or nullptr if there is not exactly
/// one user.
- VPUser *getSingleUser() { return hasOneUse() ? *user_begin() : nullptr; }
+ VPUser *getSingleUser() { return hasOneUser() ? *user_begin() : nullptr; }
const VPUser *getSingleUser() const {
- return hasOneUse() ? *user_begin() : nullptr;
+ return hasOneUser() ? *user_begin() : nullptr;
}
void replaceAllUsesWith(VPValue *New);
|
| return false; | ||
| if (hasOneUse()) | ||
| return true; | ||
| return std::equal(std::next(user_begin()), user_end(), user_begin()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Could use all_equal(Users)
|
Sounds similar to patch I wrote a while ago that got stalled - #155397 |
SmallVector Users may contain duplicate users, so relying on hasOneUse() does not guarantee a single unique user. This patch introduces hasOneUser() to check for exactly only one user, and updates getSingleUser() and VPWidenCastRecipe::computeCost() to use it.