Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

[Cranelift] add bit operation simplification rules (#12782)

Hyunbin Kim691bb4f066fb
diff --git a/cranelift/codegen/src/opts/bitops.isle b/cranelift/codegen/src/opts/bitops.isle
index 2374023c81..e3d5d6ead9 100644
--- a/cranelift/codegen/src/opts/bitops.isle
+++ b/cranelift/codegen/src/opts/bitops.isle
@@ -288,4 +288,260 @@
; (~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)))
\ No newline at end of file
+(rule (simplify (bor ty (bnot ty y) (bnot ty x))) (bnot ty (band ty x y)))
+
+; x | ((x ^ y) ^ z) --> x | (y ^ z)
+(rule (simplify (bor ty (bxor ty (bxor ty x y) z) x)) (bor ty (bxor ty y z) x))
+(rule (simplify (bor ty x (bxor ty (bxor ty x y) z))) (bor ty (bxor ty y z) x))
+(rule (simplify (bor ty (bxor ty z (bxor ty x y)) x)) (bor ty (bxor ty y z) x))
+(rule (simplify (bor ty x (bxor ty z (bxor ty x y)))) (bor ty (bxor ty y z) x))
+(rule (simplify (bor ty (bxor ty (bxor ty y x) z) x)) (bor ty (bxor ty y z) x))
+(rule (simplify (bor ty x (bxor ty (bxor ty y x) z))) (bor ty (bxor ty y z) x))
+(rule (simplify (bor ty (bxor ty z (bxor ty y x)) x)) (bor ty (bxor ty y z) x))
+(rule (simplify (bor ty x (bxor ty z (bxor ty y x)))) (bor ty (bxor ty y z) x))
+
+; (x ^ z) == (y ^ z) --> x == y
+(rule (simplify (eq ty (bxor cty x z) (bxor cty y z))) (eq ty x y))
+(rule (simplify (eq ty (bxor cty y z) (bxor cty x z))) (eq ty x y))
+(rule (simplify (eq ty (bxor cty x z) (bxor cty z y))) (eq ty x y))
+(rule (simplify (eq ty (bxor cty z y) (bxor cty x z))) (eq ty x y))
+(rule (simplify (eq ty (bxor cty z x) (bxor cty y z))) (eq ty x y))
+(rule (simplify (eq ty (bxor cty y z) (bxor cty z x))) (eq ty x y))
+(rule (simplify (eq ty (bxor cty z x) (bxor cty z y))) (eq ty x y))
+(rule (simplify (eq ty (bxor cty z y) (bxor cty z x))) (eq ty x y))
+
+; y | ~(x | y) --> y | ~x
+(rule (simplify (bor ty y (bnot ty (bor ty x y)))) (bor ty y (bnot ty x)))
+(rule (simplify (bor ty (bnot ty (bor ty x y)) y)) (bor ty y (bnot ty x)))
+(rule (simplify (bor ty y (bnot ty (bor ty y x)))) (bor ty y (bnot ty x)))
+(rule (simplify (bor ty (bnot ty (bor ty y x)) y)) (bor ty y (bnot ty x)))
+
+; y & ~(x & y) --> y & ~x
+(rule (simplify (band ty y (bnot ty (band ty x y)))) (band ty y (bnot ty x)))
+(rule (simplify (band ty (bnot ty (band ty x y)) y)) (band ty y (bnot ty x)))
+(rule (simplify (band ty y (bnot ty (band ty y x)))) (band ty y (bnot ty x)))
+(rule (simplify (band ty (bnot ty (band ty y x)) y)) (band ty y (bnot ty x)))
+
+; (~x) ^ (x | y) --> x | ~y
+(rule (simplify (bxor ty (bnot ty x) (bor ty x y))) (bor ty x (bnot ty y)))
+(rule (simplify (bxor ty (bor ty x y) (bnot ty x))) (bor ty x (bnot ty y)))
+(rule (simplify (bxor ty (bnot ty x) (bor ty y x))) (bor ty x (bnot ty y)))
+(rule (simplify (bxor ty (bor ty y x) (bnot ty x))) (bor ty x (bnot ty y)))
+
+; (x < y) | (x > y) --> x != y
+(rule (simplify (bor ty (slt ty x y) (sgt ty x y))) (ne ty x y))
+(rule (simplify (bor ty (sgt ty x y) (slt ty x y))) (ne ty x y))
+(rule (simplify (bor ty (slt ty x y) (slt ty y x))) (ne ty x y))
+(rule (simplify (bor ty (slt ty y x) (slt ty x y))) (ne ty x y))
+(rule (simplify (bor ty (sgt ty y x) (sgt ty x y))) (ne ty x y))
+(rule (simplify (bor ty (sgt ty x y) (sgt ty y x))) (ne ty x y))
+(rule (simplify (bor ty (sgt ty y x) (slt ty y x))) (ne ty x y))
+(rule (simplify (bor ty (slt ty y x) (sgt ty y x))) (ne ty x y))
+
+; (x <_u y) | (x >_u y) --> x != y
+(rule (simplify (bor ty (ult ty x y) (ugt ty x y))) (ne ty x y))
+(rule (simplify (bor ty (ugt ty x y) (ult ty x y))) (ne ty x y))
+(rule (simplify (bor ty (ult ty x y) (ult ty y x))) (ne ty x y))
+(rule (simplify (bor ty (ult ty y x) (ult ty x y))) (ne ty x y))
+(rule (simplify (bor ty (ugt ty y x) (ugt ty x y))) (ne ty x y))
+(rule (simplify (bor ty (ugt ty x y) (ugt ty y x))) (ne ty x y))
+(rule (simplify (bor ty (ugt ty y x) (ult ty y x))) (ne ty x y))
+(rule (simplify (bor ty (ult ty y x) (ugt ty y x))) (ne ty x y))
+
+; ~((~x) & y) --> x | ~y
+(rule (simplify (bnot ty (band ty (bnot ty x) y))) (bor ty x (bnot ty y)))
+(rule (simplify (bnot ty (band ty y (bnot ty x)))) (bor ty x (bnot ty y)))
+
+; ~((~x) | y) --> x & ~y
+(rule (simplify (bnot ty (bor ty (bnot ty x) y))) (band ty x (bnot ty y)))
+(rule (simplify (bnot ty (bor ty y (bnot ty x)))) (band ty x (bnot ty y)))
+
+; (x <_u y) | (x == y) --> (x <=_u y)
+(rule (simplify (bor ty (ult ty x y) (eq ty x y))) (ule ty x y))
+(rule (simplify (bor ty (eq ty x y) (ult ty x y))) (ule ty x y))
+(rule (simplify (bor ty (ult ty x y) (eq ty y x))) (ule ty x y))
+(rule (simplify (bor ty (eq ty y x) (ult ty x y))) (ule ty x y))
+
+; (y >_u x) | (x == y) --> (x <=_u y)
+(rule (simplify (bor ty (ugt ty y x) (eq ty x y))) (ule ty x y))
+(rule (simplify (bor ty (eq ty x y) (ugt ty y x))) (ule ty x y))
+(rule (simplify (bor ty (ugt ty y x) (eq ty y x))) (ule ty x y))
+(rule (simplify (bor ty (eq ty y x) (ugt ty y x))) (ule ty x y))
+
+; (x < y) | (x == y) --> (x <= y)
+(rule (simplify (bor ty (slt ty x y) (eq ty x y))) (sle ty x y))
+(rule (simplify (bor ty (eq ty x y) (slt ty x y))) (sle ty x y))
+(rule (simplify (bor ty (slt ty x y) (eq ty y x))) (sle ty x y))
+(rule (simplify (bor ty (eq ty y x) (slt ty x y))) (sle ty x y))
+
+; (y > x) | (x == y) --> (x <= y)
+(rule (simplify (bor ty (sgt ty y x) (eq ty x y))) (sle ty x y))
+(rule (simplify (bor ty (eq ty x y) (sgt ty y x))) (sle ty x y))
+(rule (simplify (bor ty (sgt ty y x) (eq ty y x))) (sle ty x y))
+(rule (simplify (bor ty (eq ty y x) (sgt ty y x))) (sle ty x y))
+
+; (x ^ z) | (((x ^ z) ^ y)) --> (x ^ z) | y
+(rule (simplify (bor ty (bxor ty x z) (bxor ty (bxor ty x z) y))) (bor ty (bxor ty x z) y))
+(rule (simplify (bor ty (bxor ty (bxor ty x z) y) (bxor ty x z))) (bor ty (bxor ty x z) y))
+(rule (simplify (bor ty (bxor ty x z) (bxor ty y (bxor ty x z)))) (bor ty (bxor ty x z) y))
+(rule (simplify (bor ty (bxor ty y (bxor ty x z)) (bxor ty x z))) (bor ty (bxor ty x z) y))
+
+(rule (simplify (bor ty (bxor ty x z) (bxor ty (bxor ty z x) y))) (bor ty (bxor ty x z) y))
+(rule (simplify (bor ty (bxor ty (bxor ty z x) y) (bxor ty x z))) (bor ty (bxor ty x z) y))
+(rule (simplify (bor ty (bxor ty x z) (bxor ty y (bxor ty z x)))) (bor ty (bxor ty x z) y))
+(rule (simplify (bor ty (bxor ty y (bxor ty z x)) (bxor ty x z))) (bor ty (bxor ty x z) y))
+
+(rule (simplify (bor ty (bxor ty z x) (bxor ty (bxor ty x z) y))) (bor ty (bxor ty x z) y))
+(rule (simplify (bor ty (bxor ty (bxor ty x z) y) (bxor ty z x))) (bor ty (bxor ty x z) y))
+(rule (simplify (bor ty (bxor ty z x) (bxor ty y (bxor ty x z)))) (bor ty (bxor ty x z) y))
+(rule (simplify (bor ty (bxor ty y (bxor ty x z)) (bxor ty z x))) (bor ty (bxor ty x z) y))
+
+(rule (simplify (bor ty (bxor ty z x) (bxor ty (bxor ty z x) y))) (bor ty (bxor ty x z) y))
+(rule (simplify (bor ty (bxor ty (bxor ty z x) y) (bxor ty z x))) (bor ty (bxor ty x z) y))
+(rule (simplify (bor ty (bxor ty z x) (bxor ty y (bxor ty z x)))) (bor ty (bxor ty x z) y))
+(rule (simplify (bor ty (bxor ty y (bxor ty z x)) (bxor ty z x))) (bor ty (bxor ty x z) y))
+
+; x | (x ^ y) --> x | y
+(rule (simplify (bor ty x (bxor ty x y))) (bor ty x y))
+(rule (simplify (bor ty (bxor ty x y) x)) (bor ty x y))
+(rule (simplify (bor ty x (bxor ty y x))) (bor ty x y))
+(rule (simplify (bor ty (bxor ty y x) x)) (bor ty x y))
+
+; ~((~x) + y) --> x - y
+(rule (simplify (bnot ty (iadd ty (bnot ty x) y))) (isub ty x y))
+(rule (simplify (bnot ty (iadd ty y (bnot ty x)))) (isub ty x y))
+
+; (x ^ z) | (y | x) --> (y | x) | z
+(rule (simplify (bor ty (bxor ty x z) (bor ty y x))) (bor ty (bor ty y x) z))
+(rule (simplify (bor ty (bor ty y x) (bxor ty x z))) (bor ty (bor ty y x) z))
+(rule (simplify (bor ty (bxor ty x z) (bor ty x y))) (bor ty (bor ty y x) z))
+(rule (simplify (bor ty (bor ty x y) (bxor ty x z))) (bor ty (bor ty y x) z))
+(rule (simplify (bor ty (bxor ty z x) (bor ty y x))) (bor ty (bor ty y x) z))
+(rule (simplify (bor ty (bor ty y x) (bxor ty z x))) (bor ty (bor ty y x) z))
+(rule (simplify (bor ty (bxor ty z x) (bor ty x y))) (bor ty (bor ty y x) z))
+(rule (simplify (bor ty (bor ty x y) (bxor ty z x))) (bor ty (bor ty y x) z))
+
+; (x | y) ^ (x ^ y) --> x & y
+(rule (simplify (bxor ty (bor ty y x) (bxor ty y x))) (band ty x y))
+(rule (simplify (bxor ty (bxor ty y x) (bor ty y x))) (band ty x y))
+(rule (simplify (bxor ty (bor ty y x) (bxor ty x y))) (band ty x y))
+(rule (simplify (bxor ty (bxor ty x y) (bor ty y x))) (band ty x y))
+(rule (simplify (bxor ty (bor ty x y) (bxor ty y x))) (band ty x y))
+(rule (simplify (bxor ty (bxor ty y x) (bor ty x y))) (band ty x y))
+(rule (simplify (bxor ty (bor ty x y) (bxor ty x y))) (band ty x y))
+(rule (simplify (bxor ty (bxor ty x y) (bor ty x y))) (band ty x y))
+
+; x | (z & (x ^ y)) --> x | (z & y)
+(rule (simplify (bor ty (band ty (bxor ty y x) z) x)) (bor ty (band ty y z) x))
+(rule (simplify (bor ty x (band ty (bxor ty y x) z))) (bor ty (band ty y z) x))
+(rule (simplify (bor ty (band ty z (bxor ty y x)) x)) (bor ty (band ty y z) x))
+(rule (simplify (bor ty x (band ty z (bxor ty y x)))) (bor ty (band ty y z) x))
+(rule (simplify (bor ty (band ty (bxor ty x y) z) x)) (bor ty (band ty y z) x))
+(rule (simplify (bor ty x (band ty (bxor ty x y) z))) (bor ty (band ty y z) x))
+(rule (simplify (bor ty (band ty z (bxor ty x y)) x)) (bor ty (band ty y z) x))
+(rule (simplify (bor ty x (band ty z (bxor ty x y)))) (bor ty (band ty y z) x))
+
+; (x | y) | (x ^ z) --> (x | y) | z
+(rule (simplify (bor ty (bor ty x y) (bxor ty x z))) (bor ty (bor ty x y) z))
+(rule (simplify (bor ty (bxor ty x z) (bor ty x y))) (bor ty (bor ty x y) z))
+(rule (simplify (bor ty (bor ty x y) (bxor ty z x))) (bor ty (bor ty x y) z))
+(rule (simplify (bor ty (bxor ty z x) (bor ty x y))) (bor ty (bor ty x y) z))
+(rule (simplify (bor ty (bor ty y x) (bxor ty x z))) (bor ty (bor ty x y) z))
+(rule (simplify (bor ty (bxor ty x z) (bor ty y x))) (bor ty (bor ty x y) z))
+(rule (simplify (bor ty (bor ty y x) (bxor ty z x))) (bor ty (bor ty x y) z))
+(rule (simplify (bor ty (bxor ty z x) (bor ty y x))) (bor ty (bor ty x y) z))
+
+; (x ^ z) != (y ^ z) --> x != y
+(rule (simplify (ne ty (bxor cty x z) (bxor cty y z))) (ne ty x y))
+(rule (simplify (ne ty (bxor cty y z) (bxor cty x z))) (ne ty x y))
+(rule (simplify (ne ty (bxor cty x z) (bxor cty z y))) (ne ty x y))
+(rule (simplify (ne ty (bxor cty z y) (bxor cty x z))) (ne ty x y))
+(rule (simplify (ne ty (bxor cty z x) (bxor cty y z))) (ne ty x y))
+(rule (simplify (ne ty (bxor cty y z) (bxor cty z x))) (ne ty x y))
+(rule (simplify (ne ty (bxor cty z x) (bxor cty z y))) (ne ty x y))
+(rule (simplify (ne ty (bxor cty z y) (bxor cty z x))) (ne ty x y))
+
+; (x & y) | (x & ~y) --> x
+(rule (simplify (bor ty (band ty x y) (band ty x (bnot ty y)))) x)
+(rule (simplify (bor ty (band ty x (bnot ty y)) (band ty x y))) x)
+(rule (simplify (bor ty (band ty x y) (band ty (bnot ty y) x))) x)
+(rule (simplify (bor ty (band ty (bnot ty y) x) (band ty x y))) x)
+(rule (simplify (bor ty (band ty y x) (band ty x (bnot ty y)))) x)
+(rule (simplify (bor ty (band ty x (bnot ty y)) (band ty y x))) x)
+(rule (simplify (bor ty (band ty y x) (band ty (bnot ty y) x))) x)
+(rule (simplify (bor ty (band ty (bnot ty y) x) (band ty y x))) x)
+
+; (x | y) & (x | ~y) --> x
+(rule (simplify (band ty (bor ty x y) (bor ty x (bnot ty y)))) x)
+(rule (simplify (band ty (bor ty x (bnot ty y)) (bor ty x y))) x)
+(rule (simplify (band ty (bor ty x y) (bor ty (bnot ty y) x))) x)
+(rule (simplify (band ty (bor ty (bnot ty y) x) (bor ty x y))) x)
+(rule (simplify (band ty (bor ty y x) (bor ty x (bnot ty y)))) x)
+(rule (simplify (band ty (bor ty x (bnot ty y)) (bor ty y x))) x)
+(rule (simplify (band ty (bor ty y x) (bor ty (bnot ty y) x))) x)
+(rule (simplify (band ty (bor ty (bnot ty y) x) (bor ty y x))) x)
+
+; (x ^ y) | ~x --> ~(x & y)
+(rule (simplify (bor ty (bxor ty y x) (bnot ty x))) (bnot ty (band ty y x)))
+(rule (simplify (bor ty (bnot ty x) (bxor ty y x))) (bnot ty (band ty y x)))
+(rule (simplify (bor ty (bxor ty x y) (bnot ty x))) (bnot ty (band ty y x)))
+(rule (simplify (bor ty (bnot ty x) (bxor ty x y))) (bnot ty (band ty y x)))
+
+; (x ^ y) ^ x --> y
+(rule (simplify (bxor ty (bxor ty x y) x)) y)
+(rule (simplify (bxor ty x (bxor ty x y))) y)
+(rule (simplify (bxor ty (bxor ty y x) x)) y)
+(rule (simplify (bxor ty x (bxor ty y x))) y)
+
+; y | (x & (y | z)) --> y | (x & z)
+(rule (simplify (bor ty (band ty x (bor ty y z)) y)) (bor ty (band ty x z) y))
+(rule (simplify (bor ty y (band ty x (bor ty y z)))) (bor ty (band ty x z) y))
+(rule (simplify (bor ty (band ty (bor ty y z) x) y)) (bor ty (band ty x z) y))
+(rule (simplify (bor ty y (band ty (bor ty y z) x))) (bor ty (band ty x z) y))
+(rule (simplify (bor ty (band ty x (bor ty z y)) y)) (bor ty (band ty x z) y))
+(rule (simplify (bor ty y (band ty x (bor ty z y)))) (bor ty (band ty x z) y))
+(rule (simplify (bor ty (band ty (bor ty z y) x) y)) (bor ty (band ty x z) y))
+(rule (simplify (bor ty y (band ty (bor ty z y) x))) (bor ty (band ty x z) y))
+
+; y & (x | (y & z)) --> y & (x | z)
+(rule (simplify (band ty (bor ty x (band ty y z)) y)) (band ty (bor ty x z) y))
+(rule (simplify (band ty y (bor ty x (band ty y z)))) (band ty (bor ty x z) y))
+(rule (simplify (band ty (bor ty (band ty y z) x) y)) (band ty (bor ty x z) y))
+(rule (simplify (band ty y (bor ty (band ty y z) x))) (band ty (bor ty x z) y))
+(rule (simplify (band ty (bor ty x (band ty z y)) y)) (band ty (bor ty x z) y))
+(rule (simplify (band ty y (bor ty x (band ty z y)))) (band ty (bor ty x z) y))
+(rule (simplify (band ty (bor ty (band ty z y) x) y)) (band ty (bor ty x z) y))
+(rule (simplify (band ty y (bor ty (band ty z y) x))) (band ty (bor ty x z) y))
+
+; y | (x ^ (y & z)) --> x | y
+(rule (simplify (bor ty (bxor ty x (band ty y z)) y)) (bor ty x y))
+(rule (simplify (bor ty y (bxor ty x (band ty y z)))) (bor ty x y))
+(rule (simplify (bor ty (bxor ty (band ty y z) x) y)) (bor ty x y))
+(rule (simplify (bor ty y (bxor ty (band ty y z) x))) (bor ty x y))
+(rule (simplify (bor ty (bxor ty x (band ty z y)) y)) (bor ty x y))
+(rule (simplify (bor ty y (bxor ty x (band ty z y)))) (bor ty x y))
+(rule (simplify (bor ty (bxor ty (band ty z y) x) y)) (bor ty x y))
+(rule (simplify (bor ty y (bxor ty (band ty z y) x))) (bor ty x y))
+
+; ((x & y) ^ y) + z --> (y + z) - (x & y)
+(rule (simplify (iadd ty (bxor ty (band ty x y) y) z)) (isub ty (iadd ty y z) (band ty x y)))
+(rule (simplify (iadd ty z (bxor ty (band ty x y) y))) (isub ty (iadd ty y z) (band ty x y)))
+(rule (simplify (iadd ty (bxor ty y (band ty x y)) z)) (isub ty (iadd ty y z) (band ty x y)))
+(rule (simplify (iadd ty z (bxor ty y (band ty x y)))) (isub ty (iadd ty y z) (band ty x y)))
+(rule (simplify (iadd ty (bxor ty (band ty y x) y) z)) (isub ty (iadd ty y z) (band ty x y)))
+(rule (simplify (iadd ty z (bxor ty (band ty y x) y))) (isub ty (iadd ty y z) (band ty x y)))
+(rule (simplify (iadd ty (bxor ty y (band ty y x)) z)) (isub ty (iadd ty y z) (band ty x y)))
+(rule (simplify (iadd ty z (bxor ty y (band ty y x)))) (isub ty (iadd ty y z) (band ty x y)))
+
+; y & (~y | x) --> y & x
+(rule (simplify (band ty y (bor ty (bnot ty y) x))) (band ty y x))
+(rule (simplify (band ty (bor ty (bnot ty y) x) y)) (band ty y x))
+(rule (simplify (band ty y (bor ty x (bnot ty y)))) (band ty y x))
+(rule (simplify (band ty (bor ty x (bnot ty y)) y)) (band ty y x))
+
+; y | (~y & x) --> y | x
+(rule (simplify (bor ty y (band ty (bnot ty y) x))) (bor ty y x))
+(rule (simplify (bor ty (band ty (bnot ty y) x) y)) (bor ty y x))
+(rule (simplify (bor ty y (band ty x (bnot ty y)))) (bor ty y x))
+(rule (simplify (bor ty (band ty x (bnot ty y)) y)) (bor ty y x))
+
diff --git a/cranelift/filetests/filetests/egraph/bitops.clif b/cranelift/filetests/filetests/egraph/bitops.clif
index 9ec681012d..1ffd6dec74 100644
--- a/cranelift/filetests/filetests/egraph/bitops.clif
+++ b/cranelift/filetests/filetests/egraph/bitops.clif
@@ -482,3 +482,479 @@ block0(v0: i32, v1: i32):
; check: v2 = band v1, v0
; check: return v2
}
+
+;; (bor ty (bxor ty (bxor ty x y) z) x) -> (bor ty (bxor ty y z) x)
+function %test_bor_bxor_bxor_x(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bxor v0, v1
+ v4 = bxor v3, v2
+ v5 = bor v4, v0
+ return v5
+}
+
+; function %test_bor_bxor_bxor_x(i32, i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32, v2: i32):
+; v6 = bxor v1, v2
+; v7 = bor v6, v0
+; return v7
+; }
+
+;; (eq ty (bxor cty x z) (bxor cty y z)) -> (eq ty x y)
+function %simplify_icmp_eq_bxor_shared_rhs(i32, i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bxor v0, v2
+ v4 = bxor v1, v2
+ v5 = icmp eq v3, v4
+ return v5
+}
+
+; function %simplify_icmp_eq_bxor_shared_rhs(i32, i32, i32) -> i8 fast {
+; block0(v0: i32, v1: i32, v2: i32):
+; v6 = icmp eq v0, v1
+; return v6
+; }
+
+;; (bor ty y (bnot ty (bor ty x y))) -> (bor ty y (bnot ty x))
+function %test_bor_bnot_bor_absorb(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bor v0, v1
+ v3 = bnot v2
+ v4 = bor v1, v3
+ return v4
+}
+
+; function %test_bor_bnot_bor_absorb(i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32):
+; v5 = bnot v0
+; v6 = bor v1, v5
+; return v6
+; }
+
+;; (band ty y (bnot ty (band ty x y))) -> (band ty y (bnot ty x))
+function %test_band_bnot_band_absorb(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = band v0, v1
+ v3 = bnot v2
+ v4 = band v1, v3
+ return v4
+}
+
+; function %test_band_bnot_band_absorb(i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32):
+; v5 = bnot v0
+; v6 = band v1, v5
+; return v6
+; }
+
+;; (bxor ty (bnot ty x) (bor ty x y)) -> (bor ty x (bnot ty y))
+function %test_bxor_bnot_bor(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bnot v0
+ v3 = bor v0, v1
+ v4 = bxor v2, v3
+ return v4
+}
+
+; function %test_bxor_bnot_bor(i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32):
+; v5 = bnot v1
+; v6 = bor v0, v5
+; return v6
+; }
+
+;; (bor ty (slt ty x y) (sgt ty x y)) -> (ne ty x y)
+function %test_bor_slt_sgt(i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32):
+ v2 = icmp slt v0, v1
+ v3 = icmp sgt v0, v1
+ v4 = bor v2, v3
+ return v4
+}
+
+; function %test_bor_slt_sgt(i32, i32) -> i8 fast {
+; block0(v0: i32, v1: i32):
+; v5 = icmp ne v0, v1
+; return v5
+; }
+
+;; (bor ty (ult ty x y) (ugt ty x y)) -> (ne ty x y)
+function %test_bor_ult_ugt(i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32):
+ v2 = icmp ult v0, v1
+ v3 = icmp ugt v0, v1
+ v4 = bor v2, v3
+ return v4
+}
+
+; function %test_bor_ult_ugt(i32, i32) -> i8 fast {
+; block0(v0: i32, v1: i32):
+; v5 = icmp ne v0, v1
+; return v5
+; }
+
+;; (bnot ty (band ty (bnot ty x) y)) -> (bor ty x (bnot ty y))
+function %test_bnot_band_bnot(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bnot v0
+ v3 = band v2, v1
+ v4 = bnot v3
+ return v4
+}
+
+; function %test_bnot_band_bnot(i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32):
+; v5 = bnot v1
+; v6 = bor v0, v5
+; return v6
+; }
+
+;; (bnot ty (bor ty (bnot ty x) y)) -> (band ty x (bnot ty y))
+function %test_bnot_bor_bnot(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bnot v0
+ v3 = bor v2, v1
+ v4 = bnot v3
+ return v4
+}
+
+; function %test_bnot_bor_bnot(i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32):
+; v5 = bnot v1
+; v6 = band v0, v5
+; return v6
+; }
+
+;; (bor ty (ult ty x y) (eq ty x y)) -> (ule ty x y)
+function %test_bor_ult_eq(i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32):
+ v2 = icmp ult v0, v1
+ v3 = icmp eq v0, v1
+ v4 = bor v2, v3
+ return v4
+}
+
+; function %test_bor_ult_eq(i32, i32) -> i8 fast {
+; block0(v0: i32, v1: i32):
+; v5 = icmp ule v0, v1
+; return v5
+; }
+
+;; (bor ty (ugt ty y x) (eq ty x y)) -> (ule ty x y)
+function %test_bor_ugt_eq_swap(i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32):
+ v2 = icmp ugt v1, v0
+ v3 = icmp eq v0, v1
+ v4 = bor v2, v3
+ return v4
+}
+
+; function %test_bor_ugt_eq_swap(i32, i32) -> i8 fast {
+; block0(v0: i32, v1: i32):
+; v5 = icmp ule v0, v1
+; return v5
+; }
+
+;; (bor ty (slt ty x y) (eq ty x y)) -> (sle ty x y)
+function %test_bor_slt_eq(i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32):
+ v2 = icmp slt v0, v1
+ v3 = icmp eq v0, v1
+ v4 = bor v2, v3
+ return v4
+}
+
+; function %test_bor_slt_eq(i32, i32) -> i8 fast {
+; block0(v0: i32, v1: i32):
+; v5 = icmp sle v0, v1
+; return v5
+; }
+
+;; (bor ty (sgt ty y x) (eq ty x y)) -> (sle ty x y)
+function %test_bor_sgt_eq_swap(i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32):
+ v2 = icmp sgt v1, v0
+ v3 = icmp eq v0, v1
+ v4 = bor v2, v3
+ return v4
+}
+
+; function %test_bor_sgt_eq_swap(i32, i32) -> i8 fast {
+; block0(v0: i32, v1: i32):
+; v5 = icmp sle v0, v1
+; return v5
+; }
+
+;; (bor ty (bxor ty x z) (bxor ty (bxor ty x z) y)) -> (bor ty (bxor ty x z) y)
+function %test_bor_bxor_bxor_chain(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bxor v0, v1
+ v4 = bxor v3, v2
+ v5 = bor v3, v4
+ return v5
+}
+
+; function %test_bor_bxor_bxor_chain(i32, i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32, v2: i32):
+; v6 = bor v3, v2
+; return v6
+; }
+
+;; (bor ty x (bxor ty x y)) -> (bor ty x y)
+function %test_bor_bxor_self(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bxor v0, v1
+ v3 = bor v0, v2
+ return v3
+}
+
+; function %test_bor_bxor_self(i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32):
+; v4 = bor v0, v1
+; return v4
+; }
+
+;; (bnot ty (iadd ty (bnot ty x) y)) -> (isub ty x y)
+function %test_bnot_iadd_bnot_to_isub(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bnot v0
+ v3 = iadd v2, v1
+ v4 = bnot v3
+ return v4
+}
+
+; function %test_bnot_iadd_bnot_to_isub(i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32):
+; v5 = isub v0, v1
+; return v5
+; }
+
+;; (bor ty (bxor ty x z) (bor ty y x)) -> (bor ty (bor ty y x) z)
+function %test_bor_bxor_bor(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bxor v0, v2
+ v4 = bor v1, v0
+ v5 = bor v3, v4
+ return v5
+}
+
+; function %test_bor_bxor_bor(i32, i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32, v2: i32):
+; v4 = bor v1, v0
+; v6 = bor v4, v2
+; return v6
+; }
+
+;; (bxor ty (bor ty x y) (bxor ty x y)) -> (band ty x y)
+function %test_bxor_bor_bxor(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bor v0, v1
+ v3 = bxor v0, v1
+ v4 = bxor v2, v3
+ return v4
+}
+
+; function %test_bxor_bor_bxor(i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32):
+; v5 = band v0, v1
+; return v5
+; }
+
+;; (bor ty (band ty (bxor ty x y) z) x) -> (bor ty (band ty y z) x)
+function %test_bor_band_bxor(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bxor v0, v1
+ v4 = band v3, v2
+ v5 = bor v4, v0
+ return v5
+}
+
+; function %test_bor_band_bxor(i32, i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32, v2: i32):
+; v6 = band v1, v2
+; v7 = bor v6, v0
+; return v7
+; }
+
+;; (bor ty (bor ty x y) (bxor ty x z)) -> (bor ty (bor ty x y) z)
+function %test_bor_bor_bxor(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bor v0, v1
+ v4 = bxor v0, v2
+ v5 = bor v3, v4
+ return v5
+}
+
+; function %test_bor_bor_bxor(i32, i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32, v2: i32):
+; v3 = bor v0, v1
+; v6 = bor v3, v2
+; return v6
+; }
+
+;; (ne ty (bxor cty x z) (bxor cty y z)) -> (ne ty x y)
+function %simplify_icmp_ne_bxor_shared_rhs(i32, i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bxor v0, v2
+ v4 = bxor v1, v2
+ v5 = icmp ne v3, v4
+ return v5
+}
+
+; function %simplify_icmp_ne_bxor_shared_rhs(i32, i32, i32) -> i8 fast {
+; block0(v0: i32, v1: i32, v2: i32):
+; v6 = icmp ne v0, v1
+; return v6
+; }
+
+;; (bor ty (band ty x y) (band ty x (bnot ty y))) -> x
+function %test_bor_band_band_bnot(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = band v0, v1
+ v3 = bnot v1
+ v4 = band v0, v3
+ v5 = bor v2, v4
+ return v5
+}
+
+; function %test_bor_band_band_bnot(i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32):
+; return v0
+; }
+
+;; (band ty (bor ty x y) (bor ty x (bnot ty y))) -> x
+function %test_band_bor_bor_bnot(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bor v0, v1
+ v3 = bnot v1
+ v4 = bor v0, v3
+ v5 = band v2, v4
+ return v5
+}
+
+; function %test_band_bor_bor_bnot(i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32):
+; return v0
+; }
+
+;; (bor ty (bxor ty x y) (bnot ty x)) -> (bnot ty (band ty y x))
+function %test_bor_bxor_bnot(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bxor v0, v1
+ v3 = bnot v0
+ v4 = bor v2, v3
+ return v4
+}
+
+; function %test_bor_bxor_bnot(i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32):
+; v5 = band v1, v0
+; v6 = bnot v5
+; return v6
+; }
+
+;; (bxor ty (bxor ty x y) x) -> y
+function %test_bxor_bxor_x(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bxor v0, v1
+ v3 = bxor v2, v0
+ return v3
+}
+
+; function %test_bxor_bxor_x(i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32):
+; return v1
+; }
+
+;; (bor ty (band ty x (bor ty y z)) y) -> (bor ty (band ty x z) y)
+function %test_bor_band_bor(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bor v1, v2
+ v4 = band v0, v3
+ v5 = bor v4, v1
+ return v5
+}
+
+; function %test_bor_band_bor(i32, i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32, v2: i32):
+; v6 = band v0, v2
+; v7 = bor v6, v1
+; return v7
+; }
+
+;; (band ty (bor ty x (band ty y z)) y) -> (band ty (bor ty x z) y)
+function %test_band_bor_band(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = band v1, v2
+ v4 = bor v0, v3
+ v5 = band v4, v1
+ return v5
+}
+
+; function %test_band_bor_band(i32, i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32, v2: i32):
+; v6 = bor v0, v2
+; v7 = band v6, v1
+; return v7
+; }
+
+;; (bor ty (bxor ty x (band ty y z)) y) -> (bor ty x y)
+function %test_bor_bxor_band(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = band v1, v2
+ v4 = bxor v0, v3
+ v5 = bor v4, v1
+ return v5
+}
+
+; function %test_bor_bxor_band(i32, i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32, v2: i32):
+; v6 = bor v0, v1
+; return v6
+; }
+
+;; (iadd ty (bxor ty (band ty x y) y) z) -> (isub ty (iadd ty y z) (band ty x y))
+function %test_iadd_bxor_band_to_isub(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = band v0, v1
+ v4 = bxor v3, v1
+ v5 = iadd v4, v2
+ return v5
+}
+
+; function %test_iadd_bxor_band_to_isub(i32, i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32, v2: i32):
+; v6 = iadd v1, v2
+; v7 = band v0, v1
+; v8 = isub v6, v7
+; return v8
+; }
+
+;; (band ty y (bor ty (bnot ty y) x)) -> (band ty y x)
+function %test_band_bor_bnot(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bnot v1
+ v3 = bor v2, v0
+ v4 = band v1, v3
+ return v4
+}
+
+; function %test_band_bor_bnot(i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32):
+; v5 = band v1, v0
+; return v5
+; }
+
+;; (bor ty y (band ty (bnot ty y) x)) -> (bor ty y x)
+function %test_bor_band_bnot(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bnot v1
+ v3 = band v2, v0
+ v4 = bor v1, v3
+ return v4
+}
+
+; function %test_bor_band_bnot(i32, i32) -> i32 fast {
+; block0(v0: i32, v1: i32):
+; v5 = bor v1, v0
+; return v5
+; }
\ No newline at end of file
diff --git a/cranelift/filetests/filetests/egraph/icmp-parameterized.clif b/cranelift/filetests/filetests/egraph/icmp-parameterized.clif
index 0d5222f921..a99f4c0d8b 100644
--- a/cranelift/filetests/filetests/egraph/icmp-parameterized.clif
+++ b/cranelift/filetests/filetests/egraph/icmp-parameterized.clif
@@ -2239,8 +2239,8 @@ block0(v0: i32, v1: i32):
; function %icmp_or_eq_ugt(i32, i32) -> i8 fast {
; block0(v0: i32, v1: i32):
-; v5 = icmp uge v0, v1
-; return v5
+; v6 = icmp uge v0, v1
+; return v6
; }
function %icmp_or_eq_uge(i32, i32) -> i8 {
@@ -2295,8 +2295,8 @@ block0(v0: i32, v1: i32):
; function %icmp_or_eq_sgt(i32, i32) -> i8 fast {
; block0(v0: i32, v1: i32):
-; v5 = icmp sge v0, v1
-; return v5
+; v6 = icmp sge v0, v1
+; return v6
; }
function %icmp_or_eq_sge(i32, i32) -> i8 {
@@ -2519,8 +2519,8 @@ block0(v0: i32, v1: i32):
; function %icmp_or_ult_ugt(i32, i32) -> i8 fast {
; block0(v0: i32, v1: i32):
-; v5 = icmp ne v0, v1
-; return v5
+; v6 = icmp ne v1, v0
+; return v6
; }
function %icmp_or_ult_uge(i32, i32) -> i8 {
@@ -2759,8 +2759,8 @@ block0(v0: i32, v1: i32):
; function %icmp_or_ugt_eq(i32, i32) -> i8 fast {
; block0(v0: i32, v1: i32):
-; v5 = icmp uge v0, v1
-; return v5
+; v6 = icmp uge v0, v1
+; return v6
; }
function %icmp_or_ugt_ne(i32, i32) -> i8 {
@@ -2787,8 +2787,8 @@ block0(v0: i32, v1: i32):
; function %icmp_or_ugt_ult(i32, i32) -> i8 fast {
; block0(v0: i32, v1: i32):
-; v5 = icmp ne v0, v1
-; return v5
+; v6 = icmp ne v1, v0
+; return v6
; }
function %icmp_or_ugt_ule(i32, i32) -> i8 {
@@ -3175,8 +3175,8 @@ block0(v0: i32, v1: i32):
; function %icmp_or_slt_sgt(i32, i32) -> i8 fast {
; block0(v0: i32, v1: i32):
-; v5 = icmp ne v0, v1
-; return v5
+; v6 = icmp ne v1, v0
+; return v6
; }
function %icmp_or_slt_sge(i32, i32) -> i8 {
@@ -3351,8 +3351,8 @@ block0(v0: i32, v1: i32):
; function %icmp_or_sgt_eq(i32, i32) -> i8 fast {
; block0(v0: i32, v1: i32):
-; v5 = icmp sge v0, v1
-; return v5
+; v6 = icmp sge v0, v1
+; return v6
; }
function %icmp_or_sgt_ne(i32, i32) -> i8 {
@@ -3443,8 +3443,8 @@ block0(v0: i32, v1: i32):
; function %icmp_or_sgt_slt(i32, i32) -> i8 fast {
; block0(v0: i32, v1: i32):
-; v5 = icmp ne v0, v1
-; return v5
+; v6 = icmp ne v1, v0
+; return v6
; }
function %icmp_or_sgt_sle(i32, i32) -> i8 {
diff --git a/cranelift/filetests/filetests/runtests/bitops.clif b/cranelift/filetests/filetests/runtests/bitops.clif
index e9ee99d980..7c4aa2ec4f 100644
--- a/cranelift/filetests/filetests/runtests/bitops.clif
+++ b/cranelift/filetests/filetests/runtests/bitops.clif
@@ -336,4 +336,399 @@ block0(v0: i32, v1: i32):
; run: %test_bor_bnot_bnot(0, 0) == 0xffffffff
; run: %test_bor_bnot_bnot(1, 0) == 0xffffffff
-; run: %test_bor_bnot_bnot(1, 1) == 0xfffffffe
\ No newline at end of file
+; run: %test_bor_bnot_bnot(1, 1) == 0xfffffffe
+
+function %test_bor_bxor_bxor_x(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bxor v0, v1
+ v4 = bxor v3, v2
+ v5 = bor v4, v0
+ return v5
+}
+
+; run: %test_bor_bxor_bxor_x(0, 0, 0) == 0
+; run: %test_bor_bxor_bxor_x(1, 0, 0) == 1
+; run: %test_bor_bxor_bxor_x(1, 1, 0) == 1
+
+function %simplify_icmp_eq_bxor_shared_rhs(i32, i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bxor v0, v2
+ v4 = bxor v1, v2
+ v5 = icmp eq v3, v4
+ return v5
+}
+
+; run: %simplify_icmp_eq_bxor_shared_rhs(0, 0, 0) == 1
+; run: %simplify_icmp_eq_bxor_shared_rhs(1, 1, 7) == 1
+; run: %simplify_icmp_eq_bxor_shared_rhs(1, 2, 7) == 0
+
+function %test_bor_bnot_bor_absorb(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bor v0, v1
+ v3 = bnot v2
+ v4 = bor v1, v3
+ return v4
+}
+
+; run: %test_bor_bnot_bor_absorb(0, 0) == 0xffffffff
+; run: %test_bor_bnot_bor_absorb(1, 0) == 0xfffffffe
+
+function %test_band_bnot_band_absorb(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = band v0, v1
+ v3 = bnot v2
+ v4 = band v1, v3
+ return v4
+}
+
+; run: %test_band_bnot_band_absorb(0, 0) == 0
+; run: %test_band_bnot_band_absorb(1, 0) == 0
+; run: %test_band_bnot_band_absorb(0, 1) == 1
+
+function %test_bxor_bnot_bor(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bnot v0
+ v3 = bor v0, v1
+ v4 = bxor v2, v3
+ return v4
+}
+
+; run: %test_bxor_bnot_bor(0, 0) == 0xffffffff
+; run: %test_bxor_bnot_bor(1, 0) == 0xffffffff
+
+;; (bor ty (slt ty x y) (sgt ty x y)) -> (ne ty x y)
+function %test_bor_slt_sgt(i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32):
+ v2 = icmp slt v0, v1
+ v3 = icmp sgt v0, v1
+ v4 = bor v2, v3
+ return v4
+}
+
+; run: %test_bor_slt_sgt(1, 1) == 0
+; run: %test_bor_slt_sgt(1, 3) == 1
+; run: %test_bor_slt_sgt(3, 1) == 1
+
+;; (bor ty (ult ty x y) (ugt ty x y)) -> (ne ty x y)
+function %test_bor_ult_ugt(i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32):
+ v2 = icmp ult v0, v1
+ v3 = icmp ugt v0, v1
+ v4 = bor v2, v3
+ return v4
+}
+
+; run: %test_bor_ult_ugt(1, 1) == 0
+; run: %test_bor_ult_ugt(1, 3) == 1
+; run: %test_bor_ult_ugt(3, 1) == 1
+
+function %test_bnot_band_bnot(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bnot v0
+ v3 = band v2, v1
+ v4 = bnot v3
+ return v4
+}
+
+; run: %test_bnot_band_bnot(0, 0) == 0xffffffff
+; run: %test_bnot_band_bnot(1, 0) == 0xffffffff
+; run: %test_bnot_band_bnot(0, 1) == 0xfffffffe
+
+function %test_bnot_bor_bnot(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bnot v0
+ v3 = bor v2, v1
+ v4 = bnot v3
+ return v4
+}
+
+; run: %test_bnot_bor_bnot(0, 0) == 0
+; run: %test_bnot_bor_bnot(1, 0) == 1
+; run: %test_bnot_bor_bnot(0, 1) == 0
+
+;; (bor ty (ult ty x y) (eq ty x y)) -> (ule ty x y)
+function %test_bor_ult_eq(i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32):
+ v2 = icmp ult v0, v1
+ v3 = icmp eq v0, v1
+ v4 = bor v2, v3
+ return v4
+}
+
+; function %test_bor_ult_eq(i32, i32) -> i8 fast {
+; block0(v0: i32, v1: i32):
+; v5 = icmp ule v0, v1
+; return v5
+; }
+
+;; (bor ty (ugt ty y x) (eq ty x y)) -> (ule ty x y)
+function %test_bor_ugt_eq_swap(i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32):
+ v2 = icmp ugt v1, v0
+ v3 = icmp eq v0, v1
+ v4 = bor v2, v3
+ return v4
+}
+
+; function %test_bor_ugt_eq_swap(i32, i32) -> i8 fast {
+; block0(v0: i32, v1: i32):
+; v5 = icmp ule v0, v1
+; return v5
+; }
+
+;; (bor ty (slt ty x y) (eq ty x y)) -> (sle ty x y)
+function %test_bor_slt_eq(i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32):
+ v2 = icmp slt v0, v1
+ v3 = icmp eq v0, v1
+ v4 = bor v2, v3
+ return v4
+}
+
+; function %test_bor_slt_eq(i32, i32) -> i8 fast {
+; block0(v0: i32, v1: i32):
+; v5 = icmp sle v0, v1
+; return v5
+; }
+
+;; (bor ty (sgt ty y x) (eq ty x y)) -> (sle ty x y)
+function %test_bor_sgt_eq_swap(i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32):
+ v2 = icmp sgt v1, v0
+ v3 = icmp eq v0, v1
+ v4 = bor v2, v3
+ return v4
+}
+
+; function %test_bor_sgt_eq_swap(i32, i32) -> i8 fast {
+; block0(v0: i32, v1: i32):
+; v5 = icmp sle v0, v1
+; return v5
+; }
+
+function %test_bor_bxor_bxor_chain(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bxor v0, v1
+ v4 = bxor v3, v2
+ v5 = bor v3, v4
+ return v5
+}
+
+; run: %test_bor_bxor_bxor_chain(0, 0, 0) == 0
+; run: %test_bor_bxor_bxor_chain(1, 0, 0) == 1
+; run: %test_bor_bxor_bxor_chain(1, 1, 0) == 0
+
+function %test_bor_bxor_self(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bxor v0, v1
+ v3 = bor v0, v2
+ return v3
+}
+
+; run: %test_bor_bxor_self(0, 0) == 0
+; run: %test_bor_bxor_self(1, 0) == 1
+; run: %test_bor_bxor_self(1, 1) == 1
+; run: %test_bor_bxor_self(0xf0, 0x0f) == 0xff
+
+function %test_bnot_iadd_bnot_to_isub_rt(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bnot v0
+ v3 = iadd v2, v1
+ v4 = bnot v3
+ return v4
+}
+
+; run: %test_bnot_iadd_bnot_to_isub_rt(0, 0) == 0
+; run: %test_bnot_iadd_bnot_to_isub_rt(4, 5) == -1
+; run: %test_bnot_iadd_bnot_to_isub_rt(0x12345678, 0x11111111) == 0x01234567
+
+function %test_bor_bxor_bor(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bxor v0, v2
+ v4 = bor v1, v0
+ v5 = bor v3, v4
+ return v5
+}
+
+; run: %test_bor_bxor_bor(0, 0, 0) == 0
+; run: %test_bor_bxor_bor(1, 0, 0) == 1
+; run: %test_bor_bxor_bor(0xf0, 0x0f, 0xaa) == 0xff
+
+function %test_bxor_bor_bxor(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bor v0, v1
+ v3 = bxor v0, v1
+ v4 = bxor v2, v3
+ return v4
+}
+
+; run: %test_bxor_bor_bxor(0, 0) == 0
+; run: %test_bxor_bor_bxor(1, 0) == 0
+; run: %test_bxor_bor_bxor(0x12345678, 0x9abcdef0) == 0x12345670
+
+function %test_bor_band_bxor(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bxor v0, v1
+ v4 = band v3, v2
+ v5 = bor v4, v0
+ return v5
+}
+
+; run: %test_bor_band_bxor(0, 0, 0) == 0
+; run: %test_bor_band_bxor(1, 0, 0) == 1
+; run: %test_bor_band_bxor(1, 1, 1) == 1
+; run: %test_bor_band_bxor(2, 1, 1) == 3
+; run: %test_bor_band_bxor(0xf0, 0x0f, 0xaa) == 0xfa
+
+function %test_bor_bor_bxor(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bor v0, v1
+ v4 = bxor v0, v2
+ v5 = bor v3, v4
+ return v5
+}
+
+; run: %test_bor_bor_bxor(0, 0, 0) == 0
+; run: %test_bor_bor_bxor(1, 0, 0) == 1
+; run: %test_bor_bor_bxor(1, 1, 0) == 1
+; run: %test_bor_bor_bxor(1, 0, 1) == 1
+; run: %test_bor_bor_bxor(0xf0, 0x0f, 0xaa) == 0xff
+
+;; (ne ty (bxor cty x z) (bxor cty y z)) -> (ne ty x y)
+function %simplify_icmp_ne_bxor_shared_rhs(i32, i32, i32) -> i8 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bxor v0, v2
+ v4 = bxor v1, v2
+ v5 = icmp ne v3, v4
+ return v5
+}
+
+; run: %simplify_icmp_ne_bxor_shared_rhs(0, 0, 0) == 0
+; run: %simplify_icmp_ne_bxor_shared_rhs(1, 1, 7) == 0
+; run: %simplify_icmp_ne_bxor_shared_rhs(0x12345678, 0x87654321, 0x9abcdef0) == 1
+
+function %test_bor_band_band_bnot(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = band v0, v1
+ v3 = bnot v1
+ v4 = band v0, v3
+ v5 = bor v2, v4
+ return v5
+}
+
+; run: %test_bor_band_band_bnot(0, 0) == 0
+; run: %test_bor_band_band_bnot(1, 0) == 1
+; run: %test_bor_band_band_bnot(0xf0, 0x0f) == 0xf0
+
+function %test_band_bor_bor_bnot(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bor v0, v1
+ v3 = bnot v1
+ v4 = bor v0, v3
+ v5 = band v2, v4
+ return v5
+}
+
+; run: %test_band_bor_bor_bnot(0, 0) == 0
+; run: %test_band_bor_bor_bnot(1, 0) == 1
+; run: %test_band_bor_bor_bnot(0xf0, 0x0f) == 0xf0
+
+function %test_bor_bxor_bnot(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bxor v0, v1
+ v3 = bnot v0
+ v4 = bor v2, v3
+ return v4
+}
+
+; run: %test_bor_bxor_bnot(1, 1) == 0xfffffffe
+; run: %test_bor_bxor_bnot(0xf0, 0x0f) == 0xffffffff
+; run: %test_bor_bxor_bnot(0x12345678, 0x9abcdef0) == 0xedcba98f
+
+function %test_bxor_bxor_x(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bxor v0, v1
+ v3 = bxor v2, v0
+ return v3
+}
+
+; run: %test_bxor_bxor_x(0, 0) == 0
+; run: %test_bxor_bxor_x(1, 0) == 0
+; run: %test_bxor_bxor_x(1, 1) == 1
+
+function %test_bor_band_bor(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = bor v1, v2
+ v4 = band v0, v3
+ v5 = bor v4, v1
+ return v5
+}
+
+; run: %test_bor_band_bor(0, 0, 0) == 0
+; run: %test_bor_band_bor(1, 0, 0) == 0
+; run: %test_bor_band_bor(1, 1, 0) == 1
+; run: %test_bor_band_bor(2, 1, 1) == 1
+; run: %test_bor_band_bor(0xf0, 0x0f, 0xaa) == 0xaf
+
+function %test_band_bor_band(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = band v1, v2
+ v4 = bor v0, v3
+ v5 = band v4, v1
+ return v5
+}
+
+; run: %test_band_bor_band(0, 0, 0) == 0
+; run: %test_band_bor_band(1, 0, 0) == 0
+; run: %test_band_bor_band(1, 1, 0) == 1
+; run: %test_band_bor_band(2, 1, 1) == 1
+; run: %test_band_bor_band(0xf0, 0x0f, 0xaa) == 0x0a
+
+function %test_bor_bxor_band(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = band v1, v2
+ v4 = bxor v0, v3
+ v5 = bor v4, v1
+ return v5
+}
+
+; run: %test_bor_bxor_band(0, 0, 0) == 0
+; run: %test_bor_bxor_band(1, 0, 0) == 1
+; run: %test_bor_bxor_band(2, 1, 1) == 3
+; run: %test_bor_bxor_band(0xf0, 0x0f, 0xaa) == 0xff
+
+function %test_iadd_bxor_band_to_isub_rt(i32, i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32, v2: i32):
+ v3 = band v0, v1
+ v4 = bxor v3, v1
+ v5 = iadd v4, v2
+ return v5
+}
+
+; run: %test_iadd_bxor_band_to_isub_rt(0, 0, 0) == 0
+; run: %test_iadd_bxor_band_to_isub_rt(2, 1, 3) == 4
+; run: %test_iadd_bxor_band_to_isub_rt(0xf0, 0x0f, 0xaa) == 0xb9
+
+function %test_band_bor_bnot(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bnot v1
+ v3 = bor v2, v0
+ v4 = band v1, v3
+ return v4
+}
+
+; run: %test_band_bor_bnot(0, 0) == 0
+; run: %test_band_bor_bnot(1, 0) == 0
+; run: %test_band_bor_bnot(0xf0, 0x0f) == 0
+
+function %test_bor_band_bnot(i32, i32) -> i32 fast {
+block0(v0: i32, v1: i32):
+ v2 = bnot v1
+ v3 = band v2, v0
+ v4 = bor v1, v3
+ return v4
+}
+
+; run: %test_bor_band_bnot(0, 0) == 0
+; run: %test_bor_band_bnot(1, 0) == 1
+; run: %test_bor_band_bnot(0xf0, 0x0f) == 0xff
\ No newline at end of file