@@ -852,8 +852,9 @@ void VPlanTransforms::clearReductionWrapFlags(VPlan &Plan) {
852
852
}
853
853
}
854
854
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) {
857
858
using namespace llvm ::VPlanPatternMatch;
858
859
859
860
if (auto *Blend = dyn_cast<VPBlendRecipe>(&R)) {
@@ -868,11 +869,11 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
868
869
if (UniqueValues.size () == 1 ) {
869
870
Blend->replaceAllUsesWith (*UniqueValues.begin ());
870
871
Blend->eraseFromParent ();
871
- return ;
872
+ return nullptr ;
872
873
}
873
874
874
875
if (Blend->isNormalized ())
875
- return ;
876
+ return nullptr ;
876
877
877
878
// Normalize the blend so its first incoming value is used as the initial
878
879
// value with the others blended into it.
@@ -907,7 +908,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
907
908
Blend->replaceAllUsesWith (NewBlend);
908
909
Blend->eraseFromParent ();
909
910
recursivelyDeleteDeadRecipes (DeadMask);
910
- return ;
911
+ return nullptr ;
911
912
}
912
913
913
914
VPValue *A;
@@ -920,7 +921,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
920
921
} else {
921
922
// Don't replace a scalarizing recipe with a widened cast.
922
923
if (isa<VPReplicateRecipe>(&R))
923
- return ;
924
+ return nullptr ;
924
925
if (ATy->getScalarSizeInBits () < TruncTy->getScalarSizeInBits ()) {
925
926
926
927
unsigned ExtOpcode = match (R.getOperand (0 ), m_SExt (m_VPValue ()))
@@ -955,6 +956,7 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
955
956
assert (TypeInfo.inferScalarType (VPV) == TypeInfo2.inferScalarType (VPV));
956
957
}
957
958
#endif
959
+ return nullptr ;
958
960
}
959
961
960
962
// Simplify (X && Y) || (X && !Y) -> X.
@@ -968,11 +970,12 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
968
970
X == X1 && Y == Y1) {
969
971
R.getVPSingleValue ()->replaceAllUsesWith (X);
970
972
R.eraseFromParent ();
971
- return ;
973
+ return nullptr ;
972
974
}
973
975
974
976
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 ;
976
979
}
977
980
978
981
// / Try to simplify the recipes in \p Plan.
@@ -981,8 +984,10 @@ static void simplifyRecipes(VPlan &Plan, LLVMContext &Ctx) {
981
984
Plan.getEntry ());
982
985
VPTypeAnalysis TypeInfo (Plan.getCanonicalIV ()->getScalarType (), Ctx);
983
986
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);
986
991
}
987
992
}
988
993
}
0 commit comments