@@ -8693,12 +8693,12 @@ bool ScalarEvolution::BackedgeTakenInfo::isConstantMaxOrZero(
8693
8693
}
8694
8694
8695
8695
ScalarEvolution::ExitLimit::ExitLimit(const SCEV *E)
8696
- : ExitLimit(E, E, E, false, {} ) {}
8696
+ : ExitLimit(E, E, E, false) {}
8697
8697
8698
8698
ScalarEvolution::ExitLimit::ExitLimit(
8699
8699
const SCEV *E, const SCEV *ConstantMaxNotTaken,
8700
8700
const SCEV *SymbolicMaxNotTaken, bool MaxOrZero,
8701
- ArrayRef<const SmallPtrSetImpl <const SCEVPredicate *> *> PredSetList )
8701
+ ArrayRef<ArrayRef <const SCEVPredicate *>> PredLists )
8702
8702
: ExactNotTaken(E), ConstantMaxNotTaken(ConstantMaxNotTaken),
8703
8703
SymbolicMaxNotTaken(SymbolicMaxNotTaken), MaxOrZero(MaxOrZero) {
8704
8704
// If we prove the max count is zero, so is the symbolic bound. This happens
@@ -8721,22 +8721,29 @@ ScalarEvolution::ExitLimit::ExitLimit(
8721
8721
assert((isa<SCEVCouldNotCompute>(ConstantMaxNotTaken) ||
8722
8722
isa<SCEVConstant>(ConstantMaxNotTaken)) &&
8723
8723
"No point in having a non-constant max backedge taken count!");
8724
- for (const auto *PredSet : PredSetList)
8725
- for (const auto *P : *PredSet)
8726
- addPredicate(P);
8724
+ SmallPtrSet<const SCEVPredicate *, 4> SeenPreds;
8725
+ for (const auto PredList : PredLists)
8726
+ for (const auto *P : PredList) {
8727
+ if (SeenPreds.contains(P))
8728
+ continue;
8729
+ assert(!isa<SCEVUnionPredicate>(P) && "Only add leaf predicates here!");
8730
+ SeenPreds.insert(P);
8731
+ Predicates.push_back(P);
8732
+ }
8727
8733
assert((isa<SCEVCouldNotCompute>(E) || !E->getType()->isPointerTy()) &&
8728
8734
"Backedge count should be int");
8729
8735
assert((isa<SCEVCouldNotCompute>(ConstantMaxNotTaken) ||
8730
8736
!ConstantMaxNotTaken->getType()->isPointerTy()) &&
8731
8737
"Max backedge count should be int");
8732
8738
}
8733
8739
8734
- ScalarEvolution::ExitLimit::ExitLimit(
8735
- const SCEV *E, const SCEV *ConstantMaxNotTaken,
8736
- const SCEV *SymbolicMaxNotTaken, bool MaxOrZero,
8737
- const SmallPtrSetImpl<const SCEVPredicate *> &PredSet)
8740
+ ScalarEvolution::ExitLimit::ExitLimit(const SCEV *E,
8741
+ const SCEV *ConstantMaxNotTaken,
8742
+ const SCEV *SymbolicMaxNotTaken,
8743
+ bool MaxOrZero,
8744
+ ArrayRef<const SCEVPredicate *> PredList)
8738
8745
: ExitLimit(E, ConstantMaxNotTaken, SymbolicMaxNotTaken, MaxOrZero,
8739
- { &PredSet } ) {}
8746
+ ArrayRef({PredList}) ) {}
8740
8747
8741
8748
/// Allocate memory for BackedgeTakenInfo and copy the not-taken count of each
8742
8749
/// computable exit into a persistent ExitNotTakenInfo array.
@@ -9098,7 +9105,7 @@ ScalarEvolution::computeExitLimitFromCondFromBinOp(
9098
9105
SymbolicMaxBECount =
9099
9106
isa<SCEVCouldNotCompute>(BECount) ? ConstantMaxBECount : BECount;
9100
9107
return ExitLimit(BECount, ConstantMaxBECount, SymbolicMaxBECount, false,
9101
- { & EL0.Predicates, & EL1.Predicates });
9108
+ {ArrayRef( EL0.Predicates), ArrayRef( EL1.Predicates) });
9102
9109
}
9103
9110
9104
9111
ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromICmp(
@@ -10131,7 +10138,7 @@ const SCEV *ScalarEvolution::stripInjectiveFunctions(const SCEV *S) const {
10131
10138
/// If the equation does not have a solution, SCEVCouldNotCompute is returned.
10132
10139
static const SCEV *
10133
10140
SolveLinEquationWithOverflow(const APInt &A, const SCEV *B,
10134
- SmallPtrSetImpl <const SCEVPredicate *> *Predicates,
10141
+ SmallVectorImpl <const SCEVPredicate *> *Predicates,
10135
10142
10136
10143
ScalarEvolution &SE) {
10137
10144
uint32_t BW = A.getBitWidth();
@@ -10162,7 +10169,7 @@ SolveLinEquationWithOverflow(const APInt &A, const SCEV *B,
10162
10169
// Avoid adding a predicate that is known to be false.
10163
10170
if (SE.isKnownPredicate(CmpInst::ICMP_NE, URem, Zero))
10164
10171
return SE.getCouldNotCompute();
10165
- Predicates->insert (SE.getEqualPredicate(URem, Zero));
10172
+ Predicates->push_back (SE.getEqualPredicate(URem, Zero));
10166
10173
}
10167
10174
}
10168
10175
@@ -10466,7 +10473,7 @@ ScalarEvolution::ExitLimit ScalarEvolution::howFarToZero(const SCEV *V,
10466
10473
// effectively V != 0. We know and take advantage of the fact that this
10467
10474
// expression only being used in a comparison by zero context.
10468
10475
10469
- SmallPtrSet <const SCEVPredicate *, 4 > Predicates;
10476
+ SmallVector <const SCEVPredicate *> Predicates;
10470
10477
// If the value is a constant
10471
10478
if (const SCEVConstant *C = dyn_cast<SCEVConstant>(V)) {
10472
10479
// If the value is already zero, the branch will execute zero times.
@@ -12885,7 +12892,7 @@ ScalarEvolution::ExitLimit
12885
12892
ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
12886
12893
const Loop *L, bool IsSigned,
12887
12894
bool ControlsOnlyExit, bool AllowPredicates) {
12888
- SmallPtrSet <const SCEVPredicate *, 4 > Predicates;
12895
+ SmallVector <const SCEVPredicate *> Predicates;
12889
12896
12890
12897
const SCEVAddRecExpr *IV = dyn_cast<SCEVAddRecExpr>(LHS);
12891
12898
bool PredicatedIV = false;
@@ -13325,7 +13332,7 @@ ScalarEvolution::howManyLessThans(const SCEV *LHS, const SCEV *RHS,
13325
13332
ScalarEvolution::ExitLimit ScalarEvolution::howManyGreaterThans(
13326
13333
const SCEV *LHS, const SCEV *RHS, const Loop *L, bool IsSigned,
13327
13334
bool ControlsOnlyExit, bool AllowPredicates) {
13328
- SmallPtrSet <const SCEVPredicate *, 4 > Predicates;
13335
+ SmallVector <const SCEVPredicate *> Predicates;
13329
13336
// We handle only IV > Invariant
13330
13337
if (!isLoopInvariant(RHS, L))
13331
13338
return getCouldNotCompute();
@@ -13695,7 +13702,7 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
13695
13702
PrintSCEVWithTypeHint(OS, EC);
13696
13703
if (isa<SCEVCouldNotCompute>(EC)) {
13697
13704
// Retry with predicates.
13698
- SmallVector<const SCEVPredicate *, 4 > Predicates;
13705
+ SmallVector<const SCEVPredicate *> Predicates;
13699
13706
EC = SE->getPredicatedExitCount(L, ExitingBlock, &Predicates);
13700
13707
if (!isa<SCEVCouldNotCompute>(EC)) {
13701
13708
OS << "\n predicated exit count for " << ExitingBlock->getName()
@@ -13747,7 +13754,7 @@ static void PrintLoopInfo(raw_ostream &OS, ScalarEvolution *SE,
13747
13754
PrintSCEVWithTypeHint(OS, ExitBTC);
13748
13755
if (isa<SCEVCouldNotCompute>(ExitBTC)) {
13749
13756
// Retry with predicates.
13750
- SmallVector<const SCEVPredicate *, 4 > Predicates;
13757
+ SmallVector<const SCEVPredicate *> Predicates;
13751
13758
ExitBTC = SE->getPredicatedExitCount(L, ExitingBlock, &Predicates,
13752
13759
ScalarEvolution::SymbolicMaximum);
13753
13760
if (!isa<SCEVCouldNotCompute>(ExitBTC)) {
@@ -14727,7 +14734,7 @@ class SCEVPredicateRewriter : public SCEVRewriteVisitor<SCEVPredicateRewriter> {
14727
14734
/// If \p NewPreds is non-null, rewrite is free to add further predicates to
14728
14735
/// \p NewPreds such that the result will be an AddRecExpr.
14729
14736
static const SCEV *rewrite(const SCEV *S, const Loop *L, ScalarEvolution &SE,
14730
- SmallPtrSetImpl <const SCEVPredicate *> *NewPreds,
14737
+ SmallVectorImpl <const SCEVPredicate *> *NewPreds,
14731
14738
const SCEVPredicate *Pred) {
14732
14739
SCEVPredicateRewriter Rewriter(L, SE, NewPreds, Pred);
14733
14740
return Rewriter.visit(S);
@@ -14783,17 +14790,18 @@ class SCEVPredicateRewriter : public SCEVRewriteVisitor<SCEVPredicateRewriter> {
14783
14790
}
14784
14791
14785
14792
private:
14786
- explicit SCEVPredicateRewriter(const Loop *L, ScalarEvolution &SE,
14787
- SmallPtrSetImpl<const SCEVPredicate *> *NewPreds,
14788
- const SCEVPredicate *Pred)
14793
+ explicit SCEVPredicateRewriter(
14794
+ const Loop *L, ScalarEvolution &SE,
14795
+ SmallVectorImpl<const SCEVPredicate *> *NewPreds,
14796
+ const SCEVPredicate *Pred)
14789
14797
: SCEVRewriteVisitor(SE), NewPreds(NewPreds), Pred(Pred), L(L) {}
14790
14798
14791
14799
bool addOverflowAssumption(const SCEVPredicate *P) {
14792
14800
if (!NewPreds) {
14793
14801
// Check if we've already made this assumption.
14794
14802
return Pred && Pred->implies(P);
14795
14803
}
14796
- NewPreds->insert (P);
14804
+ NewPreds->push_back (P);
14797
14805
return true;
14798
14806
}
14799
14807
@@ -14829,7 +14837,7 @@ class SCEVPredicateRewriter : public SCEVRewriteVisitor<SCEVPredicateRewriter> {
14829
14837
return PredicatedRewrite->first;
14830
14838
}
14831
14839
14832
- SmallPtrSetImpl <const SCEVPredicate *> *NewPreds;
14840
+ SmallVectorImpl <const SCEVPredicate *> *NewPreds;
14833
14841
const SCEVPredicate *Pred;
14834
14842
const Loop *L;
14835
14843
};
@@ -14844,8 +14852,8 @@ ScalarEvolution::rewriteUsingPredicate(const SCEV *S, const Loop *L,
14844
14852
14845
14853
const SCEVAddRecExpr *ScalarEvolution::convertSCEVToAddRecWithPredicates(
14846
14854
const SCEV *S, const Loop *L,
14847
- SmallPtrSetImpl <const SCEVPredicate *> &Preds) {
14848
- SmallPtrSet <const SCEVPredicate *, 4 > TransformPreds;
14855
+ SmallVectorImpl <const SCEVPredicate *> &Preds) {
14856
+ SmallVector <const SCEVPredicate *> TransformPreds;
14849
14857
S = SCEVPredicateRewriter::rewrite(S, L, *this, &TransformPreds, nullptr);
14850
14858
auto *AddRec = dyn_cast<SCEVAddRecExpr>(S);
14851
14859
@@ -14854,7 +14862,7 @@ const SCEVAddRecExpr *ScalarEvolution::convertSCEVToAddRecWithPredicates(
14854
14862
14855
14863
// Since the transformation was successful, we can now transfer the SCEV
14856
14864
// predicates.
14857
- Preds.insert (TransformPreds.begin(), TransformPreds.end());
14865
+ Preds.append (TransformPreds.begin(), TransformPreds.end());
14858
14866
14859
14867
return AddRec;
14860
14868
}
@@ -15101,7 +15109,7 @@ bool PredicatedScalarEvolution::hasNoOverflow(
15101
15109
15102
15110
const SCEVAddRecExpr *PredicatedScalarEvolution::getAsAddRec(Value *V) {
15103
15111
const SCEV *Expr = this->getSCEV(V);
15104
- SmallPtrSet <const SCEVPredicate *, 4> NewPreds;
15112
+ SmallVector <const SCEVPredicate *, 4> NewPreds;
15105
15113
auto *New = SE.convertSCEVToAddRecWithPredicates(Expr, &L, NewPreds);
15106
15114
15107
15115
if (!New)
0 commit comments