[llvm] 898fcfa - [NFC][SCEV] `computeSCEVAtScope()`: reserve vector size upfront

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 21 12:53:50 PST 2023


Author: Roman Lebedev
Date: 2023-01-21T23:52:51+03:00
New Revision: 898fcfac216e21860d5f687e6cbb61623ff42061

URL: https://github.com/llvm/llvm-project/commit/898fcfac216e21860d5f687e6cbb61623ff42061
DIFF: https://github.com/llvm/llvm-project/commit/898fcfac216e21860d5f687e6cbb61623ff42061.diff

LOG: [NFC][SCEV] `computeSCEVAtScope()`: reserve vector size upfront

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index d4b7873ba993..732f5921b535 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -9833,7 +9833,9 @@ const SCEV *ScalarEvolution::computeSCEVAtScope(const SCEV *V, const Loop *L) {
 
       // Okay, at least one of these operands is loop variant but might be
       // foldable.  Build a new instance of the folded commutative expression.
-      SmallVector<const SCEV *, 8> NewOps(AddRec->operands().take_front(i));
+      SmallVector<const SCEV *, 8> NewOps;
+      NewOps.reserve(AddRec->getNumOperands());
+      append_range(NewOps, AddRec->operands().take_front(i));
       NewOps.push_back(OpAtScope);
       for (++i; i != e; ++i)
         NewOps.push_back(getSCEVAtScope(AddRec->getOperand(i), L));
@@ -9879,7 +9881,9 @@ const SCEV *ScalarEvolution::computeSCEVAtScope(const SCEV *V, const Loop *L) {
       if (OpAtScope != Comm->getOperand(i)) {
         // Okay, at least one of these operands is loop variant but might be
         // foldable.  Build a new instance of the folded commutative expression.
-        SmallVector<const SCEV *, 8> NewOps(Comm->operands().take_front(i));
+        SmallVector<const SCEV *, 8> NewOps;
+        NewOps.reserve(Comm->getNumOperands());
+        append_range(NewOps, Comm->operands().take_front(i));
         NewOps.push_back(OpAtScope);
 
         for (++i; i != e; ++i) {
@@ -9979,6 +9983,7 @@ const SCEV *ScalarEvolution::computeSCEVAtScope(const SCEV *V, const Loop *L) {
       return V; // This is some other type of SCEVUnknown, just return it.
 
     SmallVector<Constant *, 4> Operands;
+    Operands.reserve(I->getNumOperands());
     bool MadeImprovement = false;
     for (Value *Op : I->operands()) {
       if (Constant *C = dyn_cast<Constant>(Op)) {


        


More information about the llvm-commits mailing list