Stream: git-wasmtime

Topic: wasmtime / PR #7453 egraphs: Merge consecutive shifts and...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2023 at 14:00):

afonso360 requested wasmtime-compiler-reviewers for a review on PR #7453.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2023 at 14:00):

afonso360 requested abrown for a review on PR #7453.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2023 at 14:00):

afonso360 opened PR #7453 from afonso360:egraphs-shifts-2 to bytecodealliance:main:

:wave: Hey,

This PR adds a few mid-end rules that merge consecutive shift and rotate instructions. Here's an overview of the rules added.

Merge consecutive shifts by a constant

(ishl (ishl x k1) k2) == (ishl x (add k1 k2)) if k1 + k2 < ty_bits
(ushr (ushr x k1) k2) == (ushr x (add k1 k2)) if k1 + k2 < ty_bits
(sshr (sshr x k1) k2) == (sshr x (add k1 k2)) if k1 + k2 < ty_bits

Merge consecutive shifts by a constant if they overflow the type size

(ishl (ishl x k1) k2) == 0 if k1 + k2 >= ty_bits
(ushr (ushr x k1) k2) == 0 if k1 + k2 >= ty_bits

Merge consecutive rotates

(rotl (rotr x y) y) == x
(rotr (rotl x y) y) == x

(rotr (rotr x y) z) == (rotr x (iadd y z))
(rotl (rotl x y) z) == (rotl x (iadd y z))
(rotr (rotl x y) z) == (rotr x (isub y z))
(rotl (rotr x y) z) == (rotl x (isub y z))

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2023 at 15:43):

fitzgen submitted PR review:

LGTM with minor nitpick about comment. Thanks!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2023 at 15:43):

fitzgen submitted PR review:

LGTM with minor nitpick about comment. Thanks!

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2023 at 15:43):

fitzgen created PR review comment:

This one is a little subtle because the example identities in the comment do not hold, but the rules are correct because they are doing the shift mask on k{1,2} before the add, and when you do that it is correct.

Mind updating the comment like so?

;; Simliarly, if the shift amount overflows the type, then we can turn
;; it into a 0
;;
;; (ishl (ishl x k1) k2) == 0 if shift_mask(k1) + shift_mask(k2) >= ty_bits
;; (ushr (ushr x k1) k2) == 0 if shift_mask(k1) + shift_mask(k2) >= ty_bits

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2023 at 17:05):

afonso360 updated PR #7453.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2023 at 17:06):

afonso360 has enabled auto merge for PR #7453.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 02 2023 at 18:17):

afonso360 merged PR #7453.


Last updated: Dec 23 2024 at 12:05 UTC