Skip to content
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

[SLP] Collect candidate VFs in vector in vectorizeStores (NFC). #82793

Merged
merged 7 commits into from
Mar 1, 2024

Conversation

fhahn
Copy link
Contributor

@fhahn fhahn commented Feb 23, 2024

This is in preparation for
#77790 and makes it easy to add other, non-power-of-2 VFs for processing.

This is in preparation for
#77790 and makes it easy to add
other, non-power-of-2 VFs for processing.
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 23, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Florian Hahn (fhahn)

Changes

This is in preparation for
#77790 and makes it easy to add other, non-power-of-2 VFs for processing.


Full diff: https://github.com/llvm/llvm-project/pull/82793.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+7-3)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index de4e56ff80659a..8ee840e97e94b7 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -13918,10 +13918,14 @@ bool SLPVectorizerPass::vectorizeStores(ArrayRef<StoreInst *> Stores,
                           << "MinVF (" << MinVF << ")\n");
       }
 
-      // FIXME: Is division-by-2 the correct step? Should we assert that the
-      // register size is a power-of-2?
-      unsigned StartIdx = 0;
+      SmallVector<unsigned> CandidateVFs;
       for (unsigned Size = MaxVF; Size >= MinVF; Size /= 2) {
+        // FIXME: Is division-by-2 the correct step? Should we assert that the
+        // register size is a power-of-2?
+        CandidateVFs.push_back(Size);
+      }
+      unsigned StartIdx = 0;
+      for (unsigned Size : CandidateVFs) {
         for (unsigned Cnt = StartIdx, E = Operands.size(); Cnt + Size <= E;) {
           ArrayRef<Value *> Slice = ArrayRef(Operands).slice(Cnt, Size);
           assert(

Comment on lines 13922 to 13926
// register size is a power-of-2?
unsigned StartIdx = 0;
SmallVector<unsigned> CandidateVFs;
for (unsigned Size = MaxVF; Size >= MinVF; Size /= 2) {
// FIXME: Is division-by-2 the correct step? Should we assert that the
// register size is a power-of-2?
CandidateVFs.push_back(Size);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// register size is a power-of-2?
unsigned StartIdx = 0;
SmallVector<unsigned> CandidateVFs;
for (unsigned Size = MaxVF; Size >= MinVF; Size /= 2) {
// FIXME: Is division-by-2 the correct step? Should we assert that the
// register size is a power-of-2?
CandidateVFs.push_back(Size);
}
unsigned Sz = MaxVF / MinVF;
SmallVector<unsigned> CandidateVFs(Sz);
// FIXME: Is division-by-2 the correct step? Should we assert that the
// register size is a power-of-2?
unsigned Size = MaxVF;
for_each(Candidate, [&](unsigned &VF) { VF = Size; Size /= 2; });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted, but needed to use unsigned Sz = 1 + Log2_32(MaxVF) - Log2_32(MinVF); and introduce early exit #83283 so we don't need to handle the case where. MaxVF < MinVF.

Exit early if MaxVF < MinVF. In that case, the loop body below will
never get entered. Note that this adjusts the condition from MaxVF <=
MinVF. If MaxVF == MinVF, vectorization may still be feasible (and the
loop below gets entered).
@fhahn fhahn changed the base branch from main to users/fhahn/slp-early-exit February 28, 2024 16:15
Copy link
Member

@alexey-bataev alexey-bataev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

Base automatically changed from users/fhahn/slp-early-exit to main March 1, 2024 19:43
@fhahn fhahn merged commit 617398e into main Mar 1, 2024
3 of 4 checks passed
@fhahn fhahn deleted the users/fhahn/slp-store-vfs-in-vector branch March 1, 2024 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants