[llvm] 5a4b7e1 - [SLP] Deduplicate loads subkey generator. NFCI
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 25 01:34:46 PDT 2023
Author: Luke Lau
Date: 2023-04-25T09:34:40+01:00
New Revision: 5a4b7e1f2e547251ead718f5da67cd671a769169
URL: https://github.com/llvm/llvm-project/commit/5a4b7e1f2e547251ead718f5da67cd671a769169
DIFF: https://github.com/llvm/llvm-project/commit/5a4b7e1f2e547251ead718f5da67cd671a769169.diff
LOG: [SLP] Deduplicate loads subkey generator. NFCI
Reviewed By: ABataev
Differential Revision: https://reviews.llvm.org/D148923
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 1e1200850ab90..2065f41ff57b7 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -12910,6 +12910,39 @@ class HorizontalReduction {
DenseMap<Value *, SmallVector<LoadInst *>> LoadsMap;
SmallSet<size_t, 2> LoadKeyUsed;
SmallPtrSet<Value *, 4> DoNotReverseVals;
+
+ auto GenerateLoadsSubkey = [&](size_t Key, LoadInst *LI) {
+ Value *Ptr = getUnderlyingObject(LI->getPointerOperand());
+ if (LoadKeyUsed.contains(Key)) {
+ auto LIt = LoadsMap.find(Ptr);
+ if (LIt != LoadsMap.end()) {
+ for (LoadInst *RLI : LIt->second) {
+ if (getPointersDiff(RLI->getType(), RLI->getPointerOperand(),
+ LI->getType(), LI->getPointerOperand(), DL, SE,
+ /*StrictCheck=*/true))
+ return hash_value(RLI->getPointerOperand());
+ }
+ for (LoadInst *RLI : LIt->second) {
+ if (arePointersCompatible(RLI->getPointerOperand(),
+ LI->getPointerOperand(), TLI)) {
+ hash_code SubKey = hash_value(RLI->getPointerOperand());
+ DoNotReverseVals.insert(RLI);
+ return SubKey;
+ }
+ }
+ if (LIt->second.size() > 2) {
+ hash_code SubKey =
+ hash_value(LIt->second.back()->getPointerOperand());
+ DoNotReverseVals.insert(LIt->second.back());
+ return SubKey;
+ }
+ }
+ }
+ LoadKeyUsed.insert(Key);
+ LoadsMap.try_emplace(Ptr).first->second.push_back(LI);
+ return hash_value(LI->getPointerOperand());
+ };
+
while (!Worklist.empty()) {
Instruction *TreeN = Worklist.pop_back_val();
SmallVector<Value *> Args;
@@ -12929,41 +12962,8 @@ class HorizontalReduction {
// results.
for (Value *V : PossibleRedVals) {
size_t Key, Idx;
- std::tie(Key, Idx) = generateKeySubkey(
- V, &TLI,
- [&](size_t Key, LoadInst *LI) {
- Value *Ptr = getUnderlyingObject(LI->getPointerOperand());
- if (LoadKeyUsed.contains(Key)) {
- auto LIt = LoadsMap.find(Ptr);
- if (LIt != LoadsMap.end()) {
- for (LoadInst *RLI: LIt->second) {
- if (getPointersDiff(
- RLI->getType(), RLI->getPointerOperand(),
- LI->getType(), LI->getPointerOperand(), DL, SE,
- /*StrictCheck=*/true))
- return hash_value(RLI->getPointerOperand());
- }
- for (LoadInst *RLI : LIt->second) {
- if (arePointersCompatible(RLI->getPointerOperand(),
- LI->getPointerOperand(), TLI)) {
- hash_code SubKey = hash_value(RLI->getPointerOperand());
- DoNotReverseVals.insert(RLI);
- return SubKey;
- }
- }
- if (LIt->second.size() > 2) {
- hash_code SubKey =
- hash_value(LIt->second.back()->getPointerOperand());
- DoNotReverseVals.insert(LIt->second.back());
- return SubKey;
- }
- }
- }
- LoadKeyUsed.insert(Key);
- LoadsMap.try_emplace(Ptr).first->second.push_back(LI);
- return hash_value(LI->getPointerOperand());
- },
- /*AllowAlternate=*/false);
+ std::tie(Key, Idx) = generateKeySubkey(V, &TLI, GenerateLoadsSubkey,
+ /*AllowAlternate=*/false);
++PossibleReducedVals[Key][Idx]
.insert(std::make_pair(V, 0))
.first->second;
@@ -12972,40 +12972,8 @@ class HorizontalReduction {
PossibleReductionOps.rend());
} else {
size_t Key, Idx;
- std::tie(Key, Idx) = generateKeySubkey(
- TreeN, &TLI,
- [&](size_t Key, LoadInst *LI) {
- Value *Ptr = getUnderlyingObject(LI->getPointerOperand());
- if (LoadKeyUsed.contains(Key)) {
- auto LIt = LoadsMap.find(Ptr);
- if (LIt != LoadsMap.end()) {
- for (LoadInst *RLI: LIt->second) {
- if (getPointersDiff(RLI->getType(),
- RLI->getPointerOperand(), LI->getType(),
- LI->getPointerOperand(), DL, SE,
- /*StrictCheck=*/true))
- return hash_value(RLI->getPointerOperand());
- }
- for (LoadInst *RLI : LIt->second) {
- if (arePointersCompatible(RLI->getPointerOperand(),
- LI->getPointerOperand(), TLI)) {
- hash_code SubKey = hash_value(RLI->getPointerOperand());
- DoNotReverseVals.insert(RLI);
- return SubKey;
- }
- }
- if (LIt->second.size() > 2) {
- hash_code SubKey = hash_value(LIt->second.back()->getPointerOperand());
- DoNotReverseVals.insert(LIt->second.back());
- return SubKey;
- }
- }
- }
- LoadKeyUsed.insert(Key);
- LoadsMap.try_emplace(Ptr).first->second.push_back(LI);
- return hash_value(LI->getPointerOperand());
- },
- /*AllowAlternate=*/false);
+ std::tie(Key, Idx) = generateKeySubkey(TreeN, &TLI, GenerateLoadsSubkey,
+ /*AllowAlternate=*/false);
++PossibleReducedVals[Key][Idx]
.insert(std::make_pair(TreeN, 0))
.first->second;
More information about the llvm-commits
mailing list