[llvm] [LV] Use SmallVector::resize instead of push_back/emplace_back in a loop. NFC (PR #83696)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 2 17:06:13 PST 2024
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/83696
This should be more efficient since the vector can know how much additional space to reserve before creating the new elements.
>From 60a8d51b667bdc6da08ff09483ae7c3a0ff491a6 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Sat, 2 Mar 2024 17:03:36 -0800
Subject: [PATCH] [LV] Use SmallVector::resize instead of
push_back/emplace_back in a loop. NFC
This should be more efficient since the vector can know how much
additional space to reserve before creating the new elements.
---
llvm/lib/Transforms/Vectorize/VPlan.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
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