We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
udiv
urem
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
Strength reduction can be performed on udiv/urem if the divisor is known to be a power of two, due to dominating condition or assume:
Compiler explorer: https://godbolt.org/z/4ncnjsPTM Alive proof: https://alive2.llvm.org/ce/z/3FJYeg
#![feature(core_intrinsics)] use std::hint::assert_unchecked as assume; use std::intrinsics::unchecked_div; use std::intrinsics::unchecked_rem; #[no_mangle] pub fn src_udiv_if(x: u32, y: u32) -> u32 { if y.is_power_of_two() { unsafe { unchecked_div(x, y) } } else { 0 } } #[no_mangle] pub fn tgt_udiv_if(x: u32, y: u32) -> u32 { if y.is_power_of_two() { x >> y.trailing_zeros() } else { 0 } } #[no_mangle] pub fn src_udiv_assume(x: u32, y: u32) -> u32 { unsafe { assume(y.is_power_of_two()); unchecked_div(x, y) } } #[no_mangle] pub fn tgt_udiv_assume(x: u32, y: u32) -> u32 { unsafe { assume(y.is_power_of_two()); x >> y.trailing_zeros() } } #[no_mangle] pub fn src_urem_if(x: u32, y: u32) -> u32 { if y.is_power_of_two() { unsafe { unchecked_rem(x, y) } } else { 0 } } #[no_mangle] pub fn tgt_urem_if(x: u32, y: u32) -> u32 { if y.is_power_of_two() { x & (y - 1) } else { 0 } } #[no_mangle] pub fn src_urem_assume(x: u32, y: u32) -> u32 { unsafe { assume(y.is_power_of_two()); unchecked_rem(x, y) } } #[no_mangle] pub fn tgt_urem_assume(x: u32, y: u32) -> u32 { unsafe { assume(y.is_power_of_two()); x & (y - 1) } }
The text was updated successfully, but these errors were encountered:
urem is being reduced to bitwise operations since #107994.
I'll fix udiv.
Sorry, something went wrong.
X udiv Y
X lshr cttz(Y)
[InstCombine] Fold X udiv Y to X lshr cttz(Y) if Y is a power of 2 (
2d5f07c
#121386) Fixes #115767 This PR folds `X udiv Y` to `X lshr cttz(Y)` if Y is a power of two since bitwise operations are faster than division. Proof: https://alive2.llvm.org/ce/z/qHmLta
ae63f00
llvm#121386) Fixes llvm#115767 This PR folds `X udiv Y` to `X lshr cttz(Y)` if Y is a power of two since bitwise operations are faster than division. Proof: https://alive2.llvm.org/ce/z/qHmLta
Successfully merging a pull request may close this issue.
Strength reduction can be performed on
udiv
/urem
if the divisor is known to be a power of two, due to dominating condition or assume:Compiler explorer: https://godbolt.org/z/4ncnjsPTM
Alive proof: https://alive2.llvm.org/ce/z/3FJYeg
The text was updated successfully, but these errors were encountered: