Skip to content

Cranelift: add mid-end opt rules - #14464

Open
myunbin wants to merge 1 commit into
bytecodealliance:mainfrom
myunbin:add-rules-261001
Open

myunbin wants to merge 1 commit into
bytecodealliance:mainfrom
myunbin:add-rules-261001

Conversation

@myunbin

@myunbin myunbin commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Add new mid-end opt rules:

  • x - (x & M) ==> x & ~M
  • (x - (y & M)) + y ==> (y & ~M) + x
  • (x + y) - (x & M) ==> (x & ~M) + y
  • ((1 << k) + 1) * y ==> (y << k) + y
  • (x + C1) - (y + C2) ==> (C1 - C2) + (x - y) and related add/sub forms
  • uextend(x) == 0 ==> x == 0
  • uextend(x) == uextend(y) ==> x == y
  • (x == y) ^ 1 ==> x != y
  • x >u (x - 1) ==> x != 0, and its dual(<u)
  • (c ? x : y) + (c ? p : q) ==> c ? (x + p) : (y + q)
  • (c ? C1 : C2) & M ==> c ? (C1 & M) : (C2 & M)
  • (x == 0) ? y : (x + y) ==> y + x, and its dual (!=)
  • (c ? C1 : C2) << K ==> c ? (C1 << K) : (C2 << K)

Thanks!

@myunbin
myunbin requested a review from a team as a code owner October 1, 2026 08:17
@myunbin
myunbin requested review from cfallin and removed request for a team October 1, 2026 08:17
@myunbin
myunbin requested a review from a team as a code owner October 1, 2026 08:35
@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language labels Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

Subscribe to Label Action

cc @avanhatt, @cfallin, @fitzgen, @mmcloughlin

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

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

  • avanhatt: isle
  • cfallin: isle
  • fitzgen: isle
  • mmcloughlin: isle

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

Learn more.

@cfallin cfallin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These all look fine overall, thanks! Just one nit below.

(rule (simplify (isub (fits_in_64 ty) x (band ty x (iconst ty y))))
(band ty (iconst ty (imm64_not ty y)) x))

;; (x + C1) - (y + C2) --> (C1 - C2) + (x - y).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's put the constant on the right of the + in the RHS of the rewrite (so (x - y) + (C1 - C2)) -- this is the direction in which we canonicalize constants in general and should play better with other const-folding rules.

This branch has not been deployed

No deployments
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