baseline: Weight the computed goto with the opcode frequencies
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- cpp
- Ambito
- backend, performance
Direzione di ricerca
Start with baseline_execution.cpp, dispatch_cgoto, and cgoto_table to understand how the computed goto maps targets to opcodes. The issue proposes adding opcode frequency weights to the indirectbr, then lists benchmarks, mainnet frequency counts, AArch64 and switch dispatch checks, and Clang build integration as open work. Done means benchmarked weights based on mainnet blocks and verified the affected dispatch paths and build integration.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
The register allocator decides which values of the Baseline dispatch loop stay in registers and which are reloaded from the stack. Without a profile, LLVM's block frequency estimate gives every target of the computed goto the same weight: in dispatch_cgoto (Clang 21) all 149 non-terminating handlers get 0.583 × the function entry, so ADD weighs as much as BLOBHASH. Changes that shift liveness in the loop then move reloads into hot handlers by chance, e.g. #1779 on AArch64 with Clang 21: +1 stack load in 52 handlers, including ADD, LT, EQ, JUMPI and DUP2.
Regular PGO does not fix this:
- Front-end instrumentation (
-fprofile-instr-use) leaves theindirectbrwithout weights. - IR instrumentation (
-fprofile-use) weights it, but restructures the whole loop. With a profile from snailtracer, sha1_shifts and swap_math, these benchmarks got 5–8% slower: the checks materialize a status code and each handler reloads 4 values before the indirect jump (ADD 18 → 26 instructions). - The IR profile is keyed by the CFG hash of
dispatch_cgoto, which contains all inlined handlers, so it goes stale with almost every change to the loop. GCC cannot reuse profiles across commits at all.
Idea
Give the compiler only the opcode frequencies, as branch_weights on the computed goto's indirectbr, and leave everything else as without a profile. The weights depend only on the opcode distribution, not on the code, so a checked-in table stays valid. The frequencies should come from mainnet blocks.
Prototype
Clang 21, x86-64: compile baseline_execution.cpp to -O3 IR, map each indirectbr target to its opcodes through cgoto_table, add the weights, then run only the code generation (-Xclang -disable-llvm-passes; without weights this gives the same object as the normal build). The weights are the opcode counts of the profile above.
Shortest success paths of the 149 handlers (instructions / stack loads):
| weights | all handlers | POP, SWAP1, JUMPI, DUP1, DUP2, AND, ADD, JUMP, SUB | SHL, SHR |
|---|---|---|---|
| none | 3152 / 180 | 1 load each | 23/1, 24/1 |
| measured counts | 3485 / 419 | no loads, same length | 25/1, 26/1 |
| 3 tiers | 3316 / 252 | no loads, same length | 27/2, 28/2 |
The tiers are 1000 for opcodes with at least 1% of the executed instructions, 30 for at least 0.01%, and 1 for the rest. MLOAD and MSTORE also lose a load. The reloads move into the cold handlers.
TODO
- Benchmark the variants.
- Count the opcode frequencies on mainnet blocks.
- Check AArch64 and the switch-based
dispatch<false>loop. - Build integration (Clang only): an extra IR step for
baseline_execution.cpp, or a pass plugin.
- Lingua principale
- C++
- Stelle
- 979
- Fork
- 340
- Merge medio
- 12h 16m
- PR unite (30g)
- 25
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ipsilon/evmone
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 56/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 57/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 12/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di ipsilon/evmone
Issue simili
-
Reference check: findingsApertaaudit-reference-check
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
schrodinger/pymol-open-source#532 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 83/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
xlnt-community/xlnt#174 ·