[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 02:59:17 PDT 2025
================
@@ -3055,6 +3055,47 @@ 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).
+static bool feedsIntoVectorReduction(ShuffleVectorInst *SVI) {
+ SmallPtrSet<Instruction *, 8> Visited;
+ SmallVector<Instruction *, 4> WorkList;
+ bool FoundReduction = false;
+
+ WorkList.push_back(SVI);
+ while (!WorkList.empty()) {
+ Instruction *I = WorkList.pop_back_val();
+ for (User *U : I->users()) {
+ auto *UI = dyn_cast<Instruction>(U);
+ if (!UI || !Visited.insert(UI).second)
+ continue;
+ if (auto *II = dyn_cast<IntrinsicInst>(UI)) {
+ // More than one reduction reached
+ if (FoundReduction)
+ return false;
+ switch (II->getIntrinsicID()) {
+ case Intrinsic::vector_reduce_add:
+ case Intrinsic::vector_reduce_mul:
+ case Intrinsic::vector_reduce_and:
+ case Intrinsic::vector_reduce_or:
+ case Intrinsic::vector_reduce_xor:
----------------
davemgreen wrote:
What about the other kinds?
https://github.com/llvm/llvm-project/pull/146694
More information about the llvm-commits
mailing list