[llvm] [SLPVectorizer] Avoid two successive hash lookups on the same key (PR #107143)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 3 12:20:11 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/107143
This patch replaces the find-try_emplace sequence with just one call
to try_emplace, thereby avoiding two successive hash lookups on the
same key. I am not using the "inserted" boolean from try_emplace to
preserve the original behavior (that is, before PR 107123) that checks
to see if the value is nullptr or not.
>From 8a35528834f973fc79b53cf066168494e4eba5ca Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 3 Sep 2024 12:12:24 -0700
Subject: [PATCH] [SLPVectorizer] Avoid two successive hash lookups on the same
key
This patch replaces the find-try_emplace sequence with just one call
to try_emplace, thereby avoiding two successive hash lookups on the
same key. I am not using the "inserted" boolean from try_emplace to
preserve the original behavior (that is, before PR 107123) that checks
to see if the value is nullptr or not.
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 3b45ca11eb6f89..cf802034cd56a3 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -11804,10 +11804,9 @@ void BoUpSLP::reorderInputsAccordingToOpcode(ArrayRef<Value *> VL,
}
Instruction &BoUpSLP::getLastInstructionInBundle(const TreeEntry *E) {
- auto It = EntryToLastInstruction.find(E);
- if (It != EntryToLastInstruction.end())
- return *It->second;
auto &Res = EntryToLastInstruction.try_emplace(E).first->second;
+ 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).
More information about the llvm-commits
mailing list