Cranelift: Generalize (x << k) >> k optimization (#5746)
* Generalize unsigned `(x << k) >> k` optimization Split the existing rule into three parts: - A dual of the rule for `(x >> k) << k` that is only valid for unsigned shifts. - Known-bits analysis for `(band (uextend x) k)`. - A new rule for converting `sextend` to `uextend` if the sign-extended bits are masked out anyway. The first two together cover the existing rule. * Generalize signed `(x << k) >> k` optimization * Review comments * Generalize sign-extending shifts further The shifts can be eliminated even if the shift amount isn't exactly equal to the difference in bit-widths between the narrow and wide types. * Add filetests
This commit is contained in:
@@ -129,6 +129,16 @@ macro_rules! isle_common_prelude_methods {
|
||||
x == y
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn u64_le(&mut self, x: u64, y: u64) -> bool {
|
||||
x <= y
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn u64_lt(&mut self, x: u64, y: u64) -> bool {
|
||||
x < y
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn u64_is_zero(&mut self, value: u64) -> bool {
|
||||
0 == value
|
||||
|
||||
Reference in New Issue
Block a user