bytecodealliance / bytecodealliance/wasmtime

[proposal] Optimize lowering for popcnt(x) == 1

Open
#3,262 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

#### Feature

This is fairly common pattern that generates by LLVM-based languages for power of two code
(`x != 0 & (x & (x - 1) == 0` => `popcnt(x) == 1`). This is a pretty compact and fast representation, but not for platforms which don't support `popcnt` instructions, such as armv8 or x86 before Nehalem architecture. AArch64 could also benefit from this.

#### Benefit

https://godbolt.org/z/dM4fqvozn

#### Implementation

During lowering I propose lower `popcnt(x) == 1` pattern to `(x != 0) & ((x & (x - 1) == 0)` for some archs.

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.