[llvm] [X86][CostModel] Add per-shape gather/scatter cost tables for AMD znver4+ (PR #199488)
Sumukh J Bharadwaj via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 17 03:44:07 PDT 2026
================
@@ -6466,26 +6468,173 @@ InstructionCost X86TTIImpl::getCFInstrCost(unsigned Opcode,
return TTI::TCC_Free;
}
-int X86TTIImpl::getGatherOverhead() const {
+int X86TTIImpl::getGatherOverhead(Type *SrcVTy) const {
// Some CPUs have more overhead for gather. The specified overhead is relative
// to the Load operation. "2" is the number provided by Intel architects. This
// parameter is used for cost estimation of Gather Op and comparison with
// other alternatives.
// TODO: Remove the explicit hasAVX512()?, That would mean we would only
// enable gather with a -march.
+
+ // AMD znver4+ targets enable per-shape costs measured on the hardware via
+ // TuningPreferGSCostTable. Pre-AVX-512 Zen parts take the scalarise path
+ // for masked gather instead.
+ if (ST->hasPreferGSCostTable() && SrcVTy) {
+ // Per-shape gather break-even overhead: the empirical cost at which the
+ // LoopVectorizer stops preferring the gather over the scalar fallback,
+ // measured by sweeping a forced overhead over a gather micro-benchmark.
+ // For shapes the znver4+ schedule model carries it is added on top of the
+ // measured hardware reciprocal-throughput in getGSVectorCost; otherwise it
+ // is the flat overhead of the generic formula. Values are non-monotonic in
+ // VF, and the i64 overhead exceeds f64 because the i64 scalar fallback runs
+ // on the cheaper integer pipeline and is harder to beat.
+ static const CostTblEntry ZenGatherCostTable[] = {
+ {ISD::LOAD, MVT::v4i32, 7}, {ISD::LOAD, MVT::v8i32, 17},
----------------
amd-subharad wrote:
Stated this in the source with the margins remeasured
https://github.com/llvm/llvm-project/pull/199488
More information about the llvm-commits
mailing list