-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add missing rotates for cranelift #11723
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
base: main
Are you sure you want to change the base?
Conversation
Subscribe to Label Action
This issue or pull request has been labeled: "cranelift", "isle"
Thus the following users have been cc'd because of the following labels:
To subscribe or unsubscribe from this label, edit the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Mind adding some tests for this too? They'd go in cranelift/filetests/filetests/egraph
for testing the IR is updated appropriately and cranelift/filetests/filetests/runtests
for ensuring that the behavior matches the interpreter.
|
||
#[inline] | ||
fn imm64_rotl(&mut self, ty: Type, x: Imm64, k: Imm64) -> Imm64 { | ||
let bw: u32 = ty.bits().min(64); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The min
here should be an assert of some form because if ty.bits()
is >=64
then that's an invalid state for this function to be in and it should panic.
#[inline] | ||
fn imm64_rotl(&mut self, ty: Type, x: Imm64, k: Imm64) -> Imm64 { | ||
let bw: u32 = ty.bits().min(64); | ||
let amt: u32 = if bw == 0 { 0 } else { (k.bits() as u32) % bw }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok to not test for 0 here because a 0-size integral type should cause a panic (which % 0
would do I believe). Handling it here would accidentally try to recover from what should otherwise be a panicking situation.
let bw: u32 = ty.bits().min(64); | ||
let amt: u32 = if bw == 0 { 0 } else { (k.bits() as u32) % bw }; | ||
|
||
let xv = x.bits() as u64; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend using cast_unsigned
here as it avoid using as
which is something we try to avoid since it's by default a lossy cast.
8 => (xv as u8).rotate_left(amt) as u64, | ||
16 => (xv as u16).rotate_left(amt) as u64, | ||
32 => (xv as u32).rotate_left(amt) as u64, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For promotion back up to u64 I'd recommend using u64::from((xv as u8).rotate_left(amt))
to avoid as u64
. The as u8
is still required, however, as this is intentionally truncating data.
Sure thing! @alexcrichton Just made PR to get initial thoughts. I will address the comments |
This adds the missed rotate optimizations in cranelift mid-end opened in #11722
Before PR:
After PR: