| Issue |
242978
|
| Summary |
[RISCV] riscv-fp-imm-cost=3 materializes constants in hot loop, regresses 782.lbm_r ~10% on SG2044 (default config)
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
jiawan-wang
|
Validating LLVM 22.1 on an SG2044 (T-Head C920, rv64gc) with SPEC CPU 2026, we found 782.lbm_r regresses ~10% under the default configuration (no `-mcpu`, i.e. what every rv64gc user gets) and bisected it to #159352 (`c2e84072`, fp-imm-cost default 2->3). cc @asb.
Setup: `-O3 -march=rv64gc`, taskset-isolated interleaved A/B, quiet sessions, 0-change controls <1%.
| 782.lbm_r, clang 22.1.8 | train (med of 3) | refrate (med of 4) |
|---|---|---|
| threshold 3 (default) | 195.0s | 1434s |
| `-riscv-lower-fpimm-cost=2` (renamed in #230014) | 174.9s | 1289s |
Knob flip on the same compiler: -10~-12% train, -10.2% refrate, across three independent sessions. Scripted bisect 21.1.8..22.1.8: 15 measurements, zero-overlap bimodal, first bad = c2e84072.
Mechanism (`LBM_performStreamCollideTRT`, ~99% of lbm; reduced repro available — the IR is identical between thresholds, pure backend): at threshold 3, five constant-pool `fld`s become `ld`+`fmv.d.x` executed every iteration; at threshold 2 they stay pool `fld`s. The threshold-3 loop body is statically smaller (333 vs 345 insns) yet slower — the cost model counts sequence length, not exposed latency. The threshold change is the trigger; how much it costs depends on how the pattern gets arranged relative to the core (contrast below).
The direction flips across benchmarks: 709.cactus_r *prefers* threshold 3 by ~18-19% (refrate, 8 runs/28h: tight 249-255s vs 294-297s clusters). So neither default is right for both. One more datapoint: the identical `ld`+`fmv.d.x` pattern, arranged with loads issued early and independent FP work between load and use, is *faster* than threshold 2 on this same core — the transfer latency is hideable by the hardware, but not in the arrangement the default model produces.
<details>
<summary>asm contrast (same threshold-3 pattern, different arrangement)</summary>
Default (slow): five `ld`->`fmv.d.x` back-to-back, ~20-25 exposed cycles/iter:
```
ld a4,64(sp) / fmv.d.x fa4,a4
ld a4,56(sp) / fmv.d.x ft1,a4
ld a4,48(sp) / fmv.d.x ft3,a4
ld a4,40(sp) / fmv.d.x fs6,a4
ld a4,32(sp) / fmv.d.x fs3,a4
```
Same pattern, loads early + transfers buried under independent FP work (fast on this core):
```
fdiv.d / fmul.d / ld+fmv / fmadd.d
fsub.d / fmul.d / fmul.d / fmv.d.x fs6,a4 ; its ld issued 30+ insns earlier
fadd.d / fsub.d / fadd.d / fmv.d.x ft11,s8 ; s8: register-resident, no ld
```
</details>
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs