@@ -852,8 +852,9 @@ void VPlanTransforms::clearReductionWrapFlags(VPlan &Plan) {
852852 }
853853}
854854
855- // / Try to simplify recipe \p R.
856- static void simplifyRecipe (VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
855+ // / Try to simplify recipe \p R. Returns any new recipes introduced during
856+ // / simplification, as a candidate for further simplification.
857+ static VPRecipeBase *simplifyRecipe (VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
857858 using namespace llvm ::VPlanPatternMatch;
858859
859860 if (auto *Blend = dyn_cast<VPBlendRecipe>(&R)) {
@@ -868,11 +869,11 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
868869 if (UniqueValues.size () == 1 ) {
869870 Blend->replaceAllUsesWith (*UniqueValues.begin ());
870871 Blend->eraseFromParent ();
871- return ;
872+ return nullptr ;
872873 }
873874
874875 if (Blend->isNormalized ())
875- return ;
876+ return nullptr ;
876877
877878 // Normalize the blend so its first incoming value is used as the initial
878879 // value with the others blended into it.
@@ -907,7 +908,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
907908 Blend->replaceAllUsesWith (NewBlend);
908909 Blend->eraseFromParent ();
909910 recursivelyDeleteDeadRecipes (DeadMask);
910- return ;
911+ return nullptr ;
911912 }
912913
913914 VPValue *A;
@@ -920,7 +921,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
920921 } else {
921922 // Don't replace a scalarizing recipe with a widened cast.
922923 if (isa<VPReplicateRecipe>(&R))
923- return ;
924+ return nullptr ;
924925 if (ATy->getScalarSizeInBits () < TruncTy->getScalarSizeInBits ()) {
925926
926927 unsigned ExtOpcode = match (R.getOperand (0 ), m_SExt (m_VPValue ()))
@@ -955,6 +956,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
955956 assert (TypeInfo.inferScalarType (VPV) == TypeInfo2.inferScalarType (VPV));
956957 }
957958#endif
959+ return nullptr ;
958960 }
959961
960962 // Simplify (X && Y) || (X && !Y) -> X.
@@ -968,11 +970,12 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
968970 X == X1 && Y == Y1) {
969971 R.getVPSingleValue ()->replaceAllUsesWith (X);
970972 R.eraseFromParent ();
971- return ;
973+ return nullptr ;
972974 }
973975
974976 if (match (&R, m_c_Mul (m_VPValue (A), m_SpecificInt (1 ))))
975- return R.getVPSingleValue ()->replaceAllUsesWith (A);
977+ R.getVPSingleValue ()->replaceAllUsesWith (A);
978+ return nullptr ;
976979}
977980
978981// / Try to simplify the recipes in \p Plan.
@@ -981,8 +984,10 @@ static void simplifyRecipes(VPlan &Plan, LLVMContext &Ctx) {
981984 Plan.getEntry ());
982985 VPTypeAnalysis TypeInfo (Plan.getCanonicalIV ()->getScalarType (), Ctx);
983986 for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
984- for (VPRecipeBase &R : make_early_inc_range (*VPBB)) {
985- simplifyRecipe (R, TypeInfo);
987+ for (auto &R : make_early_inc_range (*VPBB)) {
988+ VPRecipeBase *NewR = simplifyRecipe (R, TypeInfo);
989+ while (NewR)
990+ NewR = simplifyRecipe (*NewR, TypeInfo);
986991 }
987992 }
988993}
0 commit comments