[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
================
@@ -3297,15 +3338,80 @@ bool VectorCombine::foldSelectShuffle(Instruction &I, bool FromReduction) {
TTI.getShuffleCost(TTI::SK_PermuteTwoSrc, VT, VT, Mask, CostKind);
};
+ unsigned ElementSize = VT->getElementType()->getPrimitiveSizeInBits();
+ unsigned MaxVectorSize =
+ TTI.getRegisterBitWidth(TargetTransformInfo::RGK_FixedWidthVector);
+ unsigned MaxElementsInVector = MaxVectorSize / ElementSize;
+ // When there are multiple shufflevector operations on the same input,
+ // especially when the vector length is larger than the register size,
+ // identical shuffle patterns may occur across different groups of elements.
+ // To avoid overestimating the cost by counting these repeated shuffles more
+ // than once, we only account for unique shuffle patterns. This adjustment
+ // prevents inflated costs in the cost model for wide vectors split into
+ // several register-sized groups.
+ std::set<SmallVector<int, 4>> UniqueShuffles;
+ auto AddShuffleMaskAdjustedCost = [&](InstructionCost C, ArrayRef<int> Mask) {
----------------
davemgreen wrote:
Something like that, I'm not sure. The operands would need to be the same so maybe it is not super general, but it is useful for the target to be able to override it if necessary. We can probably move it later if we find the need.
https://github.com/llvm/llvm-project/pull/146694
More information about the llvm-commits
mailing list