@@ -463,8 +463,9 @@ void VPlanTransforms::unrollByUF(VPlan &Plan, unsigned UF) {
463463 VPlanTransforms::removeDeadRecipes (Plan);
464464}
465465
466- // / Create a single-scalar clone of \p DefR for lane \p Lane. Use \p
467- // / Def2LaneDefs to look up scalar definitions for operands of \DefR.
466+ // / Create a single-scalar clone of \p DefR (must either be a VPReplicateRecipe
467+ // / or VPInstruction) for lane \p Lane. Use \p Def2LaneDefs to look up scalar
468+ // / definitions for operands of \DefR.
468469static VPRecipeWithIRFlags *
469470cloneForLane (VPlan &Plan, VPBuilder &Builder, Type *IdxTy,
470471 VPRecipeWithIRFlags *DefR, VPLane Lane,
@@ -503,10 +504,15 @@ cloneForLane(VPlan &Plan, VPBuilder &Builder, Type *IdxTy,
503504
504505 VPRecipeWithIRFlags *New;
505506 if (auto *RepR = dyn_cast<VPReplicateRecipe>(DefR)) {
507+ // TODO: have cloning of replicate recipes also provide the desired result
508+ // coupled with setting its operands to NewOps (deriving IsSingleScalar and
509+ // Mask from the operands?)
506510 New =
507511 new VPReplicateRecipe (RepR->getUnderlyingInstr (), NewOps,
508512 /* IsSingleScalar=*/ true , /* Mask=*/ nullptr , *RepR);
509513 } else {
514+ assert (isa<VPInstruction>(DefR) &&
515+ " DefR must either be a VPReplicateRecipe or VPInstruction" );
510516 New = DefR->clone ();
511517 for (const auto &[Idx, Op] : enumerate(NewOps)) {
512518 New->setOperand (Idx, Op);
@@ -538,15 +544,15 @@ void VPlanTransforms::replicateByVF(VPlan &Plan, ElementCount VF) {
538544 SmallVector<VPRecipeBase *> ToRemove;
539545 for (VPBasicBlock *VPBB : VPBBsToUnroll) {
540546 for (VPRecipeBase &R : make_early_inc_range (*VPBB)) {
541- auto *DefR = dyn_cast<VPRecipeWithIRFlags>(&R);
542- if (!DefR || !isa<VPInstruction, VPReplicateRecipe>(DefR))
543- continue ;
544- if ((isa<VPReplicateRecipe>(DefR) &&
545- cast<VPReplicateRecipe>(DefR)->isSingleScalar ()) ||
546- (isa<VPInstruction>(DefR) &&
547- !cast<VPInstruction>(DefR)->doesGeneratePerAllLanes ()))
547+ if (!isa<VPInstruction, VPReplicateRecipe>(&R) ||
548+ (isa<VPReplicateRecipe>(&R) &&
549+ cast<VPReplicateRecipe>(&R)->isSingleScalar ()) ||
550+ (isa<VPInstruction>(&R) &&
551+ !cast<VPInstruction>(&R)->doesGeneratePerAllLanes ()))
548552 continue ;
549553
554+ auto *DefR = dyn_cast<VPRecipeWithIRFlags>(&R);
555+
550556 VPBuilder Builder (DefR);
551557 if (DefR->getNumUsers () == 0 ) {
552558 if (isa<StoreInst>(DefR->getUnderlyingInstr ()) &&
0 commit comments