[llvm] [AMDGPU] Cost of i8 vector insert/extract is free in some cases (PR #194991)
Brendon Cahoon via llvm-commits
llvm-commits at lists.llvm.org
Tue May 5 08:00:12 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;
----------------
bcahoon wrote:
This part of the PR moves this existing check to a common place, instead of needing to check in two places. Handling a dynamic index is costly; it generates multiple instructions. Since that behavior existed already, I figured it made sense to include with the new code. The effect does show up in the `CostModel `lit tests. If it's less confusing/better, then I can move the original check back and add an additional check. For example,
```
if (Index == ~0u)
return 2;
return Index == 4 ? 0 : 1;
```
The dynamic index check in the cost model doesn't affect `VectorCombine `as `VectorCombine `won't attempt to scalarize them. But, it might affect other uses of the cost model, e.g., SLP Vectorizer.
My understanding is that `BaseT::getVectorInstrCost` returns 1, by default. There is no check for a dynamic index.
https://github.com/llvm/llvm-project/pull/194991
More information about the llvm-commits
mailing list