Cranelift: missed optimization Improve divisibility test by constant
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
The issue asks for a strength reduction in Cranelift, so the work lives in its ISLE optimization rules and the lowering of remainder and divisibility tests. Read the linked Godbolt example to see the current output for a multiple-of-7 check, then look for existing constant-division rules the change could extend. Done means == and != tests against constants, for both signed and unsigned inputs and odd and even divisors, emit the short multiply-and-compare sequence and still pass the existing filetests.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Feature
Optimization of unsigned constant-remainder tests:
Take a look at: https://godbolt.org/z/MPfdhbc3q (divide x by constant, in this case 7, and then test it).
for signed/unsigned x, and for == and !=, rustc on llvm emits a short sequence, e.g. for the != case
is_multiple_of_7:
imul eax, edi, -1227133513
cmp eax, 613566757
setae al
ret
The corresponding cranelift side is much longer:
is_multiple_of_7:
mov rax, rdi
mul dword ptr [rip + 0x2b] # 0x38 <is_multiple_of_7+0x38>
mov r10, rdi
sub r10d, edx
shr r10d
add r10d, edx
shr r10d, 0x2
imul r11d, r10d, 0x7
sub edi, r11d
test edi, edi
setne al
movzx rax, al
Benefit
llvm-mca says this is 8 cycles for llvm or 20 for cranelift on a zen4. There is a similar disparity for arm64 and riscv64.
Implementation
Not sure. LLVM implements this in target independent SDAG, maybe there's a similar target independent ISLE fold that would be a good place for it?
extra note: make sure to handle signed vs unsigned, ne and eq, and odd and even numbers.
Alternatives
- We could leave this as is. I think this is a mildly popular pattern, like for byte aligning so I'd like to see it improved.
- Would need to look into cranelift more for other places to put this optimization. It could be target dependent but I assume this optimization should work the same for any target since it's a strength reduction.
- Lingua principale
- Rust
- Stelle
- 18.7k
- Fork
- 1.9k
- Merge medio
- 21h 36m
- PR unite (30g)
- 316
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la 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 bytecodealliance/wasmtime
-
bug wasm-proposal:exceptions wasmtime:debugging
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
bytecodealliance/wasmtime#14102 ·
I maintainer di solito rispondono entro 1 giorno
-
wasm-proposal:gc
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
bytecodealliance/wasmtime#13808 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
cranelift cranelift:area:clif cranelift:goal:optimize-speed enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
bytecodealliance/wasmtime#1598 · 9 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
bytecodealliance/wasmtime#14790 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 5/5 Più di una settimana Idoneità per principianti 8/100
bytecodealliance/wasmtime#14769 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di bytecodealliance/wasmtime
Issue simili
-
bug documentation sev-0
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
dekobon/big-code-analysis#1620 ·
I maintainer di solito rispondono entro 3 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
bug soroban
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
utilityjnr1/lumena#358 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
charles-hood/DiagramCraft#63 ·