[llvm] [SLP][NFC]Cache MightBeIgnored result in gather-shuffle analysis (PR #194619)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 28 06:32:38 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Alexey Bataev (alexey-bataev)
<details>
<summary>Changes</summary>
Each V in VL is queried up to 3 times for MightBeIgnored (direct +
NeighborMightBeIgnored from both neighbors), and the underlying
areAllUsersVectorized walks the instruction's user list. Memoize per
Value pointer to avoid the redundant walks.
---
Full diff: https://github.com/llvm/llvm-project/pull/194619.diff
1 Files Affected:
- (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+13-4)
``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 7826076edf435..c6f388ec1e0f5 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -20072,11 +20072,20 @@ BoUpSLP::isGatherShuffledSingleRegisterEntry(
// We suppose it is better to ignore instruction, which do not form splats,
// are not vectorized/not extractelements (these instructions will be handled
// by extractelements processing) or may form vector node in future.
- auto MightBeIgnored = [=](Value *V) {
+ // Cache results - each V in VL is queried up to 3 times (direct +
+ // NeighborMightBeIgnored from both neighbors), and areAllUsersVectorized
+ // walks each instruction's user list.
+ SmallDenseMap<Value *, bool> MightBeIgnoredCache;
+ auto MightBeIgnored = [=, &MightBeIgnoredCache](Value *V) {
+ auto [It, Inserted] = MightBeIgnoredCache.try_emplace(V);
+ if (!Inserted)
+ return It->second;
auto *I = dyn_cast<Instruction>(V);
- return I && !IsSplatOrUndefs && !isVectorized(I) &&
- !isVectorLikeInstWithConstOps(I) &&
- !areAllUsersVectorized(I, UserIgnoreList) && isSimple(I);
+ bool Res = I && !IsSplatOrUndefs && !isVectorized(I) &&
+ !isVectorLikeInstWithConstOps(I) &&
+ !areAllUsersVectorized(I, UserIgnoreList) && isSimple(I);
+ It->second = Res;
+ return Res;
};
// Check that the neighbor instruction may form a full vector node with the
// current instruction V. It is possible, if they have same/alternate opcode
``````````
</details>
https://github.com/llvm/llvm-project/pull/194619
More information about the llvm-commits
mailing list