Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cranelift: simplify icmp against UMAX/SMIN/SMAX #6037

Merged
merged 2 commits into from
Mar 17, 2023

Conversation

Kmeakin
Copy link
Contributor

@Kmeakin Kmeakin commented Mar 16, 2023

Adds the following rewrites:

;; ult(x, 0) == false.
;; ule(x, 0) == eq(x, 0)
;; ugt(x, 0) == ne(x, 0).
;; uge(x, 0) == true.

;; ult(x, UMAX) == ne(x, UMAX).
;; ule(x, UMAX) == true.
;; ugt(x, UMAX) == false.
;; uge(x, UMAX) == eq(x, UMAX).

;; slt(x, SMIN) == false.
;; sle(x, SMIN) == eq(x, SMIN).
;; sgt(x, SMIN) == ne(x, SMIN).
;; sge(x, SMIN) == true.

;; slt(x, SMAX) == ne(x, SMAX).
;; sle(x, SMAX) == true.
;; sgt(x, SMAX) == false.
;; sge(x, SMAX) == eq(x, SMAX).

Also adds ty_umin, ty_umax, ty_smin and ty_smax constructors

@cfallin cfallin self-assigned this Mar 16, 2023
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.

These all look correct to me -- thanks!

I'll note a stylistic thought (but I don't think any change is needed): I noticed the @-bindings in the left-hand sides are sometimes unused; I assume the intent of e.g. umin @ ... is to document the value at a glance? I do actually like that, but just wanted to call it out and my interpretation of it in case anyone else has thoughts. It's not an idiom I've seen before in our rules.

Could you add some egraph tests to show these rewrites happening, as well? (See files in cranelift/filetests/filetests/egraph/ for examples.) With that, I think this is good to merge.

@Kmeakin
Copy link
Contributor Author

Kmeakin commented Mar 17, 2023

These all look correct to me -- thanks!

I'll note a stylistic thought (but I don't think any change is needed): I noticed the @-bindings in the left-hand sides are sometimes unused; I assume the intent of e.g. umin @ ... is to document the value at a glance? I do actually like that, but just wanted to call it out and my interpretation of it in case anyone else has thoughts. It's not an idiom I've seen before in our rules.

Yes, the unused umin @ ... is for documentation. I can delete them if you prefer

@Kmeakin Kmeakin requested a review from cfallin March 17, 2023 01:55
@github-actions github-actions bot added the cranelift Issues related to the Cranelift code generator label Mar 17, 2023
@cfallin
Copy link
Member

cfallin commented Mar 17, 2023

No, I like the variable-bindings-as-documentation pattern actually; this LGTM. Thanks!

@cfallin cfallin added this pull request to the merge queue Mar 17, 2023
@cfallin cfallin merged commit 73cc433 into bytecodealliance:main Mar 17, 2023
@Kmeakin Kmeakin deleted the icmp-numeric-limits branch January 30, 2024 00:29
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants