Skip to content

Commit ad9f15a

Browse files
committed
[VPlan] Introduce and use VPValue::replaceUsesOfWith (NFC).
Adds an API matching LLVM's IR Value, which simplifies some code a bit.
1 parent eeebdb9 commit ad9f15a

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9924,11 +9924,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
99249924
VPValue *Cmp = Select->getOperand(0);
99259925
// If the compare is checking the reduction PHI node, adjust it to check
99269926
// the start value.
9927-
if (VPRecipeBase *CmpR = Cmp->getDefiningRecipe()) {
9928-
for (unsigned I = 0; I != CmpR->getNumOperands(); ++I)
9929-
if (CmpR->getOperand(I) == PhiR)
9930-
CmpR->setOperand(I, PhiR->getStartValue());
9931-
}
9927+
if (VPRecipeBase *CmpR = Cmp->getDefiningRecipe())
9928+
CmpR->replaceUsesOfWith(PhiR, PhiR->getStartValue());
99329929
Builder.setInsertPoint(Select);
99339930

99349931
// If the true value of the select is the reduction phi, the new value is

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,13 @@ void VPValue::replaceUsesWithIf(
14141414
}
14151415
}
14161416

1417+
void VPUser::replaceUsesOfWith(VPValue *From, VPValue *To) {
1418+
for (unsigned Idx = 0; Idx != getNumOperands(); ++Idx) {
1419+
if (getOperand(Idx) == From)
1420+
setOperand(Idx, To);
1421+
}
1422+
}
1423+
14171424
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
14181425
void VPValue::printAsOperand(raw_ostream &OS, VPSlotTracker &Tracker) const {
14191426
OS << Tracker.getOrCreateName(this);

llvm/lib/Transforms/Vectorize/VPlanValue.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ class VPUser {
246246
New->addUser(*this);
247247
}
248248

249+
/// Replaces all uses of \p From in the VPUser with \p To.
250+
void replaceUsesOfWith(VPValue *From, VPValue *To);
251+
249252
typedef SmallVectorImpl<VPValue *>::iterator operand_iterator;
250253
typedef SmallVectorImpl<VPValue *>::const_iterator const_operand_iterator;
251254
typedef iterator_range<operand_iterator> operand_range;

0 commit comments

Comments
 (0)