[llvm] 3683852 - [VPlan] Use replaceUsesWithIf in replaceAllUseswith and add comment (NFCI).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 21 04:56:27 PST 2024
Author: Florian Hahn
Date: 2024-01-21T12:56:16Z
New Revision: 3683852d4988e4641fb6c20ca8c3013d5c2989f1
URL: https://github.com/llvm/llvm-project/commit/3683852d4988e4641fb6c20ca8c3013d5c2989f1
DIFF: https://github.com/llvm/llvm-project/commit/3683852d4988e4641fb6c20ca8c3013d5c2989f1.diff
LOG: [VPlan] Use replaceUsesWithIf in replaceAllUseswith and add comment (NFCI).
Follow-up to post-commit commens for b1bfe221e6.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp
index b6e56c47c227f77..3eeb1a6948f2765 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -1136,29 +1136,18 @@ void VPlanIngredient::print(raw_ostream &O) const {
template void DomTreeBuilder::Calculate<VPDominatorTree>(VPDominatorTree &DT);
void VPValue::replaceAllUsesWith(VPValue *New) {
- if (this == New)
- return;
- for (unsigned J = 0; J < getNumUsers();) {
- VPUser *User = Users[J];
- bool RemovedUser = false;
- for (unsigned I = 0, E = User->getNumOperands(); I < E; ++I)
- if (User->getOperand(I) == this) {
- User->setOperand(I, New);
- RemovedUser = true;
- }
- // If a user got removed after updating the current user, the next user to
- // update will be moved to the current position, so we only need to
- // increment the index if the number of users did not change.
- if (!RemovedUser)
- J++;
- }
+ replaceUsesWithIf(New, [](VPUser &, unsigned) { return true; });
}
void VPValue::replaceUsesWithIf(
VPValue *New,
llvm::function_ref<bool(VPUser &U, unsigned Idx)> ShouldReplace) {
+ // Note that this early exit is required for correctness; the implementation
+ // below relies on the number of users for this VPValue to decrease, which
+ // isn't the case if this == New.
if (this == New)
return;
+
for (unsigned J = 0; J < getNumUsers();) {
VPUser *User = Users[J];
bool RemovedUser = false;
More information about the llvm-commits
mailing list