bytecodealliance / bytecodealliance/wasmtime

Missed optimization: `clz` and `ctz`

Open
#11,725 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

Missed optimization for leading (`clz`) and trailing (`ctz`) zeros.

Absolute minimum WAT file:

```wasm
(module
(func $main (export "main") (result i32)
i32.const -1
i32.clz
)
)
```
```
Not optimized for a constant matching execution (0). Dumping CLIF from /tmp/.tmpZ8O1nN/wasm[0]--function[0]--main.clif:

=================== CLIF BEGIN ===================
;; Intermediate Representation of function :
function u0:0(i64 vmctx, i64) -> i32 tail {
gv0 = vmctx
gv1 = load.i64 notrap aligned readonly gv0+8
gv2 = load.i64 notrap aligned gv1+16
stack_limit = gv2

block0(v0: i64, v1: i64):
@0025 jump block1

block1:
@0022 v3 = iconst.i32 -1
@0024 v4 = clz v3 ; v3 = -1
@0025 return v4
}

==================== CLIF END ====================
Aborted
```

P.S. I want to create issues and then create PRs, which, if deemed fit, may be added about missed optimizations. I would also suggest having a "missed-optimization" label like LLVM has, which can be helpful.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.