| Issue |
243077
|
| Summary |
[X86] znver3 scheduling model: ADC and one-operand MUL too slow, MULX with no ALU cost
|
| Labels |
backend:X86,
tools:llvm-mca
|
| Assignees |
|
| Reporter |
chfast
|
I measured a few snippets with llvm-exegesis on a Zen 3 CPU (Ryzen 9 5950X) and compared them with `llvm-mca -mcpu=znver3`. The snippet files work for both tools; all of them are at https://godbolt.org/z/K4dejs7h3 (llvm-mca trunk, `-mcpu=znver3 -iterations=1000`). For example, the `adc` one:
```asm
.att_syntax
# 8 add+adc pairs, each pair on its own registers
# LLVM-EXEGESIS-LOOP-REGISTER RDI
# LLVM-EXEGESIS-DEFREG RAX 1
# LLVM-EXEGESIS-DEFREG RBX 1
# LLVM-EXEGESIS-DEFREG RCX 1
# LLVM-EXEGESIS-DEFREG RDX 1
# LLVM-EXEGESIS-DEFREG R8 1
# LLVM-EXEGESIS-DEFREG R9 1
# LLVM-EXEGESIS-DEFREG R10 1
# LLVM-EXEGESIS-DEFREG R11 1
# LLVM-EXEGESIS-DEFREG R12 1
# LLVM-EXEGESIS-DEFREG R13 1
# LLVM-EXEGESIS-DEFREG R14 1
# LLVM-EXEGESIS-DEFREG R15 1
add %rcx, %r8
adc %rcx, %r9
add %rcx, %r10
adc %rcx, %r11
add %rcx, %r12
adc %rcx, %r13
add %rcx, %r14
adc %rcx, %r15
add %rcx, %r8
adc %rcx, %r9
add %rcx, %r10
adc %rcx, %r11
add %rcx, %r12
adc %rcx, %r13
add %rcx, %r14
adc %rcx, %r15
```
```
llvm-exegesis -mode=latency --repetition-mode=loop --loop-body-size=64 \
--benchmark-repeat-count=20 --result-aggregation-mode=min -snippets-file=adc.s
```
Cycles per snippet (llvm-exegesis: the minimum of several runs):
| snippet | llvm-exegesis | znver3 model |
|---|---|---|
| 16 × `add %rcx, rN` (4 independent chains) | 4.62 | 4.00 |
| 8 × (`add %rcx, rA; adc %rcx, rB`), each pair on its own registers | 4.61 | 10.00 |
| 8 × (`mov %rcx, %rax; mul %rbx`) | 8.47 | 24.00 |
| 16 × (`mul %rcx; mov %rdx, %rax`), a chain through the high half | 64.46 | 48.00 |
| 16 × `mul %rcx`, a chain through the low half | 48.44 | 48.00 |
| 4 × (`mulx %rcx, %r8, %r9` + 4 independent `add`s) | 9.48 | 5.01 |
**1. `adc r64, r64` costs the same as `add`.** The model holds an ALU for 4 cycles (`WriteADC`: `[Zn3ALU0123]`, `ReleaseAtCycles = [4]`). uops.info has `ADC (R64, I8)` on Zen 3 at 1 μop, latency 1, throughput 0.29.
**2. One-operand `mul r64` has a throughput of about 1 per cycle and a high-half latency of 4.** The model has 1 per 3 cycles and 3 (`WriteIMul64`: `[Zn3Multiplier]`, latency 3, `[3]`). uops.info agrees: throughput 1.00, latency 3 to `rax` and 4 to `rdx`. The low-half latency of 3 matches the model.
**3. `mulx` takes an ALU slot.** The model uses only the multiplier (`WriteMULX64`: `[Zn3Multiplier]`). Each `mulx` costs about as much as 4–5 `add`s. uops.info lists 2 μops, and port usage ALU1 from AMD's documentation.
Znver4 has the same `WriteADC`, `WriteIMul64` and `WriteMULX64` entries; I could not measure Zen 4.
This matters for multi-precision arithmetic, which is mostly `adc`, `mul`/`mulx` and `add`. The model ranked a variant of a 256-bit modular exponentiation loop (intx, as used by evmone) faster, but it measures 14–15% slower.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs