- Notifications
You must be signed in to change notification settings - Fork1.6k
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 ourterms of service andprivacy 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 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.
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 incranelift/filetests/filetests/egraph for testing the IR is updated appropriately andcranelift/filetests/filetests/runtests for ensuring that the behavior matches the interpreter.
| #[inline] | ||
| fn imm64_rotl(&mutself, 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.
Themin here should be an assert of some form because ifty.bits() is>=64 then that's an invalid state for this function to be in and it should panic.
| #[inline] | ||
| fn imm64_rotl(&mutself, ty:Type, x:Imm64, k:Imm64) ->Imm64{ | ||
| let bw:u32 = ty.bits().min(64); | ||
| let amt:u32 =if bw ==0{0} else{(k.bits()asu32) % 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()asu32) % bw}; | ||
| let xv = x.bits()asu64; |
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 usingcast_unsigned here as it avoid usingas which is something we try to avoid since it's by default a lossy cast.
| 8 =>(xvasu8).rotate_left(amt)asu64, | ||
| 16 =>(xvasu16).rotate_left(amt)asu64, | ||
| 32 =>(xvasu32).rotate_left(amt)asu64, |
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 usingu64::from((xv as u8).rotate_left(amt)) to avoidas u64. Theas u8 is still required, however, as this is intentionally truncating data.
khagankhan commentedSep 20, 2025
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: