Skip to content

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

Merged
cfallin merged 2 commits into
bytecodealliance:mainfrom
Kmeakin:icmp-numeric-limits
Mar 17, 2023
Merged

cranelift: simplify icmp against UMAX/SMIN/SMAX#6037
cfallin merged 2 commits into
bytecodealliance:mainfrom
Kmeakin:icmp-numeric-limits

Conversation

@Kmeakin
Copy link
Copy Markdown
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
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.

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