Skip to content

Type-guard bitop optimization rules (#13229)#13237

Open
bongjunj wants to merge 2 commits intobytecodealliance:mainfrom
bongjunj:fix-13229
Open

Type-guard bitop optimization rules (#13229)#13237
bongjunj wants to merge 2 commits intobytecodealliance:mainfrom
bongjunj:fix-13229

Conversation

@bongjunj
Copy link
Copy Markdown
Contributor

@bongjunj bongjunj commented Apr 30, 2026

This resolves #13229

Cause 1

bitops such as band, bor, ... are not constrained to receive only integer inputs like iadd, isub, and icmp.
The IR builder shows this fact:

Note that there is no float input for iadd, whereas band can take float inputs.

Cause 2

iconst_s and iconst_u provide convenient ways to construct constants on RHS, but they are the main contract breaker of ISLE type system. They are declared as non-partial terms, while their definition is not total. They only work for integer and vec128 types and this is why we need type guards to use them. This fact is not explicitly encoded in the declaration of the terms. I guess this is not a proper way to use ISLE, since we cannot trust the ISLE compiler and the ISLE ruleset in this way... But, to fix this, I guess we need more discussions that could easily go out of the scope of fix, so I want to leave this as a future work.

Fix

  • I added ty_iconst partial extractor which rules constructing terms with iconst_s and iconst_u can safely use.
  • The widened rules with bitops in [Cranelift] allow bitop optimizations for vectors #13199 are now guarded with ty_iconst.
  • The reported regression case is added, which tests a float input for band term.

@bongjunj bongjunj requested a review from a team as a code owner April 30, 2026 05:17
@bongjunj bongjunj requested review from alexcrichton and removed request for a team April 30, 2026 05:17
@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language labels Apr 30, 2026
@github-actions
Copy link
Copy Markdown

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
Copy Markdown
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks! To bikeshed this a bit, maybe ty_int_or_vec128? The name ty_iconst can make sense in retrospect once it's understood what it does but just by reading it it's not clear.

Another possibility is ty_int_lane because in Cranelift I believe all types are considered to have lanes, and scalars just have one lane

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.

ISLE iconst_u doesn't support float types

2 participants