-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Missed optimization for 2^n euclidean division remainder operations on signed integers. #66417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The general pattern is already handled since LLVM 18: https://llvm.godbolt.org/z/zfGjbGns9 We do fail to handle the specific form (where one select arm has been replaced by constant 1) though: https://alive2.llvm.org/ce/z/gmJ3XL |
Thanks for reporting, landed a possible fix in ce5b88b. Feel free to reopen should it be incomplete. |
ZijunZhaoCCK
pushed a commit
to ZijunZhaoCCK/llvm-project
that referenced
this issue
Sep 19, 2023
Extend folding for `2^n` euclidean division remainder operations on signed integers by handling the specific instance in which one `select` arm has already been replaced by 1. Reported-By: HypheX Fixes: llvm#66417.
zahiraam
pushed a commit
to tahonermann/llvm-project
that referenced
this issue
Oct 24, 2023
Extend folding for `2^n` euclidean division remainder operations on signed integers by handling the specific instance in which one `select` arm has already been replaced by 1. Reported-By: HypheX Fixes: llvm#66417.
zahiraam
pushed a commit
to tahonermann/llvm-project
that referenced
this issue
Oct 24, 2023
Extend folding for `2^n` euclidean division remainder operations on signed integers by handling the specific instance in which one `select` arm has already been replaced by 1. Reported-By: HypheX Fixes: llvm#66417.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When calculating the euclidean division remainder of signed integers, there is a missed optimization. The optimization should be applied as long as the divisor is a power of 2.
Missed optimization
Rust:
llvmir:
Example of what the optimization should look like
Rust:
llvmir:
It is worth noting that the optimization is applied to unsigned integers just fine:
With unsigned integers
Although, I'm not sure if this is
rustc
doing the optimization, or if LLVM is.Rust:
llvmir:
The text was updated successfully, but these errors were encountered: