Cranelift: missed optimization Improve divisibility test by constant
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Rust
- Estrellas
- 18.7k
- Forks
- 1.9k
- Merge medio
- 21 h 36 min
- PR fusionados (30 d)
- 316
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de bytecodealliance/wasmtime
-
bug wasm-proposal:exceptions wasmtime:debugging
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
bytecodealliance/wasmtime#14102 ·
Los mantenedores suelen responder en 1 día
-
wasm-proposal:gc
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
bytecodealliance/wasmtime#13808 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Add volatile flag to MemFlagsAbiertocranelift cranelift:area:clif cranelift:goal:optimize-speed enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
bytecodealliance/wasmtime#1598 · 9 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
bytecodealliance/wasmtime#14790 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 5/5 Más de una semana Aptitud para principiantes 8/100
bytecodealliance/wasmtime#14769 ·
Los mantenedores suelen responder en 1 día
Todos los issues de bytecodealliance/wasmtime
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
pop-os/cosmic-comp#2956 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
libp2p/rust-libp2p#6694 ·
Los mantenedores suelen responder en 1 día
-
Stack overflow in `check bans` with `include-dependencies = true` and a dev-dependency cycleAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
EmbarkStudios/cargo-deny#910 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
tursodatabase/turso#10054 ·
Los mantenedores suelen responder en 1 día
-
build: Update rust versionPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertodependencies
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
ibm-granite-community/granite-cli#229 ·
Los mantenedores suelen responder en 1 día