Cranelift: missed optimization Improve divisibility test by constant
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Rust
- Star
- 18.7k
- Fork
- 1.9k
- Merge trung bình
- 21 giờ 36 phút
- Pull request đã merge (30 ngày)
- 316
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bytecodealliance/wasmtime
-
bug wasm-proposal:exceptions wasmtime:debugging
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
bytecodealliance/wasmtime#14102 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
wasm-proposal:gc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
bytecodealliance/wasmtime#13808 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add volatile flag to MemFlagsĐang mởcranelift cranelift:area:clif cranelift:goal:optimize-speed enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
bytecodealliance/wasmtime#1598 · 9 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
bytecodealliance/wasmtime#14790 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 8/100
bytecodealliance/wasmtime#14769 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của bytecodealliance/wasmtime
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
bherbruck/solvecraft#2167 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
bitcoindevkit/bdk-cli#357 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Wavvon/Wavvon-clients#136 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
GUI:纯报告任务验收后误显示“已合并”Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
vorton-lang/Lobotomy#95 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
AimesSoft/NipaPlay-Reload#1022 ·
Maintainer thường phản hồi trong vòng 1 ngày