Skip to content

Commit 3683852

Browse files
committed
[VPlan] Use replaceUsesWithIf in replaceAllUseswith and add comment (NFCI).
Follow-up to post-commit commens for b1bfe22.
1 parent b0b491d commit 3683852

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,29 +1136,18 @@ void VPlanIngredient::print(raw_ostream &O) const {
11361136
template void DomTreeBuilder::Calculate<VPDominatorTree>(VPDominatorTree &DT);
11371137

11381138
void VPValue::replaceAllUsesWith(VPValue *New) {
1139-
if (this == New)
1140-
return;
1141-
for (unsigned J = 0; J < getNumUsers();) {
1142-
VPUser *User = Users[J];
1143-
bool RemovedUser = false;
1144-
for (unsigned I = 0, E = User->getNumOperands(); I < E; ++I)
1145-
if (User->getOperand(I) == this) {
1146-
User->setOperand(I, New);
1147-
RemovedUser = true;
1148-
}
1149-
// If a user got removed after updating the current user, the next user to
1150-
// update will be moved to the current position, so we only need to
1151-
// increment the index if the number of users did not change.
1152-
if (!RemovedUser)
1153-
J++;
1154-
}
1139+
replaceUsesWithIf(New, [](VPUser &, unsigned) { return true; });
11551140
}
11561141

11571142
void VPValue::replaceUsesWithIf(
11581143
VPValue *New,
11591144
llvm::function_ref<bool(VPUser &U, unsigned Idx)> ShouldReplace) {
1145+
// Note that this early exit is required for correctness; the implementation
1146+
// below relies on the number of users for this VPValue to decrease, which
1147+
// isn't the case if this == New.
11601148
if (this == New)
11611149
return;
1150+
11621151
for (unsigned J = 0; J < getNumUsers();) {
11631152
VPUser *User = Users[J];
11641153
bool RemovedUser = false;

0 commit comments

Comments
 (0)