[llvm] [AMDGPU] Cost of i8 vector insert/extract is free in some cases (PR #194991)

Janek van Oirschot via llvm-commits llvm-commits at lists.llvm.org
Tue May 5 09:27:46 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;
----------------
JanekvO wrote:

> Handling a dynamic index is costly; it generates multiple instructions

> My understanding is that `BaseT::getVectorInstrCost` returns 1, by default.

To me it sounds preferred to better model the expensive dynamic indices cost as return 2 so it's fine, I was just concerned that it may have some unintentional (negative) side-effects but it seems that it should've been a more costly return in the first place

https://github.com/llvm/llvm-project/pull/194991


More information about the llvm-commits mailing list