[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 05:17:42 PDT 2026


amd-subharad wrote:

> GCC's Zen 4 tuning found that enabling gather improved TSVC microbenchmarks but caused a performance regression in `510.parest_r`:
> 
> [gcc-mirror/gcc at 9675924](https://github.com/gcc-mirror/gcc/commit/967592488c64a86f37bef3dabebb56364f14acdd)
> 
> Could the validation include `510.parest_r` on the same harness as LBM or state that it was not measured? The available evidence alone does not support a cost-table row change.

GCC's Zen 4 tuning (gcc-mirror/gcc at 9675924) found that enabling gather regressed `510.parest_r`. That result reproduces here, on the axis that commit tests — forming gathers unconditionally. Full CPU2017 under the tuned znver4 bestmined config, AOCC 6.0.0 (build 1661), single copy, minimum over N runs with N ≥ 3, arms interleaved one iteration at a time so drift cannot bias either, each pass gated on an idle machine:

| benchmark | gathers off | gathers on | |
|---|---:|---:|---|
| `510.parest_r` | 148.81s | 169.18s | +13.7 % slower |
| `519.lbm_r` | 63.75s | 117.39s | +84.1 % slower |
| `527.cam4_r` | 124.48s | 128.18s | +3.0 % slower |
| `520.omnetpp_r` | 217.99s | 223.01s | +2.3 % slower |

Nothing improved by 2 % or more on that axis. This PR does not form gathers wholesale, though — it prices them per shape. On its own axis one compiler build serves both arms — this branch, with the OFF arm clearing the feature through `-Xclang -target-feature -Xclang -prefer-gs-cost-table`, so the two arms differ in nothing else. Same machine, the tuned bestmined config at `-O3 -march=znver4 -ffast-math -flto` with the AMD allocator, single copy, three iterations:

| benchmark | OFF | ON | |
|---|---:|---:|---|
| `510.parest_r` | 172s (169/173/172) | 173s (171/173/173) | flat |
| `519.lbm_r` | 332s (332/329/332) | 137s (139/123/137) | ratio 3.18 → 7.69 |

`510.parest_r` is flat: one second between the arms, against a four-second spread inside the OFF arm alone. The per-shape pricing is what keeps parest's gathers declined while lbm's are taken.


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


More information about the llvm-commits mailing list