Skip to content

Commit

Permalink
cranelift: simplify ineg(ineg(x)) to x (#6033)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kmeakin authored Mar 16, 2023
1 parent 07136ae commit dccc2d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cranelift/codegen/src/opts/algebraic.isle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
x))
(ineg ty x))

;; ineg(ineg(x)) == x.
(rule (simplify (ineg ty (ineg ty x))) (subsume x))

;; x*1 == 1*x == x.
(rule (simplify (imul ty
x
Expand Down
8 changes: 8 additions & 0 deletions cranelift/filetests/filetests/egraph/algebraic.clif
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ block0(v0: i8):
; check: return v5
}

function %double_ineg(i32) -> i32 {
block0(v0: i32):
v1 = ineg v0
v2 = ineg v1
return v2
; check: return v0
}

function %or_and_y_with_not_y_i8(i8, i8) -> i8 {
block0(v0: i8, v1: i8):
v2 = band v0, v1
Expand Down

0 comments on commit dccc2d6

Please sign in to comment.