[llvm] [X86][SchedModel] Add masked gather/scatter overrides to Znver4Model (PR #212997)

Sumukh J Bharadwaj via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 6 10:25:56 PDT 2026


================
@@ -509,6 +509,130 @@ defm : Zn4WriteResInt<WriteLoad, [Zn4AGU012, Zn4Load], !add(Znver4Model.LoadLate
 // Does not cost anything by itself, only has latency, matching that of the WriteLoad,
 defm : Zn4WriteResInt<WriteVecMaskedGatherWriteback, [], !add(Znver4Model.LoadLatency, 1), [], 0>;
 
+// AVX-512 masked GATHER / SCATTER. Microcoded, so entries are keyed by
+// (#elements, element width, index width); the two index widths share an entry
+// only where they measure alike. Throughput and latency were measured on
+// Znver4 with every mask bit set, and are accurate to about a cycle; scatter
+// latency is estimated rather than timed. Znver4Model also backs znver5 and
+// znver6, which run 25-55% faster and are pessimistic here.
+//
+// The FP occupancies are the uops.info Zen4 port distributions for the same
+// encodings, with the FP0-3 subgroups (FP01/FP12/FP23/FP123/FP0123) summed
+// into Zn4FPU0123. A scatter's element stores are charged to Zn4FPSt, which
+// keeps them subject to the one-FP-store-per-cycle limit; Zn4FP45 then carries
+// only the remaining FP4/5 uops, so the two together come to the measured
+// FP4/5 total.
+//
+// Those occupancies alone fall short of the measured throughput -- the
+// microcode sequencer, not any one pipe, is the limit -- so Zn4UcodeGS carries
+// the fitted residual, and a retune edits only that column. Charging it there
+// rather than to the FP pipes keeps a gather/scatter from falsely serialising
+// independent FP work. Zn4UcodeGS is abstract, not four pipes; it is declared
----------------
amd-subharad wrote:

Both were measured. They are the two experiments you name, and both numbers are in the .td comment and the commit message.

Sweep, one through five. Per-operation cost is flat to within 3% with two to five in flight: 9.6 to 9.9 cycles for a 512-bit qword gather, 17.5 to 17.7 for the dword form. A unit that overlapped them would show that falling as the count rose. The lone gather sits above the plateau (12.7 and 18.2) because it is latency-exposed, so it is excluded from the fit rather than used as the one-operation datum.

Mixed pair. A gather issued alongside a scatter costs 90-96% of the two added together, not the larger of the two, so the directions do share one limit.

The four units set resolution, not concurrency. The first four operations do not get separate units: ReleaseAtCycles on a multi-unit ProcResource is divided by the unit count for throughput, so the group serialises. Running your sweep through the model rather than the part, block throughput for one to five independent qword gathers is 9.8 / 19.5 / 29.3 / 39.0 / 48.8 — flat at 9.75 to 9.80 per operation, with no step at the fifth (pressure is 39 per gather spread over the four units). The model serialises them as the part does.

One pessimism worth stating. The shared resource makes the mixed pair exactly additive in the model 23.80 against 9.80 + 14.00 where the part is 90-96% of additive, so a mixed stream is overcharged by 4 to 10%. Splitting the limiter in two would model that overlap, but it needs a second fitted column and I would rather not add one for a 4-10% effect unless you think it earns its keep.

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


More information about the llvm-commits mailing list