Cranelift: Add egraph rule to rewrite x * C ==> x << log2(C) when C is a power of two (#5647)

This commit is contained in:
Nick Fitzgerald
2023-01-31 10:04:17 -08:00
committed by GitHub
parent 61270cdaed
commit c9d1c068bc
6 changed files with 64 additions and 4 deletions

View File

@@ -343,6 +343,17 @@ macro_rules! isle_common_prelude_methods {
imm.bits() as u64
}
#[inline]
fn imm64_power_of_two(&mut self, x: Imm64) -> Option<u64> {
let x = i64::from(x);
let x = u64::try_from(x).ok()?;
if x.is_power_of_two() {
Some(x.trailing_zeros().into())
} else {
None
}
}
#[inline]
fn u64_from_bool(&mut self, b: bool) -> u64 {
if b {