Skip to content

[Transforms] Avoid repeated hash lookups (NFC) #131556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ DbgVariableRecordsRemoveRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
continue;
DebugVariable Key(DVR.getVariable(), std::nullopt,
DVR.getDebugLoc()->getInlinedAt());
auto VMI = VariableMap.find(Key);
auto [VMI, Inserted] = VariableMap.try_emplace(Key);
// A dbg.assign with no linked instructions can be treated like a
// dbg.value (i.e. can be deleted).
bool IsDbgValueKind =
Expand All @@ -520,12 +520,12 @@ DbgVariableRecordsRemoveRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
// Update the map if we found a new value/expression describing the
// variable, or if the variable wasn't mapped already.
SmallVector<Value *, 4> Values(DVR.location_ops());
if (VMI == VariableMap.end() || VMI->second.first != Values ||
if (Inserted || VMI->second.first != Values ||
VMI->second.second != DVR.getExpression()) {
if (IsDbgValueKind)
VariableMap[Key] = {Values, DVR.getExpression()};
VMI->second = {Values, DVR.getExpression()};
else
VariableMap[Key] = {Values, nullptr};
VMI->second = {Values, nullptr};
continue;
}
// Don't delete dbg.assign intrinsics that are linked to instructions.
Expand Down Expand Up @@ -591,7 +591,7 @@ static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(&I)) {
DebugVariable Key(DVI->getVariable(), std::nullopt,
DVI->getDebugLoc()->getInlinedAt());
auto VMI = VariableMap.find(Key);
auto [VMI, Inserted] = VariableMap.try_emplace(Key);
auto *DAI = dyn_cast<DbgAssignIntrinsic>(DVI);
// A dbg.assign with no linked instructions can be treated like a
// dbg.value (i.e. can be deleted).
Expand All @@ -600,15 +600,15 @@ static bool removeRedundantDbgInstrsUsingForwardScan(BasicBlock *BB) {
// Update the map if we found a new value/expression describing the
// variable, or if the variable wasn't mapped already.
SmallVector<Value *, 4> Values(DVI->getValues());
if (VMI == VariableMap.end() || VMI->second.first != Values ||
if (Inserted || VMI->second.first != Values ||
VMI->second.second != DVI->getExpression()) {
// Use a sentinel value (nullptr) for the DIExpression when we see a
// linked dbg.assign so that the next debug intrinsic will never match
// it (i.e. always treat linked dbg.assigns as if they're unique).
if (IsDbgValueKind)
VariableMap[Key] = {Values, DVI->getExpression()};
VMI->second = {Values, DVI->getExpression()};
else
VariableMap[Key] = {Values, nullptr};
VMI->second = {Values, nullptr};
continue;
}

Expand Down
Loading