[llvm] [VectorCombine] Refine cost model and decision logic in foldSelectShuffle (PR #146694)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 23 23:59:30 PDT 2025
================
@@ -3174,6 +3174,54 @@ bool VectorCombine::foldCastFromReductions(Instruction &I) {
return true;
}
+/// Returns true if this ShuffleVectorInst eventually feeds into a
+/// vector reduction intrinsic (e.g., vector_reduce_add) by only following
+/// chains of shuffles and binary operators (in any combination/order).
+/// The search does not go deeper than the given Depth.
+static bool feedsIntoVectorReduction(ShuffleVectorInst *SVI, unsigned Depth) {
+ SmallPtrSet<Instruction *, 8> Visited;
+ SmallVector<std::pair<Instruction *, unsigned>, 4> WorkList;
+ bool FoundReduction = false;
+
+ WorkList.push_back({SVI, 0});
+ while (!WorkList.empty()) {
+ auto [I, CurDepth] = WorkList.pop_back_val();
+ if (CurDepth > Depth)
+ return false;
+
+ for (User *U : I->users()) {
+ auto *UI = dyn_cast<Instruction>(U);
+ if (!UI || !Visited.insert(UI).second)
----------------
davemgreen wrote:
I believe a User will always be an Instruction.
https://github.com/llvm/llvm-project/pull/146694
More information about the llvm-commits
mailing list