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
4 changes: 4 additions & 0 deletions cranelift/codegen/src/opts/bitops.isle
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,7 @@
(rule (simplify (bxor ty (bxor ty x y) y)) x)
(rule (simplify (bxor ty y (bxor ty x y))) x)

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

64 changes: 64 additions & 0 deletions cranelift/filetests/filetests/egraph/fold-or-and-not.clif
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
test optimize precise-output
set opt_level=speed
target x86_64

function %test1(i8, i8) -> i8 {
block0(v0: i8, v1: i8):
v2 = band v0, v1
v3 = bnot v0
v4 = bor v2, v3
return v4
}

; function %test1(i8, i8) -> i8 fast {
; block0(v0: i8, v1: i8):
; v3 = bnot v0
; v5 = bor v1, v3
; return v5
; }

function %test2(i16, i16) -> i16 {
block0(v0: i16, v1: i16):
v2 = band v0, v1
v3 = bnot v0
v4 = bor v2, v3
return v4
}

; function %test2(i16, i16) -> i16 fast {
; block0(v0: i16, v1: i16):
; v3 = bnot v0
; v5 = bor v1, v3
; return v5
; }

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

; function %test3(i32, i32) -> i32 fast {
; block0(v0: i32, v1: i32):
; v3 = bnot v0
; v5 = bor v1, v3
; return v5
; }

function %test4(i64, i64) -> i64 {
block0(v0: i64, v1: i64):
v2 = band v0, v1
v3 = bnot v0
v4 = bor v2, v3
return v4
}

; function %test4(i64, i64) -> i64 fast {
; block0(v0: i64, v1: i64):
; v3 = bnot v0
; v5 = bor v1, v3
; return v5
; }

10 changes: 10 additions & 0 deletions cranelift/filetests/filetests/runtests/bitops.clif
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,13 @@ block0(v0: i64, v1: i64):

; run: %fold_xor_xor15(0xdead0000, 0x0000beef) == 0xdead0000

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

; run: %fold_or_and_not(0, 0) == 0xffffffff

Loading