[llvm] [AMDGPU] Cost of i8 vector insert/extract is free in some cases (PR #194991)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 30 02:50:52 PDT 2026
================
@@ -1009,19 +1009,32 @@ InstructionCost GCNTTIImpl::getVectorInstrCost(
case Instruction::InsertElement: {
unsigned EltSize
= DL.getTypeSizeInBits(cast<VectorType>(ValTy)->getElementType());
+ // Dynamic indexing isn't free and is best avoided.
+ if (Index == ~0u)
+ return 2;
if (EltSize < 32) {
if (EltSize == 16 && Index == 0 && ST->has16BitInsts())
return 0;
+ // Some i8 inserts and extracts are free so we want to reduce the
+ // cost to avoid scalarization. We limit the zero cost cases to avoid
+ // adversely impacting all i8 vectorizing.
+ if (EltSize == 8) {
+ unsigned NumElts = cast<FixedVectorType>(ValTy)->getNumElements();
+ if (NumElts >= 4 && isPowerOf2_32(NumElts)) {
+ // Extracts at indices aligned to 32-bit boundaries (0, 4, 8, 12 for
+ // v16i8) are free as they access the low byte of each VGPR. Other
+ // indices require bit manipulation (shifts/byte selects) and cost 1.
----------------
arsenm wrote:
Theoretically any byte or short mask is free with SDWA depending on the user
https://github.com/llvm/llvm-project/pull/194991
More information about the llvm-commits
mailing list