Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cranelift/codegen/src/opts/bitops.isle
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,13 @@
(rule (simplify
(bxor ty (band ty z x) (band ty z y)))
(band ty z (bxor ty x y)))

; (x & y) | ~(x ^ y) => ~(x ^ y)
(rule (simplify (bor ty (band ty x y) (bnot ty (bxor ty x y)))) (bnot ty (bxor ty x y)))
(rule (simplify (bor ty (bnot ty (bxor ty x y)) (band ty x y))) (bnot ty (bxor ty x y)))
(rule (simplify (bor ty (band ty x y) (bnot ty (bxor ty y x)))) (bnot ty (bxor ty x y)))
(rule (simplify (bor ty (bnot ty (bxor ty y x)) (band ty x y))) (bnot ty (bxor ty x y)))
(rule (simplify (bor ty (band ty y x) (bnot ty (bxor ty x y)))) (bnot ty (bxor ty x y)))
(rule (simplify (bor ty (bnot ty (bxor ty x y)) (band ty y x))) (bnot ty (bxor ty x y)))
(rule (simplify (bor ty (band ty y x) (bnot ty (bxor ty y x)))) (bnot ty (bxor ty x y)))
(rule (simplify (bor ty (bnot ty (bxor ty y x)) (band ty y x))) (bnot ty (bxor ty x y)))
16 changes: 16 additions & 0 deletions cranelift/filetests/filetests/egraph/fold-bitops.clif
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,19 @@ block0(v0: i32, v1: i32, v2: i32):
; return v7
; }

;; (bor ty (band ty x y) (bnot ty (bxor ty x y))) -> (bnot ty (bxor ty x y))
function %test_bor_band_bnot_bxor(i32, i32) -> i32 fast {
block0(v0: i32, v1: i32):
v2 = band v0, v1
v3 = bxor v0, v1
v4 = bnot v3
v5 = bor v2, v4
return v5
}

; function %test_bor_band_bnot_bxor(i32, i32) -> i32 fast {
; block0(v0: i32, v1: i32):
; v6 = bxor v1, v0
; v7 = bnot v6
; return v7
; }
13 changes: 13 additions & 0 deletions cranelift/filetests/filetests/runtests/bitops.clif
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,16 @@ block0(v0: i32, v1: i32, v2: i32):

; run: %test_bxor_band_band(2, 1, 1) == 0

function %test_bor_band_bnot_bxor(i32, i32) -> i32 fast {
block0(v0: i32, v1: i32):
v2 = band v0, v1
v3 = bxor v0, v1
v4 = bnot v3
v5 = bor v2, v4
return v5
}

; run: %test_bor_band_bnot_bxor(0, 0) == 0xffffffff
; run: %test_bor_band_bnot_bxor(1, 1) == 0xffffffff
; run: %test_bor_band_bnot_bxor(0, 1) == 0xfffffffe
; run: %test_bor_band_bnot_bxor(2, 1) == 0xfffffffc
Loading