Cranelift: missed optimization Improve divisibility test by constant
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Rust
- 星标
- 18.7k
- 派生
- 1.9k
- 平均合并
- 21 小时 36 分钟
- 30 天内合并 PR
- 316
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bytecodealliance/wasmtime 的其他 Issue
-
bug wasm-proposal:exceptions wasmtime:debugging
难度 2/5 1-3 小时 新手友好度 76/100
bytecodealliance/wasmtime#14102 ·
维护者通常 1 天内回复
-
wasm-proposal:gc
难度 2/5 1-3 小时 新手友好度 62/100
bytecodealliance/wasmtime#13808 · 2 条评论 ·
维护者通常 1 天内回复
-
cranelift cranelift:area:clif cranelift:goal:optimize-speed enhancement
难度 2/5 1-3 小时 新手友好度 78/100
bytecodealliance/wasmtime#1598 · 9 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 42/100
bytecodealliance/wasmtime#14790 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 5/5 一周以上 新手友好度 8/100
bytecodealliance/wasmtime#14769 ·
维护者通常 1 天内回复
查看 bytecodealliance/wasmtime 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 88/100
pop-os/cosmic-comp#2956 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
libp2p/rust-libp2p#6694 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
EmbarkStudios/cargo-deny#910 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
tursodatabase/turso#10054 ·
维护者通常 1 天内回复
-
build: Update rust version可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭dependencies
难度 2/5 1-3 小时 新手友好度 67/100
ibm-granite-community/granite-cli#229 ·
维护者通常 1 天内回复