@@ -3800,35 +3800,41 @@ void VPlanTransforms::materializePacksAndUnpacks(VPlan &Plan) {
38003800 // Create explicit VPInstructions to convert vectors to scalars.
38013801 for (VPBasicBlock *VPBB : VPBBsInsideLoopRegion) {
38023802 for (VPRecipeBase &R : make_early_inc_range (*VPBB)) {
3803- if (isa<VPReplicateRecipe, VPInstruction, VPScalarIVStepsRecipe>(&R))
3803+ if (isa<VPReplicateRecipe, VPInstruction, VPScalarIVStepsRecipe,
3804+ VPDerivedIVRecipe, VPCanonicalIVPHIRecipe>(&R))
38043805 continue ;
38053806 for (VPValue *Def : R.definedValues ()) {
3807+ // Skip recipes that are single-scalar or only have their first lane
3808+ // used.
3809+ // TODO: The Defs skipped here may or may not be vector values.
3810+ // Introduce Unpacks, and remove them later, if they are guaranteed to
3811+ // produce scalar values.
38063812 if (vputils::isSingleScalar (Def) || vputils::onlyFirstLaneUsed (Def))
38073813 continue ;
38083814
3809- auto IsInsideReplicateRegion = [LoopRegion](VPUser *U) {
3815+ // At the moment, we only create unpacks for scalar users outside
3816+ // replicate regions. Recipes inside replicate regions still manually
3817+ // extract the required lanes.
3818+ // TODO: Remove once replicate regions are
3819+ // unrolled completely.
3820+ auto IsCandidateUnpackUser = [Def](VPUser *U) {
38103821 VPRegionBlock *ParentRegion =
38113822 cast<VPRecipeBase>(U)->getParent ()->getParent ();
3812- return ParentRegion && ParentRegion != LoopRegion;
3823+ return U->usesScalars (Def) &&
3824+ (!ParentRegion || !ParentRegion->isReplicator ());
38133825 };
3814- // At the moment, we only create unpacks for scalar users outside
3815- // replicate regions. Recipes inside replicate regions still manually
3816- // extract the required lanes. TODO: Remove once replicate regions are
3817- // unrolled explicitly.
3818- if (none_of (Def->users (), [Def, &IsInsideReplicateRegion](VPUser *U) {
3819- return !IsInsideReplicateRegion (U) && U->usesScalars (Def);
3820- }))
3826+ if (none_of (Def->users (), IsCandidateUnpackUser))
38213827 continue ;
38223828
38233829 auto *Unpack = new VPInstruction (VPInstruction::Unpack, {Def});
38243830 if (R.isPhi ())
38253831 Unpack->insertBefore (*VPBB, VPBB->getFirstNonPhi ());
38263832 else
38273833 Unpack->insertAfter (&R);
3828- Def->replaceUsesWithIf (
3829- Unpack, [Def, &IsInsideReplicateRegion ](VPUser &U, unsigned ) {
3830- return ! IsInsideReplicateRegion (&U) && U. usesScalars (Def );
3831- });
3834+ Def->replaceUsesWithIf (Unpack,
3835+ [&IsCandidateUnpackUser ](VPUser &U, unsigned ) {
3836+ return IsCandidateUnpackUser (&U);
3837+ });
38323838 }
38333839 }
38343840 }
0 commit comments