@@ -5947,6 +5947,8 @@ ScalarEvolution::BackedgeTakenInfo::getMax(ScalarEvolution *SE) const {
5947
5947
if (any_of (ExitNotTaken, PredicateNotAlwaysTrue) || !getMax ())
5948
5948
return SE->getCouldNotCompute ();
5949
5949
5950
+ assert ((isa<SCEVCouldNotCompute>(getMax ()) || isa<SCEVConstant>(getMax ())) &&
5951
+ " No point in having a non-constant max backedge taken count!" );
5950
5952
return getMax ();
5951
5953
}
5952
5954
@@ -5972,7 +5974,11 @@ bool ScalarEvolution::BackedgeTakenInfo::hasOperand(const SCEV *S,
5972
5974
}
5973
5975
5974
5976
ScalarEvolution::ExitLimit::ExitLimit (const SCEV *E)
5975
- : ExactNotTaken(E), MaxNotTaken(E), MaxOrZero(false ) {}
5977
+ : ExactNotTaken(E), MaxNotTaken(E), MaxOrZero(false ) {
5978
+ assert ((isa<SCEVCouldNotCompute>(MaxNotTaken) ||
5979
+ isa<SCEVConstant>(MaxNotTaken)) &&
5980
+ " No point in having a non-constant max backedge taken count!" );
5981
+ }
5976
5982
5977
5983
ScalarEvolution::ExitLimit::ExitLimit (
5978
5984
const SCEV *E, const SCEV *M, bool MaxOrZero,
@@ -5981,6 +5987,9 @@ ScalarEvolution::ExitLimit::ExitLimit(
5981
5987
assert ((isa<SCEVCouldNotCompute>(ExactNotTaken) ||
5982
5988
!isa<SCEVCouldNotCompute>(MaxNotTaken)) &&
5983
5989
" Exact is not allowed to be less precise than Max" );
5990
+ assert ((isa<SCEVCouldNotCompute>(MaxNotTaken) ||
5991
+ isa<SCEVConstant>(MaxNotTaken)) &&
5992
+ " No point in having a non-constant max backedge taken count!" );
5984
5993
for (auto *PredSet : PredSetList)
5985
5994
for (auto *P : *PredSet)
5986
5995
addPredicate (P);
@@ -5989,11 +5998,19 @@ ScalarEvolution::ExitLimit::ExitLimit(
5989
5998
ScalarEvolution::ExitLimit::ExitLimit (
5990
5999
const SCEV *E, const SCEV *M, bool MaxOrZero,
5991
6000
const SmallPtrSetImpl<const SCEVPredicate *> &PredSet)
5992
- : ExitLimit(E, M, MaxOrZero, {&PredSet}) {}
6001
+ : ExitLimit(E, M, MaxOrZero, {&PredSet}) {
6002
+ assert ((isa<SCEVCouldNotCompute>(MaxNotTaken) ||
6003
+ isa<SCEVConstant>(MaxNotTaken)) &&
6004
+ " No point in having a non-constant max backedge taken count!" );
6005
+ }
5993
6006
5994
6007
ScalarEvolution::ExitLimit::ExitLimit (const SCEV *E, const SCEV *M,
5995
6008
bool MaxOrZero)
5996
- : ExitLimit(E, M, MaxOrZero, None) {}
6009
+ : ExitLimit(E, M, MaxOrZero, None) {
6010
+ assert ((isa<SCEVCouldNotCompute>(MaxNotTaken) ||
6011
+ isa<SCEVConstant>(MaxNotTaken)) &&
6012
+ " No point in having a non-constant max backedge taken count!" );
6013
+ }
5997
6014
5998
6015
// / Allocate memory for BackedgeTakenInfo and copy the not-taken count of each
5999
6016
// / computable exit into a persistent ExitNotTakenInfo array.
@@ -6018,6 +6035,8 @@ ScalarEvolution::BackedgeTakenInfo::BackedgeTakenInfo(
6018
6035
6019
6036
return ExitNotTakenInfo (ExitBB, EL.ExactNotTaken , std::move (Predicate));
6020
6037
});
6038
+ assert ((isa<SCEVCouldNotCompute>(MaxCount) || isa<SCEVConstant>(MaxCount)) &&
6039
+ " No point in having a non-constant max backedge taken count!" );
6021
6040
}
6022
6041
6023
6042
// / Invalidate this result and free the ExitNotTakenInfo array.
@@ -6279,7 +6298,7 @@ ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromCondImpl(
6279
6298
// to not.
6280
6299
if (isa<SCEVCouldNotCompute>(MaxBECount) &&
6281
6300
!isa<SCEVCouldNotCompute>(BECount))
6282
- MaxBECount = BECount;
6301
+ MaxBECount = getConstant ( getUnsignedRange ( BECount). getUnsignedMax ()) ;
6283
6302
6284
6303
return ExitLimit (BECount, MaxBECount, false ,
6285
6304
{&EL0.Predicates , &EL1.Predicates });
@@ -7583,13 +7602,20 @@ ScalarEvolution::howFarToZero(const SCEV *V, const Loop *L, bool ControlsExit,
7583
7602
loopHasNoAbnormalExits (AddRec->getLoop ())) {
7584
7603
const SCEV *Exact =
7585
7604
getUDivExpr (Distance, CountDown ? getNegativeSCEV (Step) : Step);
7586
- return ExitLimit (Exact, Exact, false , Predicates);
7605
+ const SCEV *Max =
7606
+ Exact == getCouldNotCompute ()
7607
+ ? Exact
7608
+ : getConstant (getUnsignedRange (Exact).getUnsignedMax ());
7609
+ return ExitLimit (Exact, Max, false , Predicates);
7587
7610
}
7588
7611
7589
7612
// Solve the general equation.
7590
- const SCEV *E = SolveLinEquationWithOverflow (
7591
- StepC->getAPInt (), getNegativeSCEV (Start), *this );
7592
- return ExitLimit (E, E, false , Predicates);
7613
+ const SCEV *E = SolveLinEquationWithOverflow (StepC->getAPInt (),
7614
+ getNegativeSCEV (Start), *this );
7615
+ const SCEV *M = E == getCouldNotCompute ()
7616
+ ? E
7617
+ : getConstant (getUnsignedRange (E).getUnsignedMax ());
7618
+ return ExitLimit (E, M, false , Predicates);
7593
7619
}
7594
7620
7595
7621
ScalarEvolution::ExitLimit
@@ -9218,8 +9244,9 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
9218
9244
getConstant (StrideForMaxBECount), false );
9219
9245
}
9220
9246
9221
- if (isa<SCEVCouldNotCompute>(MaxBECount))
9222
- MaxBECount = BECount;
9247
+ if (isa<SCEVCouldNotCompute>(MaxBECount) &&
9248
+ !isa<SCEVCouldNotCompute>(BECount))
9249
+ MaxBECount = getConstant (getUnsignedRange (BECount).getUnsignedMax ());
9223
9250
9224
9251
return ExitLimit (BECount, MaxBECount, MaxOrZero, Predicates);
9225
9252
}
0 commit comments