@@ -154,42 +154,42 @@ static bool sinkScalarOperands(VPlan &Plan) {
154154 bool ScalarVFOnly = Plan.hasScalarVFOnly ();
155155 bool Changed = false ;
156156
157- auto IsValidSinkCandidate = [ScalarVFOnly](VPBasicBlock *SinkTo,
158- VPSingleDefRecipe *Candidate) {
159- // We only know how to duplicate VPReplicateRecipes and
160- // VPScalarIVStepsRecipes for now.
157+ SetVector<std::pair<VPBasicBlock *, VPSingleDefRecipe *>> WorkList;
158+ auto InsertIfValidSinkCandidate = [ScalarVFOnly, &WorkList](
159+ VPBasicBlock *SinkTo, VPValue *Op) {
160+ auto *Candidate =
161+ dyn_cast_or_null<VPSingleDefRecipe>(Op->getDefiningRecipe ());
162+ if (!Candidate)
163+ return ;
164+
165+ // We only know how to sink VPReplicateRecipes and VPScalarIVStepsRecipes
166+ // for now.
161167 if (!isa<VPReplicateRecipe, VPScalarIVStepsRecipe>(Candidate))
162- return false ;
168+ return ;
163169
164170 if (Candidate->getParent () == SinkTo || Candidate->mayHaveSideEffects () ||
165171 Candidate->mayReadOrWriteMemory ())
166- return false ;
172+ return ;
167173
168174 if (auto *RepR = dyn_cast<VPReplicateRecipe>(Candidate))
169175 if (!ScalarVFOnly && RepR->isSingleScalar ())
170- return false ;
176+ return ;
171177
172- return true ;
178+ WorkList. insert ({SinkTo, Candidate}) ;
173179 };
174180
175181 // First, collect the operands of all recipes in replicate blocks as seeds for
176182 // sinking.
177- SetVector<std::pair<VPBasicBlock *, VPSingleDefRecipe *>> WorkList;
178183 for (VPRegionBlock *VPR : VPBlockUtils::blocksOnly<VPRegionBlock>(Iter)) {
179184 VPBasicBlock *EntryVPBB = VPR->getEntryBasicBlock ();
180185 if (!VPR->isReplicator () || EntryVPBB->getSuccessors ().size () != 2 )
181186 continue ;
182187 VPBasicBlock *VPBB = cast<VPBasicBlock>(EntryVPBB->getSuccessors ().front ());
183188 if (VPBB->getSingleSuccessor () != VPR->getExitingBasicBlock ())
184189 continue ;
185- for (auto &Recipe : *VPBB) {
186- for (VPValue *Op : Recipe.operands ()) {
187- if (auto *Def =
188- dyn_cast_or_null<VPSingleDefRecipe>(Op->getDefiningRecipe ()))
189- if (IsValidSinkCandidate (VPBB, Def))
190- WorkList.insert ({VPBB, Def});
191- }
192- }
190+ for (auto &Recipe : *VPBB)
191+ for (VPValue *Op : Recipe.operands ())
192+ InsertIfValidSinkCandidate (VPBB, Op);
193193 }
194194
195195 // Try to sink each replicate or scalar IV steps recipe in the worklist.
@@ -234,10 +234,7 @@ static bool sinkScalarOperands(VPlan &Plan) {
234234 }
235235 SinkCandidate->moveBefore (*SinkTo, SinkTo->getFirstNonPhi ());
236236 for (VPValue *Op : SinkCandidate->operands ())
237- if (auto *Def =
238- dyn_cast_or_null<VPSingleDefRecipe>(Op->getDefiningRecipe ()))
239- if (IsValidSinkCandidate (SinkTo, Def))
240- WorkList.insert ({SinkTo, Def});
237+ InsertIfValidSinkCandidate (SinkTo, Op);
241238 Changed = true ;
242239 }
243240 return Changed;
0 commit comments