Skip to content

[Cranelift] add commutative rules for min/max ops#13198

Open
bongjunj wants to merge 2 commits intobytecodealliance:mainfrom
bongjunj:minmax-canon
Open

[Cranelift] add commutative rules for min/max ops#13198
bongjunj wants to merge 2 commits intobytecodealliance:mainfrom
bongjunj:minmax-canon

Conversation

@bongjunj
Copy link
Copy Markdown
Contributor

No description provided.

@bongjunj bongjunj requested a review from a team as a code owner April 26, 2026 12:18
@bongjunj bongjunj requested review from cfallin and removed request for a team April 26, 2026 12:18
@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language labels Apr 26, 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.

@cfallin
Copy link
Copy Markdown
Member

cfallin commented Apr 27, 2026

Thanks, @bongjunj. As noted previously we generally don't add "commutativity without a further goal"; we do have some rules that push constants "to the right" and reassociate nested expressions for some operators so that const-prop can fire, but I don't see any such motivation here (in fact, your PR description is completely empty). The tests in this PR are similarly unenlightening: they don't highlight any cases where these optimizations enabled other rules to fire, for example. Could you describe the motivation in more detail? Thanks!

@bongjunj
Copy link
Copy Markdown
Contributor Author

Sorry for the oversight on my end. I was seeing that the commutative/associative rules for iadd/isub/imul/... ops do not cover min/max operations. I have added the constant folding rules as well as the associative rules for min/max ops, and created a test scenario where the combinations actually reduces the number of min/max instructions.

Copy link
Copy Markdown
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!

@cfallin cfallin added this pull request to the merge queue Apr 27, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 27, 2026
@cfallin
Copy link
Copy Markdown
Member

cfallin commented Apr 27, 2026

@bongjunj it looks like there's a failing filecheck in CI only found once this hit the merge queue -- happy to re-merge once that's resolved...

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