@@ -162,17 +162,10 @@ static bool sinkScalarOperands(VPlan &Plan) {
162
162
// TODO: add ".cloned" suffix to name of Clone's VPValue.
163
163
164
164
Clone->insertBefore (SinkCandidate);
165
- for (auto *U : to_vector (SinkCandidate->getVPSingleValue ()->users ())) {
166
- auto *UI = cast<VPRecipeBase>(U);
167
- if (UI->getParent () == SinkTo)
168
- continue ;
169
-
170
- for (unsigned Idx = 0 ; Idx != UI->getNumOperands (); Idx++) {
171
- if (UI->getOperand (Idx) != SinkCandidate->getVPSingleValue ())
172
- continue ;
173
- UI->setOperand (Idx, Clone);
174
- }
175
- }
165
+ SinkCandidate->getVPSingleValue ()->replaceUsesWithIf (
166
+ Clone, [SinkTo](VPUser &U, unsigned ) {
167
+ return cast<VPRecipeBase>(&U)->getParent () != SinkTo;
168
+ });
176
169
}
177
170
SinkCandidate->moveBefore (*SinkTo, SinkTo->getFirstNonPhi ());
178
171
for (VPValue *Op : SinkCandidate->operands ())
@@ -277,16 +270,10 @@ static bool mergeReplicateRegionsIntoSuccessors(VPlan &Plan) {
277
270
VPValue *PredInst1 =
278
271
cast<VPPredInstPHIRecipe>(&Phi1ToMove)->getOperand (0 );
279
272
VPValue *Phi1ToMoveV = Phi1ToMove.getVPSingleValue ();
280
- for (VPUser *U : to_vector (Phi1ToMoveV->users ())) {
281
- auto *UI = dyn_cast<VPRecipeBase>(U);
282
- if (!UI || UI->getParent () != Then2)
283
- continue ;
284
- for (unsigned I = 0 , E = U->getNumOperands (); I != E; ++I) {
285
- if (Phi1ToMoveV != U->getOperand (I))
286
- continue ;
287
- U->setOperand (I, PredInst1);
288
- }
289
- }
273
+ Phi1ToMoveV->replaceUsesWithIf (PredInst1, [Then2](VPUser &U, unsigned ) {
274
+ auto *UI = dyn_cast<VPRecipeBase>(&U);
275
+ return UI && UI->getParent () == Then2;
276
+ });
290
277
291
278
Phi1ToMove.moveBefore (*Merge2, Merge2->begin ());
292
279
}
@@ -542,16 +529,10 @@ void VPlanTransforms::optimizeInductions(VPlan &Plan, ScalarEvolution &SE) {
542
529
543
530
// Update scalar users of IV to use Step instead. Use SetVector to ensure
544
531
// the list of users doesn't contain duplicates.
545
- SetVector<VPUser *> Users (WideIV->user_begin (), WideIV->user_end ());
546
- for (VPUser *U : Users) {
547
- if (HasOnlyVectorVFs && !U->usesScalars (WideIV))
548
- continue ;
549
- for (unsigned I = 0 , E = U->getNumOperands (); I != E; I++) {
550
- if (U->getOperand (I) != WideIV)
551
- continue ;
552
- U->setOperand (I, Steps);
553
- }
554
- }
532
+ WideIV->replaceUsesWithIf (
533
+ Steps, [HasOnlyVectorVFs, WideIV](VPUser &U, unsigned ) {
534
+ return !HasOnlyVectorVFs || U.usesScalars (WideIV);
535
+ });
555
536
}
556
537
}
557
538
0 commit comments