Skip to content

Commit 270ee65

Browse files
authored
[Analysis][NFC] Clean-up in ScalarEvolution when copying predicates (#108851)
There are a few places in ScalarEvolution.cpp where we copy predicates from one list to another and they have a similar pattern: for (const auto *P : ENT.Predicates) Predicates->push_back(P); We can avoid the loop by writing them like this: Predicates->append(ENT.Predicates.begin(), ENT.Predicates.end()); which may end up being more efficient since we only have to try reserving more space once.
1 parent 1e64864 commit 270ee65

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8594,8 +8594,7 @@ const SCEV *ScalarEvolution::BackedgeTakenInfo::getExact(
85948594
Ops.push_back(BECount);
85958595

85968596
if (Preds)
8597-
for (const auto *P : ENT.Predicates)
8598-
Preds->push_back(P);
8597+
append_range(*Preds, ENT.Predicates);
85998598

86008599
assert((Preds || ENT.hasAlwaysTruePredicate()) &&
86018600
"Predicate should be always true!");
@@ -8616,8 +8615,7 @@ ScalarEvolution::BackedgeTakenInfo::getExitNotTaken(
86168615
if (ENT.hasAlwaysTruePredicate())
86178616
return &ENT;
86188617
else if (Predicates) {
8619-
for (const auto *P : ENT.Predicates)
8620-
Predicates->push_back(P);
8618+
append_range(*Predicates, ENT.Predicates);
86218619
return &ENT;
86228620
}
86238621
}
@@ -8659,8 +8657,7 @@ const SCEV *ScalarEvolution::BackedgeTakenInfo::getSymbolicMax(
86598657
"dominate latch!");
86608658
ExitCounts.push_back(ExitCount);
86618659
if (Predicates)
8662-
for (const auto *P : ENT.Predicates)
8663-
Predicates->push_back(P);
8660+
append_range(*Predicates, ENT.Predicates);
86648661

86658662
assert((Predicates || ENT.hasAlwaysTruePredicate()) &&
86668663
"Predicate should be always true!");
@@ -14804,8 +14801,7 @@ const SCEVAddRecExpr *ScalarEvolution::convertSCEVToAddRecWithPredicates(
1480414801

1480514802
// Since the transformation was successful, we can now transfer the SCEV
1480614803
// predicates.
14807-
for (const auto *P : TransformPreds)
14808-
Preds.insert(P);
14804+
Preds.insert(TransformPreds.begin(), TransformPreds.end());
1480914805

1481014806
return AddRec;
1481114807
}

0 commit comments

Comments
 (0)