Add missing rotates for cranelift#11723
Add missing rotates for cranelift#11723khagankhan wants to merge 1 commit intobytecodealliance:mainfrom
Conversation
Subscribe to Label ActionDetailsThis 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 |
alexcrichton
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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: