[PATCH] D135977: [LV] Simplify register usage code and avoid double map lookups.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 14 11:20:25 PDT 2022
craig.topper created this revision.
craig.topper added reviewers: fhahn, reames.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added a subscriber: pcwang-thead.
Herald added a project: LLVM.
Instead of checking whether a map entry exists to decide if we should
initialize it or add to it, we can rely on the map entry being constructed
and initialized to 0 before the addition happens.
For the std::max case, I've made a reference to the map entry to
avoid looking it up twice.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D135977
Files:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -6026,10 +6026,9 @@
if (VFs[j].isScalar()) {
for (auto *Inst : OpenIntervals) {
unsigned ClassID = TTI.getRegisterClassForType(false, Inst->getType());
- if (RegUsage.find(ClassID) == RegUsage.end())
- RegUsage[ClassID] = 1;
- else
- RegUsage[ClassID] += 1;
+ // If RegUsage[ClassID] doesn't exist, it will be default
+ // constructed as 0 before the addition
+ RegUsage[ClassID] += 1;
}
} else {
collectUniformsAndScalars(VFs[j]);
@@ -6039,25 +6038,21 @@
continue;
if (isScalarAfterVectorization(Inst, VFs[j])) {
unsigned ClassID = TTI.getRegisterClassForType(false, Inst->getType());
- if (RegUsage.find(ClassID) == RegUsage.end())
- RegUsage[ClassID] = 1;
- else
- RegUsage[ClassID] += 1;
+ // If RegUsage[ClassID] doesn't exist, it will be default
+ // constructed as 0 before the addition
+ RegUsage[ClassID] += 1;
} else {
unsigned ClassID = TTI.getRegisterClassForType(true, Inst->getType());
- if (RegUsage.find(ClassID) == RegUsage.end())
- RegUsage[ClassID] = GetRegUsage(Inst->getType(), VFs[j]);
- else
- RegUsage[ClassID] += GetRegUsage(Inst->getType(), VFs[j]);
+ // If RegUsage[ClassID] doesn't exist, it will be default
+ // constructed as 0 before the addition
+ RegUsage[ClassID] += GetRegUsage(Inst->getType(), VFs[j]);
}
}
}
for (auto& pair : RegUsage) {
- if (MaxUsages[j].find(pair.first) != MaxUsages[j].end())
- MaxUsages[j][pair.first] = std::max(MaxUsages[j][pair.first], pair.second);
- else
- MaxUsages[j][pair.first] = pair.second;
+ auto &Entry = MaxUsages[j][pair.first];
+ Entry = std::max(Entry, pair.second);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135977.467853.patch
Type: text/x-patch
Size: 2215 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221014/074a8484/attachment.bin>
More information about the llvm-commits
mailing list