-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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: use more iconst_[su]
in opts, notably enabling some i128 patterns
#7693
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,13 @@ | |
|
||
;; Masking out any of the top bits of the result of `uextend` is a no-op. (This | ||
;; is like a cheap version of known-bits analysis.) | ||
(rule (simplify (band wide x @ (uextend _ (value_type narrow)) (iconst _ (u64_from_imm64 mask)))) | ||
(rule (simplify (band wide x @ (uextend _ (value_type narrow)) (iconst_u _ mask))) | ||
; Check that `narrow_mask` has a subset of the bits that `mask` does. | ||
(if-let $true (let ((narrow_mask u64 (ty_mask narrow))) (u64_eq narrow_mask (u64_and mask narrow_mask)))) | ||
x) | ||
|
||
;; Masking out the sign-extended bits of an `sextend` turns it into a `uextend`. | ||
(rule (simplify (band wide (sextend _ x @ (value_type narrow)) (iconst _ (u64_from_imm64 mask)))) | ||
(rule (simplify (band wide (sextend _ x @ (value_type narrow)) (iconst_u _ mask))) | ||
(if-let $true (u64_eq mask (ty_mask narrow))) | ||
(uextend wide x)) | ||
|
||
|
@@ -49,3 +49,12 @@ | |
;; actually doing the extend in the first place. | ||
(rule (simplify (ireduce ty (sextend _ x @ (value_type ty)))) x) | ||
(rule (simplify (ireduce ty (uextend _ x @ (value_type ty)))) x) | ||
|
||
;; `band`, `bor`, and `bxor` can't affect any bits that aren't set in the one of | ||
;; the inputs, so they can be pushed down inside `uextend`s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could pull these (and the reduce ones) into a separate PR if you want, since they're not really following the bigger theme of the PR. They just came from looking at cprop -- which in general can't do 128-bit constants usefully -- and trying to find what would be possible on the extended constants that |
||
(rule (simplify (band bigty (uextend _ x@(value_type smallty)) (uextend _ y@(value_type smallty)))) | ||
(uextend bigty (band smallty x y))) | ||
(rule (simplify (bor bigty (uextend _ x@(value_type smallty)) (uextend _ y@(value_type smallty)))) | ||
(uextend bigty (bor smallty x y))) | ||
(rule (simplify (bxor bigty (uextend _ x@(value_type smallty)) (uextend _ y@(value_type smallty)))) | ||
(uextend bigty (bxor smallty x y))) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,3 +117,4 @@ block0(v0: i8): | |
; check: v4 = iconst.i8 0 | ||
; check: v5 = icmp ne v0, v4 | ||
; check: return v5 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how elegant this is now, but it's still restricted to 64-bit and smaller because
iconst_s $I128 k
will emit a sign-extended constant that's probably the same thing it started with.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind adding a comment to this effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.