@@ -972,8 +972,25 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
972972 if (match (&R, m_c_Mul (m_VPValue (A), m_SpecificInt (1 ))))
973973 return R.getVPSingleValue ()->replaceAllUsesWith (A);
974974
975- if (match (&R, m_Not (m_Not (m_VPValue (A)))))
976- return R.getVPSingleValue ()->replaceAllUsesWith (A);
975+ if (match (&R, m_Not (m_VPValue (A)))) {
976+ if (match (A, m_Not (m_VPValue (A))))
977+ return R.getVPSingleValue ()->replaceAllUsesWith (A);
978+
979+ // Try to fold Not into compares by adjusting the predicate in-place.
980+ if (isa<VPWidenRecipe>(A) && A->getNumUsers () == 1 ) {
981+ auto *WideCmp = cast<VPWidenRecipe>(A);
982+ if (WideCmp->getOpcode () == Instruction::ICmp ||
983+ WideCmp->getOpcode () == Instruction::FCmp) {
984+ WideCmp->setPredicate (
985+ CmpInst::getInversePredicate (WideCmp->getPredicate ()));
986+ R.getVPSingleValue ()->replaceAllUsesWith (WideCmp);
987+ // If WideCmp doesn't have a debug location, use the one from the
988+ // negation, to preserve the location.
989+ if (!WideCmp->getDebugLoc () && R.getDebugLoc ())
990+ WideCmp->setDebugLoc (R.getDebugLoc ());
991+ }
992+ }
993+ }
977994
978995 // Remove redundant DerviedIVs, that is 0 + A * 1 -> A and 0 + 0 * x -> 0.
979996 if ((match (&R,
@@ -983,21 +1000,6 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
9831000 TypeInfo.inferScalarType (R.getOperand (1 )) ==
9841001 TypeInfo.inferScalarType (R.getVPSingleValue ()))
9851002 return R.getVPSingleValue ()->replaceAllUsesWith (R.getOperand (1 ));
986-
987- if (match (&R, m_Not (m_VPValue (A))) && isa<VPWidenRecipe>(A) &&
988- A->getNumUsers () == 1 ) {
989- auto *WideCmp = cast<VPWidenRecipe>(A);
990- if (WideCmp->getOpcode () == Instruction::ICmp ||
991- WideCmp->getOpcode () == Instruction::FCmp) {
992- WideCmp->setPredicate (
993- CmpInst::getInversePredicate (WideCmp->getPredicate ()));
994- R.getVPSingleValue ()->replaceAllUsesWith (WideCmp);
995- // If WideCmp doesn't have a debug location, use the one from the
996- // negation, to preserve the location.
997- if (!WideCmp->getDebugLoc ())
998- WideCmp->setDebugLoc (R.getDebugLoc ());
999- }
1000- }
10011003}
10021004
10031005void VPlanTransforms::simplifyRecipes (VPlan &Plan, Type &CanonicalIVTy) {
0 commit comments