Skip to content
Closed
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
6 changes: 6 additions & 0 deletions cranelift/codegen/src/opts/bitops.isle
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,10 @@
(rule (simplify (iadd ty (ineg ty y) (bor ty y x)))
(band ty x (bnot ty y)))

; (~x) & (~y) --> ~(x | y)
(rule (simplify (band ty (bnot ty x) (bnot ty y))) (bnot ty (bor ty x y)))
(rule (simplify (band ty (bnot ty y) (bnot ty x))) (bnot ty (bor ty x y)))

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

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

; function %test_band_bnot_bnot(i32, i32) -> i32 fast {
; block0(v0: i32, v1: i32):
; v7 = bor v1, v0
; v8 = bnot v7
; return v8
; }

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

; function %test_bor_bnot_bnot(i32, i32) -> i32 fast {
; block0(v0: i32, v1: i32):
; v7 = band v1, v0
; v8 = bnot v7
; return v8
; }

26 changes: 25 additions & 1 deletion cranelift/filetests/filetests/runtests/bitops.clif
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,28 @@ block0(v0: i32, v1: i32):
; run: %test_iadd_bor_ineg(0, 0) == 0
; run: %test_iadd_bor_ineg(1, 1) == 0
; run: %test_iadd_bor_ineg(2, 1) == 2
; run: %test_iadd_bor_ineg(0xffffffff, 0) == -1
; run: %test_iadd_bor_ineg(0xffffffff, 0) == -1

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

; run: %test_band_bnot_bnot(0, 0) == 0xffffffff
; run: %test_band_bnot_bnot(1, 0) == 0xfffffffe
; run: %test_band_bnot_bnot(1, 1) == 0xfffffffe

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

; run: %test_bor_bnot_bnot(0, 0) == 0xffffffff
; run: %test_bor_bnot_bnot(1, 0) == 0xffffffff
; run: %test_bor_bnot_bnot(1, 1) == 0xfffffffe
Loading