@@ -969,6 +969,32 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
969
969
970
970
if (match (&R, m_c_Mul (m_VPValue (A), m_SpecificInt (1 ))))
971
971
return R.getVPSingleValue ()->replaceAllUsesWith (A);
972
+
973
+ if (auto *DerivedIV = dyn_cast<VPDerivedIVRecipe>(&R)) {
974
+ VPValue *Start = DerivedIV->getStartValue ();
975
+ VPValue *Step = DerivedIV->getStepValue ();
976
+ VPValue *Op = DerivedIV->getOperand (1 );
977
+ if (Step->isLiveIn () && Start->isLiveIn ()) {
978
+ auto *StartC = dyn_cast<ConstantInt>(Start->getLiveInIRValue ());
979
+ auto *StepC = dyn_cast<ConstantInt>(Step->getLiveInIRValue ());
980
+ if (Op->isLiveIn ()) {
981
+ auto *OpC = dyn_cast_if_present<ConstantInt>(Op->getUnderlyingValue ());
982
+ if (OpC && OpC->getType () == StepC->getType () && StartC->getType ()) {
983
+ APInt Folded =
984
+ StartC->getValue () + OpC->getValue () * StepC->getValue ();
985
+ DerivedIV->replaceAllUsesWith (
986
+ R.getParent ()->getPlan ()->getOrAddLiveIn (
987
+ ConstantInt::get (TypeInfo.getContext (), Folded)));
988
+ }
989
+ }
990
+ if (StartC && StartC->isZero () && StepC && StepC->isOne () &&
991
+ TypeInfo.inferScalarType (DerivedIV) ==
992
+ TypeInfo.inferScalarType (DerivedIV->getOperand (1 ))) {
993
+ DerivedIV->replaceAllUsesWith (DerivedIV->getOperand (1 ));
994
+ DerivedIV->eraseFromParent ();
995
+ }
996
+ }
997
+ }
972
998
}
973
999
974
1000
// / Move loop-invariant recipes out of the vector loop region in \p Plan.
0 commit comments