[llvm] [SLP][NFC] Simplify population of `ReducedVals` (PR #156292)
Piotr Fusik via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 1 01:09:01 PDT 2025
https://github.com/pfusik created https://github.com/llvm/llvm-project/pull/156292
None
>From 568322b1d2334f6cdd66491bad3ed1f594e9ea30 Mon Sep 17 00:00:00 2001
From: Piotr Fusik <p.fusik at samsung.com>
Date: Mon, 1 Sep 2025 10:06:16 +0200
Subject: [PATCH] [SLP][NFC] Simplify population of `ReducedVals`
---
.../Transforms/Vectorize/SLPVectorizer.cpp | 25 +++++++++----------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 4d4f34a0bdd38..aab88190fdb7b 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -23835,21 +23835,20 @@ class HorizontalReduction {
stable_sort(PossibleRedValsVect, [](const auto &P1, const auto &P2) {
return P1.size() > P2.size();
});
- int NewIdx = -1;
+ bool First = true;
for (ArrayRef<Value *> Data : PossibleRedValsVect) {
- if (NewIdx < 0 ||
- (!isGoodForReduction(Data) &&
- (!isa<LoadInst>(Data.front()) ||
- !isa<LoadInst>(ReducedVals[NewIdx].front()) ||
- getUnderlyingObject(
- cast<LoadInst>(Data.front())->getPointerOperand()) !=
- getUnderlyingObject(
- cast<LoadInst>(ReducedVals[NewIdx].front())
- ->getPointerOperand())))) {
- NewIdx = ReducedVals.size();
+ if (First) {
+ First = false;
ReducedVals.emplace_back();
- }
- ReducedVals[NewIdx].append(Data.rbegin(), Data.rend());
+ } else if (!isGoodForReduction(Data)) {
+ auto *LI = dyn_cast<LoadInst>(Data.front());
+ auto *LastLI = dyn_cast<LoadInst>(ReducedVals.back().front());
+ if (!LI || !LastLI ||
+ getUnderlyingObject(LI->getPointerOperand()) !=
+ getUnderlyingObject(LastLI->getPointerOperand()))
+ ReducedVals.emplace_back();
+ }
+ ReducedVals.back().append(Data.rbegin(), Data.rend());
}
}
// Sort the reduced values by number of same/alternate opcode and/or pointer
More information about the llvm-commits
mailing list