[llvm] ac783ad - [LV] Use SmallVector::resize instead of push_back/emplace_back in a loop. NFC (#83696)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 4 10:01:28 PST 2024
Author: Craig Topper
Date: 2024-03-04T10:01:24-08:00
New Revision: ac783addc4dd5bda557cc07b90c08bab2d110ec3
URL: https://github.com/llvm/llvm-project/commit/ac783addc4dd5bda557cc07b90c08bab2d110ec3
DIFF: https://github.com/llvm/llvm-project/commit/ac783addc4dd5bda557cc07b90c08bab2d110ec3.diff
LOG: [LV] Use SmallVector::resize instead of push_back/emplace_back in a loop. NFC (#83696)
This should be more efficient since the vector can know how much
additional space to reserve before creating the new elements.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.h
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 16c09a83e777dd..bc499400bced84 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -311,12 +311,12 @@ struct VPTransformState {
void set(VPValue *Def, Value *V, const VPIteration &Instance) {
auto Iter = Data.PerPartScalars.insert({Def, {}});
auto &PerPartVec = Iter.first->second;
- while (PerPartVec.size() <= Instance.Part)
- PerPartVec.emplace_back();
+ if (PerPartVec.size() <= Instance.Part)
+ PerPartVec.resize(Instance.Part + 1);
auto &Scalars = PerPartVec[Instance.Part];
unsigned CacheIdx = Instance.Lane.mapToCacheIndex(VF);
- while (Scalars.size() <= CacheIdx)
- Scalars.push_back(nullptr);
+ if (Scalars.size() <= CacheIdx)
+ Scalars.resize(CacheIdx + 1);
assert(!Scalars[CacheIdx] && "should overwrite existing value");
Scalars[CacheIdx] = V;
}
More information about the llvm-commits
mailing list