Skip to content

Commit ac783ad

Browse files
authored
[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.
1 parent 379e55e commit ac783ad

File tree

1 file changed

+4
-4
lines changed
  • llvm/lib/Transforms/Vectorize

1 file changed

+4
-4
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,12 @@ struct VPTransformState {
311311
void set(VPValue *Def, Value *V, const VPIteration &Instance) {
312312
auto Iter = Data.PerPartScalars.insert({Def, {}});
313313
auto &PerPartVec = Iter.first->second;
314-
while (PerPartVec.size() <= Instance.Part)
315-
PerPartVec.emplace_back();
314+
if (PerPartVec.size() <= Instance.Part)
315+
PerPartVec.resize(Instance.Part + 1);
316316
auto &Scalars = PerPartVec[Instance.Part];
317317
unsigned CacheIdx = Instance.Lane.mapToCacheIndex(VF);
318-
while (Scalars.size() <= CacheIdx)
319-
Scalars.push_back(nullptr);
318+
if (Scalars.size() <= CacheIdx)
319+
Scalars.resize(CacheIdx + 1);
320320
assert(!Scalars[CacheIdx] && "should overwrite existing value");
321321
Scalars[CacheIdx] = V;
322322
}

0 commit comments

Comments
 (0)