[llvm] 270ee65 - [Analysis][NFC] Clean-up in ScalarEvolution when copying predicates (#108851)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 17 02:28:29 PDT 2024
Author: David Sherwood
Date: 2024-09-17T10:28:24+01:00
New Revision: 270ee6549c9368b2ff86ef9794a7fd5e5496ef00
URL: https://github.com/llvm/llvm-project/commit/270ee6549c9368b2ff86ef9794a7fd5e5496ef00
DIFF: https://github.com/llvm/llvm-project/commit/270ee6549c9368b2ff86ef9794a7fd5e5496ef00.diff
LOG: [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.
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 57e03f667ba6ff..e06863b6deb902 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -8594,8 +8594,7 @@ const SCEV *ScalarEvolution::BackedgeTakenInfo::getExact(
Ops.push_back(BECount);
if (Preds)
- for (const auto *P : ENT.Predicates)
- Preds->push_back(P);
+ append_range(*Preds, ENT.Predicates);
assert((Preds || ENT.hasAlwaysTruePredicate()) &&
"Predicate should be always true!");
@@ -8616,8 +8615,7 @@ ScalarEvolution::BackedgeTakenInfo::getExitNotTaken(
if (ENT.hasAlwaysTruePredicate())
return &ENT;
else if (Predicates) {
- for (const auto *P : ENT.Predicates)
- Predicates->push_back(P);
+ append_range(*Predicates, ENT.Predicates);
return &ENT;
}
}
@@ -8659,8 +8657,7 @@ const SCEV *ScalarEvolution::BackedgeTakenInfo::getSymbolicMax(
"dominate latch!");
ExitCounts.push_back(ExitCount);
if (Predicates)
- for (const auto *P : ENT.Predicates)
- Predicates->push_back(P);
+ append_range(*Predicates, ENT.Predicates);
assert((Predicates || ENT.hasAlwaysTruePredicate()) &&
"Predicate should be always true!");
@@ -14804,8 +14801,7 @@ const SCEVAddRecExpr *ScalarEvolution::convertSCEVToAddRecWithPredicates(
// Since the transformation was successful, we can now transfer the SCEV
// predicates.
- for (const auto *P : TransformPreds)
- Preds.insert(P);
+ Preds.insert(TransformPreds.begin(), TransformPreds.end());
return AddRec;
}
More information about the llvm-commits
mailing list