Skip to content

[Cranelift] add type-aware rotate operations#12764

Open
bongjunj wants to merge 1 commit intobytecodealliance:mainfrom
bongjunj:ty-aware-ops
Open

[Cranelift] add type-aware rotate operations#12764
bongjunj wants to merge 1 commit intobytecodealliance:mainfrom
bongjunj:ty-aware-ops

Conversation

@bongjunj
Copy link
Contributor

Related to #12759. Rotation operations are sensitive to type width; therefore their semantics should change per the operands' type rather than being fixed to u64, u32, and so on.

@bongjunj bongjunj requested a review from a team as a code owner March 12, 2026 02:12
@bongjunj bongjunj requested review from cfallin and removed request for a team March 12, 2026 02:12
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language labels Mar 12, 2026
@github-actions
Copy link

Subscribe to Label Action

cc @cfallin, @fitzgen

Details This issue or pull request has been labeled: "cranelift", "isle"

Thus the following users have been cc'd because of the following labels:

  • cfallin: isle
  • fitzgen: isle

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! A few thoughts below but the logic generally looks good to me.

let x = (x.bits() as u64) & ty_mask;

// Mask off any excess rotate bits so the rotate stays within `ty`.
let shift_mask = bits - 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put a debug_assert here that bits is a power of two? This is true for all of our types today but I don't want to bake the assumption in without something guarding it.

let x = (x.bits() as u64) & ty_mask;

// Mask off any excess rotate bits so the rotate stays within `ty`.
let shift_mask = bits - 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise here (debug-assert power-of-two).

}

#[inline]
fn imm64_rotl(&mut self, ty: Type, x: Imm64, y: Imm64) -> Imm64 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have these helpers in the prelude, we should be able to implement rotl/rotr constant propagation rules too, right? It seems odd to have just the rule in this PR (for rotr-of-select-of-constants) -- can we add simple cprop as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants