Skip to content

Commit

Permalink
egraphs: Remove iconcat as a shift input
Browse files Browse the repository at this point in the history
  • Loading branch information
afonso360 committed Nov 1, 2023
1 parent de52d71 commit 7d1d538
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cranelift/codegen/src/opts/shifts.isle
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,17 @@
(rule (simplify (rotl ty x (ireduce _ y @ (value_type (fits_in_64 _))))) (rotl ty x y))
(rule (simplify (rotl ty x (uextend _ y))) (rotl ty x y))
(rule (simplify (rotl ty x (sextend _ y))) (rotl ty x y))

;; Remove iconcat from the shift amount input. This is correct even if the
;; the iconcat is i8 type, since it can represent the largest shift amount
;; for i128 types.
;;
;; (op x (iconcat y1 y2)) == (op x y1)
;;
;; where `op` is one of ishl, ushr, sshr, rotl, rotr

(rule (simplify (ishl ty x (iconcat _ y _))) (ishl ty x y))
(rule (simplify (ushr ty x (iconcat _ y _))) (ushr ty x y))
(rule (simplify (sshr ty x (iconcat _ y _))) (sshr ty x y))
(rule (simplify (rotr ty x (iconcat _ y _))) (rotr ty x y))
(rule (simplify (rotl ty x (iconcat _ y _))) (rotl ty x y))
55 changes: 55 additions & 0 deletions cranelift/filetests/filetests/egraph/shifts.clif
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,58 @@ block0(v0: i8, v1: i16):

; check: v4 = rotl v0, v1
; check: return v4


function %ishl_amt_type_iconcat(i8, i16, i16) -> i8 {
block0(v0: i8, v1: i16, v2: i16):
v3 = iconcat.i16 v1, v2
v4 = ishl.i8 v0, v3
return v4
}

; check: v5 = ishl v0, v1
; check: return v5


function %ushr_amt_type_iconcat(i8, i16, i16) -> i8 {
block0(v0: i8, v1: i16, v2: i16):
v3 = iconcat.i16 v1, v2
v4 = ushr.i8 v0, v3
return v4
}

; check: v5 = ushr v0, v1
; check: return v5


function %sshr_amt_type_iconcat(i8, i16, i16) -> i8 {
block0(v0: i8, v1: i16, v2: i16):
v3 = iconcat.i16 v1, v2
v4 = sshr.i8 v0, v3
return v4
}

; check: v5 = sshr v0, v1
; check: return v5


function %rotr_amt_type_iconcat(i8, i16, i16) -> i8 {
block0(v0: i8, v1: i16, v2: i16):
v3 = iconcat.i16 v1, v2
v4 = rotr.i8 v0, v3
return v4
}

; check: v5 = rotr v0, v1
; check: return v5


function %rotl_amt_type_iconcat(i8, i16, i16) -> i8 {
block0(v0: i8, v1: i16, v2: i16):
v3 = iconcat.i16 v1, v2
v4 = rotl.i8 v0, v3
return v4
}

; check: v5 = rotl v0, v1
; check: return v5

0 comments on commit 7d1d538

Please sign in to comment.