[llvm] [SLPVectorizer] Use DenseMap::operator[] (NFC) (PR #107123)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 3 10:08:49 PDT 2024
https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/107123
>From e7455938fb9389db298994ec9af09adb8a41bdef Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 3 Sep 2024 08:26:45 -0700
Subject: [PATCH 1/2] [SLPVectorizer] Use DenseMap::operator[] (NFC)
I'm planning to deprecate and eventually remove
DenseMap::FindAndConstruct in favor of operator[].
---
.../Transforms/Vectorize/SLPVectorizer.cpp | 22 +++++++++----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 5c37c2fdd2de3e..8a239c163a84cb 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -11841,9 +11841,9 @@ void BoUpSLP::reorderInputsAccordingToOpcode(ArrayRef<Value *> VL,
}
Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
- auto &Res = EntryToLastInstruction.FindAndConstruct(E);
- if (Res.second)
- return *Res.second;
+ auto &Res = EntryToLastInstruction[E];
+ if (Res)
+ return *Res;
// Get the basic block this bundle is in. All instructions in the bundle
// should be in this block (except for extractelement-like instructions with
// constant indeces).
@@ -11947,10 +11947,10 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
return isa<ExtractElementInst, UndefValue>(V) ||
areAllOperandsNonInsts(V);
})))
- Res.second = FindLastInst();
+ Res = FindLastInst();
else
- Res.second = FindFirstInst();
- return *Res.second;
+ Res = FindFirstInst();
+ return *Res;
}
// Find the last instruction. The common case should be that BB has been
@@ -11964,7 +11964,7 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
auto *Bundle = BlocksSchedules[BB]->getScheduleData(V);
if (Bundle && Bundle->isPartOfBundle())
for (; Bundle; Bundle = Bundle->NextInBundle)
- Res.second = Bundle->Inst;
+ Res = Bundle->Inst;
}
// LastInst can still be null at this point if there's either not an entry
@@ -11985,10 +11985,10 @@ Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
// not ideal. However, this should be exceedingly rare since it requires that
// we both exit early from buildTree_rec and that the bundle be out-of-order
// (causing us to iterate all the way to the end of the block).
- if (!Res.second)
- Res.second = FindLastInst();
- assert(Res.second && "Failed to find last instruction in bundle");
- return *Res.second;
+ if (!Res)
+ Res = FindLastInst();
+ assert(Res && "Failed to find last instruction in bundle");
+ return *Res;
}
void BoUpSLP::setInsertPointAfterBundle(const TreeEntry *E) {
>From 92333c3f068c3d2550a72c591524cea79b239e82 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 3 Sep 2024 10:05:24 -0700
Subject: [PATCH 2/2] Use find and try_emplace instead of operator[].
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 8a239c163a84cb..7f5c0e7c87cfbb 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -11841,9 +11841,10 @@ void BoUpSLP::reorderInputsAccordingToOpcode(ArrayRef<Value *> VL,
}
Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
- auto &Res = EntryToLastInstruction[E];
- if (Res)
- return *Res;
+ auto It = EntryToLastInstruction.find(E);
+ if (It != EntryToLastInstruction.end())
+ return *It->second;
+ auto &Res = EntryToLastInstruction.try_emplace(E).first->second;
// Get the basic block this bundle is in. All instructions in the bundle
// should be in this block (except for extractelement-like instructions with
// constant indeces).
More information about the llvm-commits
mailing list