[llvm] [DAG] Change `isExtractSubvectorCheap` into `getExtractSubvectorCost` (PR #213614)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 3 01:42:40 PDT 2026
================
@@ -3540,13 +3540,22 @@ class LLVM_ABI TargetLoweringBase {
return false;
}
- /// Return true if EXTRACT_SUBVECTOR is cheap for extracting this result type
- /// from this source type with this index. This is needed because
- /// EXTRACT_SUBVECTOR usually has custom lowering that depends on the index of
- /// the first element, and only the target knows which lowering is cheap.
- virtual bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT,
- unsigned Index) const {
- return false;
+ /// Return the cost of extracting a subvector of type \p ResVT from a vector
+ /// of type \p SrcVT, starting at element \p Index:
+ ///
+ /// 0 - Free: lowers to no instruction at all, e.g. a subregister copy.
+ /// 1 - Cheap: lowers to at most one instruction, and may still be free if
+ /// the target can fold the extract into the instruction consuming it
+ /// (e.g. a widening op that reads the high half of a register).
+ /// 2 - Expensive: needs a shuffle sequence that cannot be folded away.
----------------
RKSimon wrote:
I would give real money for TCC_Expensive to be removed, let alone leak into DAG - adding a cost mechanism encourages complex accumulation and comparisons, which doesn't usually remain stable in the DAG (NegatibleCost is the only one that sort of works and that's because NegatedExpression uses target-specific overrides everywhere).
Have you looked at moving this in the other direction and replacing isExtractSubvectorCheap with a more limited isExtractSubvectorFree?
https://github.com/llvm/llvm-project/pull/213614
More information about the llvm-commits
mailing list