Skip to content

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

Cranelift: add mid-end opt rules (#14697)

Hyunbin Kimdd74102446ac
diff --git a/cranelift/codegen/src/opts/arithmetic.isle b/cranelift/codegen/src/opts/arithmetic.isle
index f5a34f29a2..e500678727 100644
--- a/cranelift/codegen/src/opts/arithmetic.isle
+++ b/cranelift/codegen/src/opts/arithmetic.isle
@@ -2,19 +2,19 @@
;; eg: `iadd`, `isub`, `ineg`, `imul`, `fadd`, `fsub`, `fmul`
;; For commutative instructions, we depend on cprop.isle pushing immediates to
-;; the right, and thus only simplify patterns like `x+0`, not `0+x`.
+;; the right, and thus only simplify patterns like `x+0`, not `0+x`
-;; x+0 == x.
+;; x+0 == x
(rule iadd_x_plus_zero (simplify (iadd ty
x
(all_zero ty)))
(subsume x))
-;; x-0 == x.
+;; x-0 == x
(rule (simplify (isub ty
x
(all_zero ty)))
(subsume x))
-;; 0-x == (ineg x).
+;; 0-x == (ineg x)
(rule (simplify (isub ty
(all_zero ty)
x))
@@ -31,37 +31,37 @@
(rule (simplify (isub ty x (ineg ty y)))
(iadd ty x y))
-;; ineg(ineg(x)) == x.
+;; ineg(ineg(x)) == x
(rule (simplify (ineg ty (ineg ty x))) (subsume x))
-;; ineg(x) * ineg(y) == x*y.
+;; ineg(x) * ineg(y) == x*y
(rule (simplify (imul ty (ineg ty x) (ineg ty y)))
(subsume (imul ty x y)))
-;; iabs(ineg(x)) == iabs(x).
+;; iabs(ineg(x)) == iabs(x)
(rule (simplify (iabs ty (ineg ty x)))
(iabs ty x))
-;; iabs(iabs(x)) == iabs(x).
+;; iabs(iabs(x)) == iabs(x)
(rule (simplify (iabs ty inner @ (iabs ty x)))
(subsume inner))
-;; x-x == 0.
+;; x-x == 0
(rule (simplify (isub ty x x)) (subsume (all_zero ty)))
-;; x*1 == x.
+;; x*1 == x
(rule (simplify (imul ty
x
(iconst_u ty 1)))
(subsume x))
-;; x*0 == 0.
+;; x*0 == 0
(rule (simplify (imul ty
_
zero @ (all_zero ty)))
(subsume zero))
-;; x*-1 == ineg(x).
+;; x*-1 == ineg(x)
(rule (simplify (imul ty x (iconst_s ty -1)))
(ineg ty x))
@@ -75,15 +75,15 @@
(rule (simplify (bnot ty (iadd ty x (iconst_s ty -1))))
(ineg ty x))
-;; x / 1 == x.
+;; x / 1 == x
(rule (simplify_skeleton (sdiv x (iconst_s ty 1))) x)
(rule (simplify_skeleton (udiv x (iconst_u ty 1))) x)
-;; Unsigned `x / d == x >> ilog2(d)` when d is a power of two.
+;; Unsigned `x / d == x >> ilog2(d)` when d is a power of two
(rule (simplify_skeleton (udiv x (iconst_u ty (u64_extract_power_of_two d))))
(ushr ty x (iconst_u ty (u64_ilog2 d))))
-;; Signed `x / d` when d is a power of two is a bit more involved...
+;; Signed `x / d` when d is a power of two is a bit more involved
(rule (simplify_skeleton (sdiv x (iconst_u ty (u64_extract_power_of_two d))))
(if-let true (u64_gt d 1))
;; This rule musn't fire for the most negative number - which looks like
@@ -98,7 +98,7 @@
t4))
;; And signed `x / d` when d is a negative power of two is the same, but with a
-;; negation.
+;; negation
(rule (simplify_skeleton (sdiv x (iconst_s ty d)))
(if-let true (i64_is_negative_power_of_two d))
(if-let true (i64_ne d -1))
@@ -110,7 +110,7 @@
(t5 Value (ineg ty t4)))
t5))
-;; General cases for `udiv` with constant divisors.
+;; General cases for `udiv` with constant divisors
(rule (simplify_skeleton (udiv x (iconst_u $I32 (u64_extract_non_zero (u32_from_u64 d)))))
(if-let false (u32_is_power_of_two d))
(apply_div_const_magic_u32 (Opcode.Udiv) x d))
@@ -118,7 +118,7 @@
(if-let false (u64_is_power_of_two d))
(apply_div_const_magic_u64 (Opcode.Udiv) x d))
-;; General cases for `sdiv` with constant divisors.
+;; General cases for `sdiv` with constant divisors
(rule (simplify_skeleton (sdiv x (iconst_s $I32 (i64_extract_non_zero (i32_from_i64 d)))))
(if-let false (i64_is_any_sign_power_of_two d))
(apply_div_const_magic_s32 (Opcode.Sdiv) x d))
@@ -131,17 +131,17 @@
(rule (simplify_skeleton (srem x (iconst_u ty 1))) (all_zero ty))
(rule (simplify_skeleton (srem x (iconst_s ty -1))) (all_zero ty))
-;; Unsigned `x % d == x & ((1 << ilog2(d)) - 1)` when `d` is a power of two.
+;; Unsigned `x % d == x & ((1 << ilog2(d)) - 1)` when `d` is a power of two
(rule (simplify_skeleton (urem x (iconst_u ty (u64_extract_power_of_two d))))
(if-let true (u64_gt d 1))
(let ((mask Value (iconst_u ty (u64_sub (u64_shl 1 (u64_ilog2 d)) 1))))
(band ty x mask)))
;; Signed `x % d` when `d` is a (possibly negative) power of two is a little
-;; more complicated.
+;; more complicated
(rule (simplify_skeleton (srem x d_val @ (iconst_s ty d)))
;; Interestingly, this same sequence works for both positive and negative
- ;; powers of two.
+ ;; powers of two
(if-let true (i64_is_any_sign_power_of_two d))
(if-let true (i64_ne d 1))
(if-let true (i64_ne d -1))
@@ -153,7 +153,7 @@
(t5 Value (isub ty x t4)))
t5))
-;; General cases for `urem` with constant divisors.
+;; General cases for `urem` with constant divisors
(rule (simplify_skeleton (urem x (iconst_u $I32 (u64_extract_non_zero (u32_from_u64 d)))))
(if-let false (u32_is_power_of_two d))
(apply_div_const_magic_u32 (Opcode.Urem) x d))
@@ -161,7 +161,7 @@
(if-let false (u64_is_power_of_two d))
(apply_div_const_magic_u64 (Opcode.Urem) x d))
-;; General cases for `srem` with constant divisors.
+;; General cases for `srem` with constant divisors
(rule (simplify_skeleton (srem x (iconst_s $I32 (i64_extract_non_zero (i32_from_i64 d)))))
(if-let false (i64_is_any_sign_power_of_two d))
(apply_div_const_magic_s32 (Opcode.Srem) x d))
@@ -169,28 +169,28 @@
(if-let false (i64_is_any_sign_power_of_two d))
(apply_div_const_magic_s64 (Opcode.Srem) x d))
-;; x*2 == x+x.
+;; x*2 == x+x
(rule (simplify (imul ty x (iconst_u _ 2)))
(iadd ty x x))
-;; x*c == x<<log2(c) when c is a power of two.
+;; x*c == x<<log2(c) when c is a power of two
;;
;; Note that the type of `iconst` must be the same as the type of `imul`,
;; so these rules can only fire in situations where it's safe to construct an
-;; `iconst` of that type.
+;; `iconst` of that type
(rule (simplify (imul ty x (iconst _ (imm64_power_of_two c))))
(ishl ty x (iconst ty (imm64 c))))
-;; fneg(fneg(x)) == x.
+;; fneg(fneg(x)) == x
(rule (simplify (fneg ty (fneg ty x))) (subsume x))
;; If both of the multiplied arguments to an `fma` are negated then remove
-;; both of them since they cancel out.
+;; both of them since they cancel out
(rule (simplify (fma ty (fneg ty x) (fneg ty y) z))
(fma ty x y z))
;; If both of the multiplied arguments to an `fmul` are negated then remove
-;; both of them since they cancel out.
+;; both of them since they cancel out
(rule fmul_fneg_fneg (simplify (fmul ty (fneg ty x) (fneg ty y)))
(fmul ty x y))
@@ -214,7 +214,7 @@
;; type so remove any unnecessary `uextend` or `sextend` to give backends
;; the chance to convert from the smallest integral type to the float. This
;; can help lowerings on x64 for example which has a less efficient u64-to-float
-;; conversion than other bit widths.
+;; conversion than other bit widths
(rule (simplify (fcvt_from_uint ty (uextend _ val)))
(fcvt_from_uint ty val))
(rule (simplify (fcvt_from_sint ty (sextend _ val)))
@@ -291,7 +291,7 @@
(eq ty y (iconst ty1 (imm64 (u64_div z x)))))
;; (x + y) + (-y) ==> x
-;; and equivalent operand-order variants.
+;; and equivalent operand-order variants
(rule (simplify (iadd ty (iadd ty x y) (ineg ty y))) x)
(rule (simplify (iadd ty (ineg ty y) (iadd ty x y))) x)
(rule (simplify (iadd ty (iadd ty y x) (ineg ty y))) x)
@@ -394,8 +394,8 @@
;; a value of 1 but for vectors this is -1 since each lane is filled with all
;; 1s. We use `(all_zero ty)` for falses for both integers and vectors. This is
;; because of the Cranelift semantics:
-;; When comparing scalars, the result is 1 if the condition holds, or 0 otherwise.
-;; When comparing vectors, the result is -1 (all-ones) if the condition holds, or 0 otherwise.
+;; When comparing scalars, the result is 1 if the condition holds, or 0 otherwise
+;; When comparing vectors, the result is -1 (all-ones) if the condition holds, or 0 otherwise
(decl cmp_true (Type) Value)
(rule 0 (cmp_true (ty_int ty)) (iconst_u ty 1))
(rule 1 (cmp_true (ty_vec128 ty)) (iconst_s ty -1))
@@ -589,17 +589,17 @@
;; -(~x) --> x + 1
(rule (simplify (ineg (ty_int ty) (bnot ty x))) (iadd ty x (iconst_u ty 1)))
-;; ~(-x) --> x - 1.
+;; ~(-x) --> x - 1
(rule (simplify (bnot (ty_int ty) (ineg ty x))) (isub ty x (iconst_u ty 1)))
;; -1 - x --> ~x
(rule (simplify (isub ty (iconst_s ty -1) x)) (bnot ty x))
-;; Negate integer constants at compile time.
+;; -iconst(C) --> iconst(-C)
(rule (simplify (ineg (fits_in_64 ty) (iconst ty x)))
(iconst ty (imm64_neg ty x)))
-;; -(X * C) = X * (-C)
+;; -(x * C) --> x * (-C)
(rule (simplify (ineg (fits_in_64 ty) (imul ty x (iconst ty c))))
(imul ty x (iconst ty (imm64_neg ty c))))
@@ -625,11 +625,11 @@
(rule (simplify_skeleton (udiv x (ishl ty (iconst_u ty 1) y)))
(ushr ty x y))
-;; x %u (1 << k) --> x & ((1 << k) - 1).
+;; x %u (1 << k) --> x & ((1 << k) - 1)
(rule (simplify_skeleton (urem x divisor @ (ishl ty (iconst_u ty 1) k)))
(band ty x (isub ty divisor (iconst_u ty 1))))
-;; (x - (y & M)) + y --> (y & ~M) + x.
+;; (x - (y & M)) + y --> (y & ~M) + x
(rule (simplify (iadd (fits_in_64 ty)
(isub ty x (band ty y (iconst ty z)))
y))
@@ -647,7 +647,7 @@
(band ty y (iconst ty z))))
(iadd ty (band ty y (iconst ty (imm64_not ty z))) x))
-;; ((1 << k) + 1) * y --> (y << k) + y.
+;; ((1 << k) + 1) * y --> (y << k) + y
(rule (simplify (imul ty
(iadd ty (ishl ty (iconst_u ty 1) x) (iconst_u ty 1))
y))
@@ -657,11 +657,11 @@
(iadd ty (ishl ty (iconst_u ty 1) y) (iconst_u ty 1))))
(iadd ty (ishl ty x y) x))
-;; x - (x & M) --> x & ~M.
+;; x - (x & M) --> x & ~M
(rule (simplify (isub (fits_in_64 ty) x (band ty x (iconst ty y))))
(band ty x (iconst ty (imm64_not ty y))))
-;; (x + C1) - (y + C2) --> (x - y) + (C1 - C2).
+;; (x + C1) - (y + C2) --> (x - y) + (C1 - C2)
(rule (simplify (isub (fits_in_64 ty)
(iadd ty x (iconst ty y))
(iadd ty z (iconst ty p))))
@@ -675,7 +675,7 @@
(isub ty z (iconst ty p))))
(iadd ty (isub ty x z) (iconst ty (imm64_sub ty p y))))
-;; (x + C1) + (C2 - y) --> (x - y) + (C1 + C2).
+;; (x + C1) + (C2 - y) --> (x - y) + (C1 + C2)
(rule (simplify (iadd (fits_in_64 ty)
(iadd ty x (iconst ty y))
(isub ty (iconst ty z) p)))
diff --git a/cranelift/codegen/src/opts/bitops.isle b/cranelift/codegen/src/opts/bitops.isle
index 105587afb6..fb54ceec37 100644
--- a/cranelift/codegen/src/opts/bitops.isle
+++ b/cranelift/codegen/src/opts/bitops.isle
@@ -1,6 +1,6 @@
;; Rewrites for `band`, `bnot`, `bor`, `bxor`
-;; Match or create an all-zero bit pattern for all bitwise types.
+;; all_zero(ty) --> 0
(decl all_zero_etor (Type) TypeAndInstructionData)
(extern extractor all_zero_etor all_zero_etor)
(decl f16_zero () Ieee16)
@@ -17,12 +17,12 @@
(rule 4 (all_zero $F128) (f128const $F128 (zero_constant $F128)))
(rule 5 (all_zero (ty_vector ty)) (vconst ty (zero_constant ty)))
-;; x | 0 == x | x == x.
+;; x | 0 == x | x --> x
(rule bor_x_zero (simplify (bor ty x (all_zero ty))) (subsume x))
(rule bor_zero_x (simplify (bor ty (all_zero ty) x)) (subsume x))
(rule (simplify (bor ty x x)) (subsume x))
-;; x ^ 0 == x.
+;; x ^ 0 --> x
(rule bxor_x_zero (simplify (bxor ty x (all_zero ty))) (subsume x))
(rule bxor_zero_x (simplify (bxor ty (all_zero ty) x)) (subsume x))
@@ -41,11 +41,11 @@
(rule (simplify (band ty x (iconst_s ty -1)))
(subsume x))
-;; x & 0 == 0; 0 & x == 0.
+;; x & 0 --> 0
(rule (simplify (band ty x zero @ (all_zero ty))) (subsume zero))
(rule (simplify (band ty zero @ (all_zero ty) x)) (subsume zero))
-;; x & not(x) == 0; not(x) & x == 0.
+;; x & ~x --> 0
(rule (simplify (band ty x (bnot ty x))) (subsume (all_zero ty)))
(rule (simplify (band ty (bnot ty x) x)) (subsume (all_zero ty)))
@@ -240,7 +240,7 @@
(bxor ty (band ty z x) (band ty z y)))
(band ty z (bxor ty x y)))
-; (x & y) | ~(x ^ y) => ~(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)))
@@ -739,7 +739,7 @@
(rule (simplify (eq rty (bnot cty y) (band cty (bnot cty y) x))) (eq rty (bor cty y x) (iconst_s cty -1)))
(rule (simplify (eq rty (bnot cty y) (band cty x (bnot cty y)))) (eq rty (bor cty y x) (iconst_s cty -1)))
-;; (~x & y) & x == (x & ~y) & y == 0.
+;; (~x & y) & x --> 0
(rule (simplify (band ty (band ty (bnot ty x) y) x))
(subsume (all_zero ty)))
(rule (simplify (band ty (band ty x (bnot ty y)) y))
@@ -749,7 +749,7 @@
(rule (simplify (band ty x (band ty y (bnot ty x))))
(subsume (all_zero ty)))
-;; ~(x | y) & x == ~(x | y) & y == 0.
+;; ~(x | y) & x --> 0
(rule (simplify (band ty (bnot ty (bor ty x y)) x))
(subsume (all_zero ty)))
(rule (simplify (band ty (bnot ty (bor ty x y)) y))
@@ -759,7 +759,7 @@
(rule (simplify (band ty x (bnot ty (bor ty y x))))
(subsume (all_zero ty)))
-;; x >=_u (x & y), and (x & y) <=_u x --> true
+;; x >=u (x & y) --> true
(rule (simplify (uge rty x (band ty x y))) (cmp_true rty))
(rule (simplify (uge rty x (band ty y x))) (cmp_true rty))
(rule (simplify (ule rty (band ty x y) x)) (cmp_true rty))
@@ -769,7 +769,7 @@
(rule (simplify (ult rty x (band ty x y))) (subsume (all_zero rty)))
(rule (simplify (ult rty x (band ty y x))) (subsume (all_zero rty)))
-;; (x | y) >=_u x, and x <=_u (x | y) --> true
+;; (x | y) >=u x --> true
(rule (simplify (uge rty (bor ty x y) x)) (cmp_true rty))
(rule (simplify (uge rty (bor ty y x) x)) (cmp_true rty))
(rule (simplify (ule rty x (bor ty x y))) (cmp_true rty))
@@ -791,16 +791,16 @@
;; popcnt(bitrev(x)) == popcnt(x)
(rule (simplify (popcnt ty (bitrev ty x))) (popcnt ty x))
-;; (x ^ y) ^ (x ^ z) --> y ^ z.
+;; (x ^ y) ^ (x ^ z) --> y ^ z
(rule (simplify (bxor ty (bxor ty x y) (bxor ty x z))) (subsume (bxor ty y z)))
(rule (simplify (bxor ty (bxor ty x y) (bxor ty z x))) (subsume (bxor ty y z)))
(rule (simplify (bxor ty (bxor ty y x) (bxor ty x z))) (subsume (bxor ty y z)))
(rule (simplify (bxor ty (bxor ty y x) (bxor ty z x))) (subsume (bxor ty y z)))
-;; (-x) & 1 --> x & 1.
+;; (-x) & 1 --> x & 1
(rule (simplify (band ty (ineg ty x) (iconst_u ty 1))) (band ty x (iconst_u ty 1)))
-;; (x & y) & (x | z) --> x & y.
+;; (x & y) & (x | z) --> x & y
(rule (simplify (band ty (band ty x y) (bor ty x z))) (subsume (band ty x y)))
(rule (simplify (band ty (bor ty x z) (band ty x y))) (subsume (band ty x y)))
(rule (simplify (band ty (band ty x y) (bor ty z x))) (subsume (band ty x y)))
@@ -810,7 +810,7 @@
(rule (simplify (band ty (band ty y x) (bor ty z x))) (subsume (band ty x y)))
(rule (simplify (band ty (bor ty z x) (band ty y x))) (subsume (band ty x y)))
-;; (x & y) | (x | z) --> x | z.
+;; (x & y) | (x | z) --> x | z
(rule (simplify (bor ty (band ty x y) (bor ty x z))) (subsume (bor ty x z)))
(rule (simplify (bor ty (bor ty x z) (band ty x y))) (subsume (bor ty x z)))
(rule (simplify (bor ty (band ty x y) (bor ty z x))) (subsume (bor ty x z)))
@@ -820,14 +820,29 @@
(rule (simplify (bor ty (band ty y x) (bor ty z x))) (subsume (bor ty x z)))
(rule (simplify (bor ty (bor ty z x) (band ty y x))) (subsume (bor ty x z)))
-;; (x & y) | (x ^ y) --> x | y.
+;; (x & y) | (x ^ y) --> x | y
(rule (simplify (bor ty (band ty x y) (bxor ty x y))) (bor ty x y))
(rule (simplify (bor ty (bxor ty x y) (band ty x y))) (bor ty x y))
(rule (simplify (bor ty (band ty x y) (bxor ty y x))) (bor ty x y))
(rule (simplify (bor ty (bxor ty y x) (band ty x y))) (bor ty x y))
-;; ~((~x) - y) --> x + y.
+;; ~((~x) - y) --> x + y
(rule (simplify (bnot ty (isub ty (bnot ty x) y))) (iadd ty x y))
-;; ~((~x) >>s y) --> x >>s y.
+;; ~((~x) >>s y) --> x >>s y
(rule (simplify (bnot ty (sshr ty (bnot ty x) y))) (sshr ty x y))
+
+;; ~x & (x | y) --> ~x & y
+(rule (simplify (band ty (bnot ty x) (bor ty x y))) (band ty (bnot ty x) y))
+(rule (simplify (band ty (bnot ty x) (bor ty y x))) (band ty (bnot ty x) y))
+(rule (simplify (band ty (bor ty x y) (bnot ty x))) (band ty (bnot ty x) y))
+(rule (simplify (band ty (bor ty x y) (bnot ty y))) (band ty (bnot ty y) x))
+
+;; ~x ^ C --> x ^ ~C
+(rule (simplify (bxor (fits_in_64 (ty_int ty)) (bnot ty x) (iconst ty y))) (bxor ty x (iconst ty (imm64_not ty y))))
+
+;; ~(x & y) & (x | y) --> x ^ y
+(rule (simplify (band ty (bnot ty (band ty x y)) (bor ty x y))) (bxor ty x y))
+
+;; ~(x & y) | x --> -1
+(rule (simplify (bor (ty_int_vec128 ty) (bnot ty (band ty x y)) x)) (subsume (iconst_s ty -1)))
diff --git a/cranelift/codegen/src/opts/extends.isle b/cranelift/codegen/src/opts/extends.isle
index 7d4e6fcfe1..b86ae1c602 100644
--- a/cranelift/codegen/src/opts/extends.isle
+++ b/cranelift/codegen/src/opts/extends.isle
@@ -94,33 +94,46 @@
(rule (simplify (iconcat $I128 x (all_zero _))) (uextend $I128 x))
(rule (simplify (iconcat $I128 x (sshr _ x (iconst_u _ 63)))) (sextend $I128 x))
-;; Select narrowest type
+;; ireduce(ireduce(x)) --> ireduce(x)
(rule (simplify (ireduce ty (ireduce cty x))) (ireduce ty x))
-;; uextend(x) <u uextend(y) --> x <u y.
-(rule (simplify (ult rty
- (uextend ty x @ (value_type (ty_int narrow)))
- (uextend ty y @ (value_type narrow))))
- (ult rty x y))
+;; uextend(x) <u uextend(y) --> x <u y
+(rule (simplify (ult ty (uextend cty x @ (value_type ty1)) (uextend cty y @ (value_type ty1)))) (ult ty x y))
-;; uextend(x) == 0 --> x == 0.
+;; uextend(x) == 0 --> x == 0
(rule (simplify (eq ty
(uextend ty1 x @ (value_type cty))
(iconst_u ty1 0)))
(eq ty x (iconst_u cty 0)))
-;; uextend(x) == uextend(y) --> x == y, when x and y have the same type.
+;; uextend(x) == uextend(y) --> x == y
(rule (simplify (eq ty
(uextend cty x @ (value_type ty1))
(uextend cty y @ (value_type ty1))))
(eq ty x y))
-;; sextend(x) OP sextend(y) --> x OP y, where OP = {==, <s}.
-(rule (simplify (eq rty
- (sextend ty x @ (value_type (ty_int narrow)))
- (sextend ty y @ (value_type narrow))))
- (eq rty x y))
-(rule (simplify (slt rty
- (sextend ty x @ (value_type (ty_int narrow)))
- (sextend ty y @ (value_type narrow))))
- (slt rty x y))
+;; sextend(x) OP sextend(y) --> x OP y (OP = {==, <s})
+(rule (simplify (eq ty (sextend cty x @ (value_type ty1)) (sextend cty y @ (value_type ty1)))) (eq ty x y))
+(rule (simplify (slt ty (sextend cty x @ (value_type ty1)) (sextend cty y @ (value_type ty1)))) (slt ty x y))
+
+;; extend(x) != extend(y) --> x != y
+(rule (simplify (ne ty (sextend cty x @ (value_type ty1)) (sextend cty y @ (value_type ty1)))) (ne ty x y))
+(rule (simplify (ne ty (uextend cty x @ (value_type ty1)) (uextend cty y @ (value_type ty1)))) (ne ty x y))
+
+;; sextend(x) OPs sextend(y) --> x OPs y
+(rule (simplify (sge ty (sextend cty x @ (value_type ty1)) (sextend cty y @ (value_type ty1)))) (sge ty x y))
+(rule (simplify (sle ty (sextend cty x @ (value_type ty1)) (sextend cty y @ (value_type ty1)))) (sge ty y x))
+
+;; uextend(x) OPs uextend(y) --> x OPu y
+(rule (simplify (sge ty (uextend cty x @ (value_type ty1)) (uextend cty y @ (value_type ty1)))) (uge ty x y))
+(rule (simplify (sgt ty (uextend cty x @ (value_type ty1)) (uextend cty y @ (value_type ty1)))) (ugt ty x y))
+(rule (simplify (sle ty (uextend cty x @ (value_type ty1)) (uextend cty y @ (value_type ty1)))) (ule ty x y))
+(rule (simplify (slt ty (uextend cty x @ (value_type ty1)) (uextend cty y @ (value_type ty1)))) (ult ty x y))
+
+;; extend(x) OPu extend(y) --> x OPu y
+(rule (simplify (uge ty (sextend cty x @ (value_type ty1)) (sextend cty y @ (value_type ty1)))) (uge ty x y))
+(rule (simplify (ugt ty (sextend cty x @ (value_type ty1)) (sextend cty y @ (value_type ty1)))) (ugt ty x y))
+(rule (simplify (ule ty (sextend cty x @ (value_type ty1)) (sextend cty y @ (value_type ty1)))) (ule ty x y))
+(rule (simplify (ult ty (sextend cty x @ (value_type ty1)) (sextend cty y @ (value_type ty1)))) (ult ty x y))
+(rule (simplify (uge ty (uextend cty x @ (value_type ty1)) (uextend cty y @ (value_type ty1)))) (uge ty x y))
+(rule (simplify (ule ty (uextend cty x @ (value_type ty1)) (uextend cty y @ (value_type ty1)))) (ule ty x y))
diff --git a/cranelift/codegen/src/opts/icmp.isle b/cranelift/codegen/src/opts/icmp.isle
index 20b025c5ba..ce85807e24 100644
--- a/cranelift/codegen/src/opts/icmp.isle
+++ b/cranelift/codegen/src/opts/icmp.isle
@@ -481,11 +481,11 @@
;; ~x != x --> 1
(rule (simplify (ne ty (bnot cty x) x)) (subsume (cmp_true ty)))
-;; x >=_u (x - y) --> x >=_u y, and the opposites
+;; x >=u (x - y) --> x >=u y
(rule (simplify (uge rty x (isub ty x y))) (uge rty x y))
(rule (simplify (ult rty x (isub ty x y))) (ult rty x y))
-;; x >=_u (x >>_u y) --> true, and the opposites
+;; x >=u (x >>u y) --> true
(rule (simplify (uge rty x (ushr ty x y))) (cmp_true rty))
(rule (simplify (ule rty (ushr ty x y) x)) (cmp_true rty))
(rule (simplify (ugt rty (ushr ty x y) x)) (subsume (all_zero rty)))
@@ -513,25 +513,25 @@
(rule (simplify (ne ty (smin cty x y) (smax cty x y))) (ne ty x y))
(rule (simplify (ne ty (smin cty x y) (smax cty y x))) (ne ty x y))
-;; (x - y) == 0 ==> x == y
+;; (x - y) == 0 --> x == y
(rule (simplify (eq ty (isub cty x y) (all_zero cty))) (eq ty x y))
-;; (x - y) != 0 ==> x != y
+;; (x - y) != 0 --> x != y
(rule (simplify (ne ty (isub cty x y) (all_zero cty))) (ne ty x y))
-;; (x ^ y) == 0 ==> x == y
+;; (x ^ y) == 0 --> x == y
(rule (simplify (eq ty (bxor cty x y) (all_zero cty))) (eq ty x y))
-;; (x ^ y) != 0 ==> x != y
+;; (x ^ y) != 0 --> x != y
(rule (simplify (ne ty (bxor cty x y) (all_zero cty))) (ne ty x y))
-;; (x ^ y) == x ==> y == 0
+;; (x ^ y) == x --> y == 0
(rule (simplify (eq ty (bxor cty x y) x)) (eq ty y (all_zero cty)))
-;; (x + y) != x ==> y != 0
+;; (x + y) != x --> y != 0
(rule (simplify (ne ty (iadd cty x y) x)) (ne ty y (all_zero cty)))
-;; -x != -y ==> x != y
+;; -x != -y --> x != y
(rule (simplify (ne ty (ineg cty x) (ineg cty y))) (ne ty x y))
;; (x >>s y) >s -1 --> x >=s 0
@@ -542,11 +542,11 @@
(rule (simplify (sge ty (sshr cty x y) (all_zero cty)))
(subsume (sge ty x (all_zero cty))))
-;; rotl(x, k) == rotl(y, k) --> x == y.
+;; rotl(x, k) == rotl(y, k) --> x == y
(rule (simplify (eq ty (rotl cty x k) (rotl cty y k)))
(subsume (eq ty x y)))
-;; (x >=s 0) & (x <s N) --> x <u N, 0 < N < 2^(B - 1).
+;; (x >=s 0) & (x <s N) --> x <u N, 0 < N < 2^(B - 1)
(rule (simplify (band rty
(sge rty x (all_zero ty))
(slt rty x n @ (iconst_s (ty_int ty) limit))))
@@ -558,7 +558,7 @@
(if-let true (i64_gt limit 0))
(ult rty x n))
-;; x == ((x + (y >>u (B - k))) & -2^k) --> (x & (2^k - 1)) == 0.
+;; x == ((x + (y >>u (B - k))) & -2^k) --> (x & (2^k - 1)) == 0
(rule (simplify (eq rty x
(band (ty_int ty)
(iadd ty x (ushr ty y (iconst_u _ shift)))
@@ -606,18 +606,23 @@
(subsume (eq rty (band ty x (iconst_s ty (i64_wrapping_sub (i64_wrapping_neg mask) 1)))
(all_zero ty))))
-;; (x == y) ^ 1 --> x != y.
+;; (x == y) ^ 1 --> x != y
(rule (simplify (bxor ty
(eq ty x @ (value_type cty) y @ (value_type cty))
(iconst_u ty 1)))
(ne ty x y))
-;; x >u (x - 1) --> x != 0, and its dual.
+;; x >u (x - 1) --> x != 0
(rule (simplify (ugt ty x (isub cty x (iconst_u cty 1))))
(ne ty x (iconst_u cty 0)))
(rule (simplify (ult ty (isub cty x (iconst_u cty 1)) x))
(ne ty x (iconst_u cty 0)))
-;; rotr(x, k) == rotr(y, k) --> x == y.
+;; rotr(x, k) == rotr(y, k) --> x == y
(rule (simplify (eq ty (rotr cty x k) (rotr cty y k)))
(subsume (eq ty x y)))
+
+;; (x != 0) | (y != 0) --> (x | y) != 0
+(rule (simplify (bor ty (ne ty x (iconst_u cty 0)) (ne ty y (iconst_u cty 0)))) (ne ty (bor cty x y) (all_zero cty)))
+;; (x == 0) & (y == 0) --> (x | y) == 0
+(rule (simplify (band ty (eq ty x (iconst_u cty 0)) (eq ty y (iconst_u cty 0)))) (eq ty (bor cty x y) (all_zero cty)))
diff --git a/cranelift/codegen/src/opts/selects.isle b/cranelift/codegen/src/opts/selects.isle
index ff34c71a93..c61df8a22e 100644
--- a/cranelift/codegen/src/opts/selects.isle
+++ b/cranelift/codegen/src/opts/selects.isle
@@ -201,23 +201,23 @@
(rule (simplify (select ty x (eq ty y z) (eq ty (iconst_u cty p) y))) (eq ty y (select cty x z (iconst_u cty p))))
(rule (simplify (select ty x (eq ty y z) (eq ty y (iconst_u cty p)))) (eq ty y (select cty x z (iconst_u cty p))))
-;; (x == y) ? 0 : (x - y) ==> x - y
+;; (x == y) ? 0 : (x - y) --> x - y
(rule (simplify (select ty (eq cty x y) (all_zero ty) (isub ty x y)))
(isub ty x y))
-;; (c ? y : z) + (c ? z : y) ==> z + y
+;; (c ? y : z) + (c ? z : y) --> z + y
(rule (simplify (iadd ty (select ty c y z) (select ty c z y)))
(iadd ty z y))
-;; (x != y) ? (x - y) : 0 ==> x - y
+;; (x != y) ? (x - y) : 0 --> x - y
(rule (simplify (select ty (ne cty x y) (isub ty x y) (all_zero ty)))
(isub ty x y))
-;; (c ? x : y) + (c ? p : q) --> c ? (x + p) : (y + q).
+;; (c ? x : y) + (c ? p : q) --> c ? (x + p) : (y + q)
(rule (simplify (iadd ty (select ty x y z) (select ty x p q)))
(select ty x (iadd ty y p) (iadd ty z q)))
-;; (c ? C1 : C2) & M --> c ? (C1 & M) : (C2 & M).
+;; (c ? C1 : C2) & M --> c ? (C1 & M) : (C2 & M)
(rule (simplify (band (fits_in_64 ty)
(select ty x (iconst ty y) (iconst ty z))
(iconst ty p)))
@@ -238,7 +238,7 @@
(iconst ty (imm64_and ty y (imm64 p)))
(iconst_u ty z)))
-;; (x == 0) ? y : (x + y) --> y + x, and its dual.
+;; (x == 0) ? y : (x + y) --> y + x
(rule (simplify (select ty
(eq cty x (iconst_u ty 0))
y
@@ -260,7 +260,7 @@
y))
(iadd ty y x))
-;; (c ? x : y) OP (c ? y : x) --> x OP y, where OP = {&, |, ^}.
+;; (c ? x : y) OP (c ? y : x) --> x OP y (OP = {&, |, ^})
(rule (simplify (band ty (select ty c x y) (select ty c y x)))
(subsume (band ty x y)))
(rule (simplify (bor ty (select ty c x y) (select ty c y x)))
@@ -268,7 +268,7 @@
(rule (simplify (bxor ty (select ty c x y) (select ty c y x)))
(subsume (bxor ty x y)))
-;; (x == y) ? 0 : (x ^ y) --> x ^ y, and its variants
+;; (x == y) ? 0 : (x ^ y) --> x ^ y
(rule (simplify (select ty (eq cty x y) (all_zero ty) (bxor ty x y)))
(bxor ty x y))
(rule (simplify (select ty (eq cty x y) (all_zero ty) (bxor ty y x)))
@@ -278,7 +278,7 @@
(rule (simplify (select ty (ne cty x y) (bxor ty y x) (all_zero ty)))
(bxor ty x y))
-;; (k == 0) ? x : (x shift k) --> x shift k
+;; (k == 0) ? x : OP(x, k) --> OP(x, k) (OP = {ishl, ushr, sshr, rotl, rotr})
(rule (simplify (select ty (eq cty k (all_zero _)) x (ishl ty x k)))
(ishl ty x k))
(rule (simplify (select ty (ne cty k (all_zero _)) (ishl ty x k) x))
@@ -299,3 +299,17 @@
(rotr ty x k))
(rule (simplify (select ty (ne cty k (all_zero _)) (rotr ty x k) x))
(rotr ty x k))
+
+;; (c ? C1 : C2) | M --> c ? (C1 | M) : (C2 | M)
+(rule (simplify (bor (fits_in_64 ty) (select ty x (iconst ty y) (iconst ty z)) (iconst ty p))) (select ty x (iconst ty (imm64_or ty y p)) (iconst ty (imm64_or ty z p))))
+(rule (simplify (bor (fits_in_64 ty) (iconst ty x) (select ty y (iconst ty z) (iconst ty p)))) (select ty y (iconst ty (imm64_or ty x z)) (iconst ty (imm64_or ty x p))))
+
+;; (c ? C1 : C2) ^ M --> c ? (C1 ^ M) : (C2 ^ M)
+(rule (simplify (bxor (fits_in_64 ty) (select ty x (iconst ty y) (iconst ty z)) (iconst ty p))) (select ty x (iconst ty (imm64_xor ty y p)) (iconst ty (imm64_xor ty z p))))
+(rule (simplify (bxor (fits_in_64 ty) (iconst ty x) (select ty y (iconst ty z) (iconst ty p)))) (select ty y (iconst ty (imm64_xor ty x z)) (iconst ty (imm64_xor ty x p))))
+
+;; C - (c ? C1 : C2) --> c ? (C - C1) : (C - C2)
+(rule (simplify (isub (fits_in_64 ty) (iconst ty x) (select ty y (iconst ty z) (iconst ty p)))) (select ty y (iconst ty (imm64_sub ty x z)) (iconst ty (imm64_sub ty x p))))
+
+;; (c ? C1 : C2) - C --> c ? (C1 - C) : (C2 - C)
+(rule (simplify (isub (fits_in_64 ty) (select ty x (iconst ty y) (iconst ty z)) (iconst ty p))) (select ty x (iconst ty (imm64_sub ty y p)) (iconst ty (imm64_sub ty z p))))
diff --git a/cranelift/codegen/src/opts/shifts.isle b/cranelift/codegen/src/opts/shifts.isle
index 5059bb6260..96ad855f06 100644
--- a/cranelift/codegen/src/opts/shifts.isle
+++ b/cranelift/codegen/src/opts/shifts.isle
@@ -323,35 +323,48 @@
(rule (simplify (ushr ty (band ty (ishl ty x y) z) y)) (band ty x (ushr ty z y)))
(rule (simplify (ushr ty (band ty x (ishl ty y z)) z)) (band ty y (ushr ty x z)))
-;; Zero remains zero for any shift or rotate amount.
+;; OP(0, k) --> 0 (OP = {ishl, ushr, sshr, rotl, rotr})
(rule (simplify (ishl ty (all_zero ty) x)) (subsume (all_zero ty)))
(rule (simplify (ushr ty (all_zero ty) x)) (subsume (all_zero ty)))
(rule (simplify (sshr ty (all_zero ty) x)) (subsume (all_zero ty)))
(rule (simplify (rotl ty (all_zero ty) x)) (subsume (all_zero ty)))
(rule (simplify (rotr ty (all_zero ty) x)) (subsume (all_zero ty)))
-;; All ones remain all ones for arithmetic right shifts or rotates.
+;; OP(-1, k) --> -1 (OP = {sshr, rotl, rotr})
(rule (simplify (sshr ty (iconst_s ty -1) x)) (subsume (iconst_s ty -1)))
(rule (simplify (rotl ty (iconst_s ty -1) x)) (subsume (iconst_s ty -1)))
(rule (simplify (rotr ty (iconst_s ty -1) x)) (subsume (iconst_s ty -1)))
-;; x << (k & (B - 1)) --> x << k.
+;; x << (k & (B - 1)) --> x << k
(rule (simplify (ishl ty x (band _ k (iconst_u _ mask))))
(if-let mask (ty_shift_mask ty))
(ishl ty x k))
-;; x >>u (k & (B - 1)) --> x >>u k.
+;; x >>u (k & (B - 1)) --> x >>u k
(rule (simplify (ushr ty x (band _ k (iconst_u _ mask))))
(if-let mask (ty_shift_mask ty))
(ushr ty x k))
-;; x >>s (k & (B - 1)) --> x >>s k.
+;; x >>s (k & (B - 1)) --> x >>s k
(rule (simplify (sshr ty x (band _ k (iconst_u _ mask))))
(if-let mask (ty_shift_mask ty))
(sshr ty x k))
-;; (c ? C1 : C2) << K --> c ? (C1 << K) : (C2 << K).
+;; (c ? C1 : C2) << K --> c ? (C1 << K) : (C2 << K)
(rule (simplify (ishl (fits_in_64 ty)
(select ty x (iconst ty y) (iconst ty z))
(iconst ty p)))
(select ty x
(iconst ty (imm64_shl ty y p))
(iconst ty (imm64_shl ty z p))))
+
+;; (x >> k) OP (y >> k) --> (x OP y) >> k (OP = {&, |})
+(rule (simplify (bor ty (sshr ty x y) (sshr ty z y))) (sshr ty (bor ty x z) y))
+(rule (simplify (bor ty (ushr ty x y) (ushr ty z y))) (ushr ty (bor ty x z) y))
+(rule (simplify (band ty (sshr ty x y) (sshr ty z y))) (sshr ty (band ty x z) y))
+(rule (simplify (band ty (ushr ty x y) (ushr ty z y))) (ushr ty (band ty x z) y))
+
+;; (x >>s k) & (y >>u k) --> (x & y) >>u k
+(rule (simplify (band ty (sshr ty x y) (ushr ty z y))) (ushr ty (band ty x z) y))
+(rule (simplify (band ty (ushr ty x y) (sshr ty z y))) (ushr ty (band ty x z) y))
+
+;; ((x & M) << k) & M --> (x << k) & M (M = 2^n - 1)
+(rule (simplify (band ty (ishl ty (band ty x (iconst_u ty y)) z) (iconst_u ty y))) (if-let true (u64_eq (u64_and y (u64_wrapping_add y 1)) 0)) (band ty (ishl ty x z) (iconst_u ty y)))
diff --git a/cranelift/filetests/filetests/egraph/bitops.clif b/cranelift/filetests/filetests/egraph/bitops.clif
index fd7daf1395..4319f4ccc6 100644
--- a/cranelift/filetests/filetests/egraph/bitops.clif
+++ b/cranelift/filetests/filetests/egraph/bitops.clif
@@ -1498,3 +1498,154 @@ block0(v0: f32):
; check: v3 = f32const 0.0
; check: return v3
}
+
+function %band_bnot_bor_xy_i32(i32, i32) -> i32 {
+block0(v0: i32, v1: i32):
+ v2 = bnot v0
+ v3 = bor v0, v1
+ v4 = band v2, v3
+ return v4
+}
+
+; check: function %band_bnot_bor_xy_i32(i32, i32) -> i32 fast {
+; nextln: block0(v0: i32, v1: i32):
+; nextln: v2 = bnot v0
+; nextln: v5 = band v2, v1
+; nextln: return v5
+; nextln: }
+
+function %band_bnot_bor_yx_i32(i32, i32) -> i32 {
+block0(v0: i32, v1: i32):
+ v2 = bnot v0
+ v3 = bor v1, v0
+ v4 = band v2, v3
+ return v4
+}
+
+; check: function %band_bnot_bor_yx_i32(i32, i32) -> i32 fast {
+; nextln: block0(v0: i32, v1: i32):
+; nextln: v2 = bnot v0
+; nextln: v5 = band v2, v1
+; nextln: return v5
+; nextln: }
+
+function %band_bor_bnot_x_i32(i32, i32) -> i32 {
+block0(v0: i32, v1: i32):
+ v2 = bor v0, v1
+ v3 = bnot v0
+ v4 = band v2, v3
+ return v4
+}
+
+; check: function %band_bor_bnot_x_i32(i32, i32) -> i32 fast {
+; nextln: block0(v0: i32, v1: i32):
+; nextln: v3 = bnot v0
+; nextln: v5 = band v3, v1
+; nextln: return v5
+; nextln: }
+
+function %band_bor_bnot_y_i32(i32, i32) -> i32 {
+block0(v0: i32, v1: i32):
+ v2 = bor v0, v1
+ v3 = bnot v1
+ v4 = band v2, v3
+ return v4
+}
+
+; check: function %band_bor_bnot_y_i32(i32, i32) -> i32 fast {
+; nextln: block0(v0: i32, v1: i32):
+; nextln: v3 = bnot v1
+; nextln: v5 = band v3, v0
+; nextln: return v5
+; nextln: }
+
+function %bnot_xor_constant_i64(i64) -> i64 {
+block0(v0: i64):
+ v1 = bnot v0
+ v2 = iconst.i64 85
+ v3 = bxor v1, v2
+ return v3
+}
+
+; check: function %bnot_xor_constant_i64(i64) -> i64 fast {
+; nextln: block0(v0: i64):
+; nextln: v4 = iconst.i64 -86
+; nextln: v5 = bxor v0, v4 ; v4 = -86
+; nextln: return v5
+; nextln: }
+
+function %bnot_xor_constant_i8(i8) -> i8 {
+block0(v0: i8):
+ v1 = bnot v0
+ v2 = iconst.i8 85
+ v3 = bxor v1, v2
+ return v3
+}
+
+; check: function %bnot_xor_constant_i8(i8) -> i8 fast {
+; nextln: block0(v0: i8):
+; nextln: v4 = iconst.i8 -86
+; nextln: v5 = bxor v0, v4 ; v4 = -86
+; nextln: return v5
+; nextln: }
+
+function %band_bnot_band_bor_to_xor_i32(i32, i32) -> i32 {
+block0(v0: i32, v1: i32):
+ v2 = band v0, v1
+ v3 = bnot v2
+ v4 = bor v0, v1
+ v5 = band v3, v4
+ return v5
+}
+
+; check: function %band_bnot_band_bor_to_xor_i32(i32, i32) -> i32 fast {
+; nextln: block0(v0: i32, v1: i32):
+; nextln: v6 = bxor v0, v1
+; nextln: return v6
+; nextln: }
+
+function %bor_bnot_band_absorb_i32(i32, i32) -> i32 {
+block0(v0: i32, v1: i32):
+ v2 = band v0, v1
+ v3 = bnot v2
+ v4 = bor v3, v0
+ return v4
+}
+
+; check: function %bor_bnot_band_absorb_i32(i32, i32) -> i32 fast {
+; nextln: block0(v0: i32, v1: i32):
+; nextln: v5 = iconst.i32 -1
+; nextln: return v5 ; v5 = -1
+; nextln: }
+
+
+function %band_bnot_band_bor_to_xor_i32x4(i32x4, i32x4) -> i32x4 {
+block0(v0: i32x4, v1: i32x4):
+ v2 = band v0, v1
+ v3 = bnot v2
+ v4 = bor v0, v1
+ v5 = band v3, v4
+ return v5
+}
+
+; check: function %band_bnot_band_bor_to_xor_i32x4(i32x4, i32x4) -> i32x4 fast {
+; nextln: block0(v0: i32x4, v1: i32x4):
+; nextln: v6 = bxor v0, v1
+; nextln: return v6
+; nextln: }
+
+function %bor_bnot_band_absorb_i32x4(i32x4, i32x4) -> i32x4 {
+block0(v0: i32x4, v1: i32x4):
+ v2 = band v0, v1
+ v3 = bnot v2
+ v4 = bor v3, v0
+ return v4
+}
+
+; check: function %bor_bnot_band_absorb_i32x4(i32x4, i32x4) -> i32x4 fast {
+; nextln: const0 = 0xffffffffffffffffffffffffffffffff
+; nextln: $(=^$)
+; nextln: block0(v0: i32x4, v1: i32x4):
+; nextln: v7 = vconst.i32x4 const0
+; nextln: return v7 ; v7 = const0
+; nextln: }
diff --git a/cranelift/filetests/filetests/egraph/extends.clif b/cranelift/filetests/filetests/egraph/extends.clif
index d87f88ff26..946104816c 100644
--- a/cranelift/filetests/filetests/egraph/extends.clif
+++ b/cranelift/filetests/filetests/egraph/extends.clif
@@ -475,3 +475,315 @@ block0(v0: i8, v1: i8):
; check: v3 = uextend.i32 v1
; check: v4 = icmp eq v2, v3
; check: return v4
+
+function %ne_sextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp ne v2, v3
+ return v4
+}
+
+; check: function %ne_sextend_i8_i64(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp ne v0, v1
+; nextln: return v5
+; nextln: }
+
+function %ne_uextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp ne v2, v3
+ return v4
+}
+
+; check: function %ne_uextend_i8_i64(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp ne v0, v1
+; nextln: return v5
+; nextln: }
+
+function %sge_sextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp sge v2, v3
+ return v4
+}
+
+; check: function %sge_sextend_i8_i64(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp sge v0, v1
+; nextln: return v5
+; nextln: }
+
+function %sle_sextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp sle v2, v3
+ return v4
+}
+
+; check: function %sle_sextend_i8_i64(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp sge v1, v0
+; nextln: return v5
+; nextln: }
+
+function %sge_uextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp sge v2, v3
+ return v4
+}
+
+; check: function %sge_uextend_i8_i64(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp uge v0, v1
+; nextln: return v5
+; nextln: }
+
+function %sgt_uextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp sgt v2, v3
+ return v4
+}
+
+; check: function %sgt_uextend_i8_i64(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp ugt v0, v1
+; nextln: return v5
+; nextln: }
+
+function %sle_uextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp sle v2, v3
+ return v4
+}
+
+; check: function %sle_uextend_i8_i64(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp ule v0, v1
+; nextln: return v5
+; nextln: }
+
+function %slt_uextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp slt v2, v3
+ return v4
+}
+
+; check: function %slt_uextend_i8_i64(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp ult v0, v1
+; nextln: return v5
+; nextln: }
+
+function %uge_sextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp uge v2, v3
+ return v4
+}
+
+; check: function %uge_sextend_i8_i64(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp uge v0, v1
+; nextln: return v5
+; nextln: }
+
+function %ugt_sextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp ugt v2, v3
+ return v4
+}
+
+; check: function %ugt_sextend_i8_i64(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp ugt v0, v1
+; nextln: return v5
+; nextln: }
+
+function %ule_sextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp ule v2, v3
+ return v4
+}
+
+; check: function %ule_sextend_i8_i64(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp ule v0, v1
+; nextln: return v5
+; nextln: }
+
+function %ult_sextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp ult v2, v3
+ return v4
+}
+
+; check: function %ult_sextend_i8_i64(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp ult v0, v1
+; nextln: return v5
+; nextln: }
+
+function %uge_uextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp uge v2, v3
+ return v4
+}
+
+; check: function %uge_uextend_i8_i64(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp uge v0, v1
+; nextln: return v5
+; nextln: }
+
+function %ule_uextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp ule v2, v3
+ return v4
+}
+
+; check: function %ule_uextend_i8_i64(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp ule v0, v1
+; nextln: return v5
+; nextln: }
+
+function %sge_uextend_i8_i16(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i16 v0
+ v3 = uextend.i16 v1
+ v4 = icmp sge v2, v3
+ return v4
+}
+
+; check: function %sge_uextend_i8_i16(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp uge v0, v1
+; nextln: return v5
+; nextln: }
+
+function %sgt_uextend_i8_i16(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i16 v0
+ v3 = uextend.i16 v1
+ v4 = icmp sgt v2, v3
+ return v4
+}
+
+; check: function %sgt_uextend_i8_i16(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp ugt v0, v1
+; nextln: return v5
+; nextln: }
+
+function %sle_uextend_i8_i16(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i16 v0
+ v3 = uextend.i16 v1
+ v4 = icmp sle v2, v3
+ return v4
+}
+
+; check: function %sle_uextend_i8_i16(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp ule v0, v1
+; nextln: return v5
+; nextln: }
+
+function %slt_uextend_i8_i16(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i16 v0
+ v3 = uextend.i16 v1
+ v4 = icmp slt v2, v3
+ return v4
+}
+
+; check: function %slt_uextend_i8_i16(i8, i8) -> i8 fast {
+; nextln: block0(v0: i8, v1: i8):
+; nextln: v5 = icmp ult v0, v1
+; nextln: return v5
+; nextln: }
+
+function %sge_sextend_i8_i64_different_input_types(i8, i16) -> i8 {
+block0(v0: i8, v1: i16):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp sge v2, v3
+ return v4
+}
+
+; check: function %sge_sextend_i8_i64_different_input_types(i8, i16) -> i8 fast {
+; nextln: block0(v0: i8, v1: i16):
+; nextln: v2 = sextend.i64 v0
+; nextln: v3 = sextend.i64 v1
+; nextln: v4 = icmp sge v2, v3
+; nextln: return v4
+; nextln: }
+
+function %uge_uextend_i8_i64_different_input_types(i8, i16) -> i8 {
+block0(v0: i8, v1: i16):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp uge v2, v3
+ return v4
+}
+
+; check: function %uge_uextend_i8_i64_different_input_types(i8, i16) -> i8 fast {
+; nextln: block0(v0: i8, v1: i16):
+; nextln: v2 = uextend.i64 v0
+; nextln: v3 = uextend.i64 v1
+; nextln: v4 = icmp uge v2, v3
+; nextln: return v4
+; nextln: }
+
+function %uge_sextend_i64_i128(i64, i64) -> i8 {
+block0(v0: i64, v1: i64):
+ v2 = sextend.i128 v0
+ v3 = sextend.i128 v1
+ v4 = icmp uge v2, v3
+ return v4
+}
+
+; check: function %uge_sextend_i64_i128(i64, i64) -> i8 fast {
+; nextln: block0(v0: i64, v1: i64):
+; nextln: v5 = icmp uge v0, v1
+; nextln: return v5
+; nextln: }
+
+function %sgt_uextend_i64_i128(i64, i64) -> i8 {
+block0(v0: i64, v1: i64):
+ v2 = uextend.i128 v0
+ v3 = uextend.i128 v1
+ v4 = icmp sgt v2, v3
+ return v4
+}
+
+; check: function %sgt_uextend_i64_i128(i64, i64) -> i8 fast {
+; nextln: block0(v0: i64, v1: i64):
+; nextln: v5 = icmp ugt v0, v1
+; nextln: return v5
+; nextln: }
diff --git a/cranelift/filetests/filetests/egraph/i128-opts.clif b/cranelift/filetests/filetests/egraph/i128-opts.clif
index 33e96ec52f..ec7814ccd5 100644
--- a/cranelift/filetests/filetests/egraph/i128-opts.clif
+++ b/cranelift/filetests/filetests/egraph/i128-opts.clif
@@ -144,7 +144,7 @@ block0:
v1 = uextend.i128 v0
v2 = icmp slt v1, v1
return v2
- ; check: v3 = iconst.i8 0
+ ; check: v4 = iconst.i8 0
; check: return
}
@@ -157,3 +157,36 @@ block0:
; check: v4 = iconst.i8 0
; check: return
}
+
+function %bor_bnot_band_absorb_i128(i128, i128) -> i128 {
+block0(v0: i128, v1: i128):
+ v2 = band v0, v1
+ v3 = bnot v2
+ v4 = bor v3, v0
+ return v4
+}
+
+; check: function %bor_bnot_band_absorb_i128(i128, i128) -> i128 fast {
+; nextln: block0(v0: i128, v1: i128):
+; nextln: v5 = iconst.i64 -1
+; nextln: v6 = sextend.i128 v5 ; v5 = -1
+; nextln: return v6
+; nextln: }
+
+function %bnot_xor_constant_i128_guard(i128) -> i128 {
+block0(v0: i128):
+ v1 = bnot v0
+ v2 = iconst.i64 85
+ v3 = uextend.i128 v2
+ v4 = bxor v1, v3
+ return v4
+}
+
+; check: function %bnot_xor_constant_i128_guard(i128) -> i128 fast {
+; nextln: block0(v0: i128):
+; nextln: v1 = bnot v0
+; nextln: v2 = iconst.i64 85
+; nextln: v3 = uextend.i128 v2 ; v2 = 85
+; nextln: v4 = bxor v1, v3
+; nextln: return v4
+; nextln: }
diff --git a/cranelift/filetests/filetests/egraph/icmp.clif b/cranelift/filetests/filetests/egraph/icmp.clif
index 402de717e1..e202251fab 100644
--- a/cranelift/filetests/filetests/egraph/icmp.clif
+++ b/cranelift/filetests/filetests/egraph/icmp.clif
@@ -1447,3 +1447,37 @@ block0(v0: i32, v1: i32, v2: i32):
; v3 = rotr v0, v2
; return v6, v3
; }
+
+function %bor_ne_zero_i32(i32, i32) -> i8 {
+block0(v0: i32, v1: i32):
+ v2 = iconst.i32 0
+ v3 = icmp ne v0, v2
+ v4 = icmp ne v1, v2
+ v5 = bor v3, v4
+ return v5
+}
+
+; function %bor_ne_zero_i32(i32, i32) -> i8 fast {
+; block0(v0: i32, v1: i32):
+; v6 = bor v0, v1
+; v2 = iconst.i32 0
+; v7 = icmp ne v6, v2 ; v2 = 0
+; return v7
+; }
+
+function %band_eq_zero_i32(i32, i32) -> i8 {
+block0(v0: i32, v1: i32):
+ v2 = iconst.i32 0
+ v3 = icmp eq v0, v2
+ v4 = icmp eq v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; function %band_eq_zero_i32(i32, i32) -> i8 fast {
+; block0(v0: i32, v1: i32):
+; v6 = bor v0, v1
+; v2 = iconst.i32 0
+; v7 = icmp eq v6, v2 ; v2 = 0
+; return v7
+; }
diff --git a/cranelift/filetests/filetests/egraph/selects.clif b/cranelift/filetests/filetests/egraph/selects.clif
index 29ed52da0c..c3ab029bc7 100644
--- a/cranelift/filetests/filetests/egraph/selects.clif
+++ b/cranelift/filetests/filetests/egraph/selects.clif
@@ -946,3 +946,165 @@ block0(v0: i32, v1: i32):
; v5 = select v3, v0, v4
; return v5
; }
+
+function %bor_select_constants_right_i64(i8) -> i64 {
+block0(v0: i8):
+ v1 = iconst.i64 17
+ v2 = iconst.i64 33
+ v3 = select v0, v1, v2
+ v4 = iconst.i64 5
+ v5 = bor v3, v4
+ return v5
+}
+
+; function %bor_select_constants_right_i64(i8) -> i64 fast {
+; block0(v0: i8):
+; v6 = iconst.i64 21
+; v7 = iconst.i64 37
+; v8 = select v0, v6, v7 ; v6 = 21, v7 = 37
+; return v8
+; }
+
+function %bor_select_constants_left_i64(i8) -> i64 {
+block0(v0: i8):
+ v1 = iconst.i64 17
+ v2 = iconst.i64 33
+ v3 = select v0, v1, v2
+ v4 = iconst.i64 5
+ v5 = bor v4, v3
+ return v5
+}
+
+; function %bor_select_constants_left_i64(i8) -> i64 fast {
+; block0(v0: i8):
+; v6 = iconst.i64 21
+; v7 = iconst.i64 37
+; v8 = select v0, v6, v7 ; v6 = 21, v7 = 37
+; return v8
+; }
+
+function %bxor_select_constants_right_i64(i8) -> i64 {
+block0(v0: i8):
+ v1 = iconst.i64 17
+ v2 = iconst.i64 33
+ v3 = select v0, v1, v2
+ v4 = iconst.i64 5
+ v5 = bxor v3, v4
+ return v5
+}
+
+; function %bxor_select_constants_right_i64(i8) -> i64 fast {
+; block0(v0: i8):
+; v6 = iconst.i64 20
+; v7 = iconst.i64 36
+; v8 = select v0, v6, v7 ; v6 = 20, v7 = 36
+; return v8
+; }
+
+function %bxor_select_constants_left_i64(i8) -> i64 {
+block0(v0: i8):
+ v1 = iconst.i64 17
+ v2 = iconst.i64 33
+ v3 = select v0, v1, v2
+ v4 = iconst.i64 5
+ v5 = bxor v4, v3
+ return v5
+}
+
+; function %bxor_select_constants_left_i64(i8) -> i64 fast {
+; block0(v0: i8):
+; v6 = iconst.i64 20
+; v7 = iconst.i64 36
+; v8 = select v0, v6, v7 ; v6 = 20, v7 = 36
+; return v8
+; }
+
+function %isub_select_constants_left_i64(i8) -> i64 {
+block0(v0: i8):
+ v1 = iconst.i64 17
+ v2 = iconst.i64 33
+ v3 = select v0, v1, v2
+ v4 = iconst.i64 85
+ v5 = isub v4, v3
+ return v5
+}
+
+; function %isub_select_constants_left_i64(i8) -> i64 fast {
+; block0(v0: i8):
+; v6 = iconst.i64 68
+; v7 = iconst.i64 52
+; v8 = select v0, v6, v7 ; v6 = 68, v7 = 52
+; return v8
+; }
+
+function %isub_select_constants_right_i64(i8) -> i64 {
+block0(v0: i8):
+ v1 = iconst.i64 17
+ v2 = iconst.i64 33
+ v3 = select v0, v1, v2
+ v4 = iconst.i64 85
+ v5 = isub v3, v4
+ return v5
+}
+
+; function %isub_select_constants_right_i64(i8) -> i64 fast {
+; block0(v0: i8):
+; v6 = iconst.i64 -68
+; v7 = iconst.i64 -52
+; v8 = select v0, v6, v7 ; v6 = -68, v7 = -52
+; return v8
+; }
+
+function %isub_select_constants_left_i8_wrapping(i8) -> i8 {
+block0(v0: i8):
+ v1 = iconst.i8 127
+ v2 = iconst.i8 -128
+ v3 = select v0, v1, v2
+ v4 = iconst.i8 1
+ v5 = isub v4, v3
+ return v5
+}
+
+; function %isub_select_constants_left_i8_wrapping(i8) -> i8 fast {
+; block0(v0: i8):
+; v6 = iconst.i8 -126
+; v7 = iconst.i8 -127
+; v8 = select v0, v6, v7 ; v6 = -126, v7 = -127
+; return v8
+; }
+
+function %isub_select_constants_right_i8_wrapping(i8) -> i8 {
+block0(v0: i8):
+ v1 = iconst.i8 127
+ v2 = iconst.i8 -128
+ v3 = select v0, v1, v2
+ v4 = iconst.i8 1
+ v5 = isub v3, v4
+ return v5
+}
+
+; function %isub_select_constants_right_i8_wrapping(i8) -> i8 fast {
+; block0(v0: i8):
+; v6 = iconst.i8 126
+; v1 = iconst.i8 127
+; v7 = select v0, v6, v1 ; v6 = 126, v1 = 127
+; return v7
+; }
+
+function %bor_select_nonconstant_branch_i64(i8, i64) -> i64 {
+block0(v0: i8, v1: i64):
+ v2 = iconst.i64 17
+ v3 = select v0, v2, v1
+ v4 = iconst.i64 5
+ v5 = bor v3, v4
+ return v5
+}
+
+; function %bor_select_nonconstant_branch_i64(i8, i64) -> i64 fast {
+; block0(v0: i8, v1: i64):
+; v2 = iconst.i64 17
+; v3 = select v0, v2, v1 ; v2 = 17
+; v4 = iconst.i64 5
+; v5 = bor v3, v4 ; v4 = 5
+; return v5
+; }
diff --git a/cranelift/filetests/filetests/egraph/shifts.clif b/cranelift/filetests/filetests/egraph/shifts.clif
index 4953d4a7c3..8b79db1211 100644
--- a/cranelift/filetests/filetests/egraph/shifts.clif
+++ b/cranelift/filetests/filetests/egraph/shifts.clif
@@ -858,3 +858,235 @@ block0(v0: i8):
; check: v7 = iconst.i8 20
; check: v8 = select v0, v6, v7 ; v6 = 12, v7 = 20
; check: return v8
+
+function %bor_sshr_sshr_same_count_i32(i32, i32, i8) -> i32 {
+block0(v0: i32, v1: i32, v2: i8):
+ v3 = sshr v0, v2
+ v4 = sshr v1, v2
+ v5 = bor v3, v4
+ return v5
+}
+
+; check: function %bor_sshr_sshr_same_count_i32(i32, i32, i8) -> i32 fast {
+; nextln: block0(v0: i32, v1: i32, v2: i8):
+; nextln: v6 = bor v0, v1
+; nextln: v7 = sshr v6, v2
+; nextln: return v7
+; nextln: }
+
+function %bor_ushr_ushr_same_count_i32(i32, i32, i8) -> i32 {
+block0(v0: i32, v1: i32, v2: i8):
+ v3 = ushr v0, v2
+ v4 = ushr v1, v2
+ v5 = bor v3, v4
+ return v5
+}
+
+; check: function %bor_ushr_ushr_same_count_i32(i32, i32, i8) -> i32 fast {
+; nextln: block0(v0: i32, v1: i32, v2: i8):
+; nextln: v6 = bor v0, v1
+; nextln: v7 = ushr v6, v2
+; nextln: return v7
+; nextln: }
+
+function %band_sshr_sshr_same_count_i32(i32, i32, i8) -> i32 {
+block0(v0: i32, v1: i32, v2: i8):
+ v3 = sshr v0, v2
+ v4 = sshr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; check: function %band_sshr_sshr_same_count_i32(i32, i32, i8) -> i32 fast {
+; nextln: block0(v0: i32, v1: i32, v2: i8):
+; nextln: v6 = band v0, v1
+; nextln: v7 = sshr v6, v2
+; nextln: return v7
+; nextln: }
+
+function %band_ushr_ushr_same_count_i32(i32, i32, i8) -> i32 {
+block0(v0: i32, v1: i32, v2: i8):
+ v3 = ushr v0, v2
+ v4 = ushr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; check: function %band_ushr_ushr_same_count_i32(i32, i32, i8) -> i32 fast {
+; nextln: block0(v0: i32, v1: i32, v2: i8):
+; nextln: v6 = band v0, v1
+; nextln: v7 = ushr v6, v2
+; nextln: return v7
+; nextln: }
+
+function %band_sshr_ushr_same_count_i32(i32, i32, i8) -> i32 {
+block0(v0: i32, v1: i32, v2: i8):
+ v3 = sshr v0, v2
+ v4 = ushr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; check: function %band_sshr_ushr_same_count_i32(i32, i32, i8) -> i32 fast {
+; nextln: block0(v0: i32, v1: i32, v2: i8):
+; nextln: v6 = band v0, v1
+; nextln: v7 = ushr v6, v2
+; nextln: return v7
+; nextln: }
+
+function %band_ushr_sshr_same_count_i32(i32, i32, i8) -> i32 {
+block0(v0: i32, v1: i32, v2: i8):
+ v3 = ushr v0, v2
+ v4 = sshr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; check: function %band_ushr_sshr_same_count_i32(i32, i32, i8) -> i32 fast {
+; nextln: block0(v0: i32, v1: i32, v2: i8):
+; nextln: v6 = band v0, v1
+; nextln: v7 = ushr v6, v2
+; nextln: return v7
+; nextln: }
+
+function %band_ushr_different_counts_i32(i32, i32, i8, i8) -> i32 {
+block0(v0: i32, v1: i32, v2: i8, v3: i8):
+ v4 = ushr v0, v2
+ v5 = ushr v1, v3
+ v6 = band v4, v5
+ return v6
+}
+
+; check: function %band_ushr_different_counts_i32(i32, i32, i8, i8) -> i32 fast {
+; nextln: block0(v0: i32, v1: i32, v2: i8, v3: i8):
+; nextln: v4 = ushr v0, v2
+; nextln: v5 = ushr v1, v3
+; nextln: v6 = band v4, v5
+; nextln: return v6
+; nextln: }
+
+function %masked_ishl_low_mask_i32(i32, i8) -> i32 {
+block0(v0: i32, v1: i8):
+ v2 = iconst.i32 255
+ v3 = band v0, v2
+ v4 = ishl v3, v1
+ v5 = band v4, v2
+ return v5
+}
+
+; check: function %masked_ishl_low_mask_i32(i32, i8) -> i32 fast {
+; nextln: block0(v0: i32, v1: i8):
+; nextln: v6 = ishl v0, v1
+; nextln: v2 = iconst.i32 255
+; nextln: v7 = band v6, v2 ; v2 = 255
+; nextln: return v7
+; nextln: }
+
+function %masked_ishl_noncontiguous_mask_i32(i32, i8) -> i32 {
+block0(v0: i32, v1: i8):
+ v2 = iconst.i32 5
+ v3 = band v0, v2
+ v4 = ishl v3, v1
+ v5 = band v4, v2
+ return v5
+}
+
+; check: function %masked_ishl_noncontiguous_mask_i32(i32, i8) -> i32 fast {
+; nextln: block0(v0: i32, v1: i8):
+; nextln: v2 = iconst.i32 5
+; nextln: v3 = band v0, v2 ; v2 = 5
+; nextln: v4 = ishl v3, v1
+; nextln: v5 = band v4, v2 ; v2 = 5
+; nextln: return v5
+; nextln: }
+
+
+function %bor_sshr_sshr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 {
+block0(v0: i32x4, v1: i32x4, v2: i32):
+ v3 = sshr v0, v2
+ v4 = sshr v1, v2
+ v5 = bor v3, v4
+ return v5
+}
+
+; check: function %bor_sshr_sshr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 fast {
+; nextln: block0(v0: i32x4, v1: i32x4, v2: i32):
+; nextln: v6 = bor v0, v1
+; nextln: v7 = sshr v6, v2
+; nextln: return v7
+; nextln: }
+
+function %bor_ushr_ushr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 {
+block0(v0: i32x4, v1: i32x4, v2: i32):
+ v3 = ushr v0, v2
+ v4 = ushr v1, v2
+ v5 = bor v3, v4
+ return v5
+}
+
+; check: function %bor_ushr_ushr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 fast {
+; nextln: block0(v0: i32x4, v1: i32x4, v2: i32):
+; nextln: v6 = bor v0, v1
+; nextln: v7 = ushr v6, v2
+; nextln: return v7
+; nextln: }
+
+function %band_sshr_sshr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 {
+block0(v0: i32x4, v1: i32x4, v2: i32):
+ v3 = sshr v0, v2
+ v4 = sshr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; check: function %band_sshr_sshr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 fast {
+; nextln: block0(v0: i32x4, v1: i32x4, v2: i32):
+; nextln: v6 = band v0, v1
+; nextln: v7 = sshr v6, v2
+; nextln: return v7
+; nextln: }
+
+function %band_ushr_ushr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 {
+block0(v0: i32x4, v1: i32x4, v2: i32):
+ v3 = ushr v0, v2
+ v4 = ushr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; check: function %band_ushr_ushr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 fast {
+; nextln: block0(v0: i32x4, v1: i32x4, v2: i32):
+; nextln: v6 = band v0, v1
+; nextln: v7 = ushr v6, v2
+; nextln: return v7
+; nextln: }
+
+function %band_sshr_ushr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 {
+block0(v0: i32x4, v1: i32x4, v2: i32):
+ v3 = sshr v0, v2
+ v4 = ushr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; check: function %band_sshr_ushr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 fast {
+; nextln: block0(v0: i32x4, v1: i32x4, v2: i32):
+; nextln: v6 = band v0, v1
+; nextln: v7 = ushr v6, v2
+; nextln: return v7
+; nextln: }
+
+function %band_ushr_sshr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 {
+block0(v0: i32x4, v1: i32x4, v2: i32):
+ v3 = ushr v0, v2
+ v4 = sshr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; check: function %band_ushr_sshr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 fast {
+; nextln: block0(v0: i32x4, v1: i32x4, v2: i32):
+; nextln: v6 = band v0, v1
+; nextln: v7 = ushr v6, v2
+; nextln: return v7
+; nextln: }
diff --git a/cranelift/filetests/filetests/runtests/extend.clif b/cranelift/filetests/filetests/runtests/extend.clif
index c186af4f84..b9c4126e05 100644
--- a/cranelift/filetests/filetests/runtests/extend.clif
+++ b/cranelift/filetests/filetests/runtests/extend.clif
@@ -551,3 +551,377 @@ block0(v0: i8, v1: i8):
; run: %eq_mixed_sign_and_zero_extend(0, 0) == 1
; run: %eq_mixed_sign_and_zero_extend(127, 127) == 1
; run: %eq_mixed_sign_and_zero_extend(-128, -128) == 0
+
+function %ne_sextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp ne v2, v3
+ return v4
+}
+
+; run: %ne_sextend_i8_i64(0, 0) == 0
+; run: %ne_sextend_i8_i64(0, 1) == 1
+; run: %ne_sextend_i8_i64(1, 0) == 1
+; run: %ne_sextend_i8_i64(-1, 0) == 1
+; run: %ne_sextend_i8_i64(0, -1) == 1
+; run: %ne_sextend_i8_i64(-1, -1) == 0
+; run: %ne_sextend_i8_i64(-128, 127) == 1
+; run: %ne_sextend_i8_i64(127, -128) == 1
+
+function %ne_uextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp ne v2, v3
+ return v4
+}
+
+; run: %ne_uextend_i8_i64(0, 0) == 0
+; run: %ne_uextend_i8_i64(0, 1) == 1
+; run: %ne_uextend_i8_i64(1, 0) == 1
+; run: %ne_uextend_i8_i64(-1, 0) == 1
+; run: %ne_uextend_i8_i64(0, -1) == 1
+; run: %ne_uextend_i8_i64(-1, -1) == 0
+; run: %ne_uextend_i8_i64(-128, 127) == 1
+; run: %ne_uextend_i8_i64(127, -128) == 1
+
+function %sge_sextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp sge v2, v3
+ return v4
+}
+
+; run: %sge_sextend_i8_i64(0, 0) == 1
+; run: %sge_sextend_i8_i64(0, 1) == 0
+; run: %sge_sextend_i8_i64(1, 0) == 1
+; run: %sge_sextend_i8_i64(-1, 0) == 0
+; run: %sge_sextend_i8_i64(0, -1) == 1
+; run: %sge_sextend_i8_i64(-1, -1) == 1
+; run: %sge_sextend_i8_i64(-128, 127) == 0
+; run: %sge_sextend_i8_i64(127, -128) == 1
+
+function %sle_sextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp sle v2, v3
+ return v4
+}
+
+; run: %sle_sextend_i8_i64(0, 0) == 1
+; run: %sle_sextend_i8_i64(0, 1) == 1
+; run: %sle_sextend_i8_i64(1, 0) == 0
+; run: %sle_sextend_i8_i64(-1, 0) == 1
+; run: %sle_sextend_i8_i64(0, -1) == 0
+; run: %sle_sextend_i8_i64(-1, -1) == 1
+; run: %sle_sextend_i8_i64(-128, 127) == 1
+; run: %sle_sextend_i8_i64(127, -128) == 0
+
+function %sge_uextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp sge v2, v3
+ return v4
+}
+
+; run: %sge_uextend_i8_i64(0, 0) == 1
+; run: %sge_uextend_i8_i64(0, 1) == 0
+; run: %sge_uextend_i8_i64(1, 0) == 1
+; run: %sge_uextend_i8_i64(-1, 0) == 1
+; run: %sge_uextend_i8_i64(0, -1) == 0
+; run: %sge_uextend_i8_i64(-1, -1) == 1
+; run: %sge_uextend_i8_i64(-128, 127) == 1
+; run: %sge_uextend_i8_i64(127, -128) == 0
+
+function %sgt_uextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp sgt v2, v3
+ return v4
+}
+
+; run: %sgt_uextend_i8_i64(0, 0) == 0
+; run: %sgt_uextend_i8_i64(0, 1) == 0
+; run: %sgt_uextend_i8_i64(1, 0) == 1
+; run: %sgt_uextend_i8_i64(-1, 0) == 1
+; run: %sgt_uextend_i8_i64(0, -1) == 0
+; run: %sgt_uextend_i8_i64(-1, -1) == 0
+; run: %sgt_uextend_i8_i64(-128, 127) == 1
+; run: %sgt_uextend_i8_i64(127, -128) == 0
+
+function %sle_uextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp sle v2, v3
+ return v4
+}
+
+; run: %sle_uextend_i8_i64(0, 0) == 1
+; run: %sle_uextend_i8_i64(0, 1) == 1
+; run: %sle_uextend_i8_i64(1, 0) == 0
+; run: %sle_uextend_i8_i64(-1, 0) == 0
+; run: %sle_uextend_i8_i64(0, -1) == 1
+; run: %sle_uextend_i8_i64(-1, -1) == 1
+; run: %sle_uextend_i8_i64(-128, 127) == 0
+; run: %sle_uextend_i8_i64(127, -128) == 1
+
+function %slt_uextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp slt v2, v3
+ return v4
+}
+
+; run: %slt_uextend_i8_i64(0, 0) == 0
+; run: %slt_uextend_i8_i64(0, 1) == 1
+; run: %slt_uextend_i8_i64(1, 0) == 0
+; run: %slt_uextend_i8_i64(-1, 0) == 0
+; run: %slt_uextend_i8_i64(0, -1) == 1
+; run: %slt_uextend_i8_i64(-1, -1) == 0
+; run: %slt_uextend_i8_i64(-128, 127) == 0
+; run: %slt_uextend_i8_i64(127, -128) == 1
+
+function %uge_sextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp uge v2, v3
+ return v4
+}
+
+; run: %uge_sextend_i8_i64(0, 0) == 1
+; run: %uge_sextend_i8_i64(0, 1) == 0
+; run: %uge_sextend_i8_i64(1, 0) == 1
+; run: %uge_sextend_i8_i64(-1, 0) == 1
+; run: %uge_sextend_i8_i64(0, -1) == 0
+; run: %uge_sextend_i8_i64(-1, -1) == 1
+; run: %uge_sextend_i8_i64(-128, 127) == 1
+; run: %uge_sextend_i8_i64(127, -128) == 0
+
+function %ugt_sextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp ugt v2, v3
+ return v4
+}
+
+; run: %ugt_sextend_i8_i64(0, 0) == 0
+; run: %ugt_sextend_i8_i64(0, 1) == 0
+; run: %ugt_sextend_i8_i64(1, 0) == 1
+; run: %ugt_sextend_i8_i64(-1, 0) == 1
+; run: %ugt_sextend_i8_i64(0, -1) == 0
+; run: %ugt_sextend_i8_i64(-1, -1) == 0
+; run: %ugt_sextend_i8_i64(-128, 127) == 1
+; run: %ugt_sextend_i8_i64(127, -128) == 0
+
+function %ule_sextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp ule v2, v3
+ return v4
+}
+
+; run: %ule_sextend_i8_i64(0, 0) == 1
+; run: %ule_sextend_i8_i64(0, 1) == 1
+; run: %ule_sextend_i8_i64(1, 0) == 0
+; run: %ule_sextend_i8_i64(-1, 0) == 0
+; run: %ule_sextend_i8_i64(0, -1) == 1
+; run: %ule_sextend_i8_i64(-1, -1) == 1
+; run: %ule_sextend_i8_i64(-128, 127) == 0
+; run: %ule_sextend_i8_i64(127, -128) == 1
+
+function %ult_sextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp ult v2, v3
+ return v4
+}
+
+; run: %ult_sextend_i8_i64(0, 0) == 0
+; run: %ult_sextend_i8_i64(0, 1) == 1
+; run: %ult_sextend_i8_i64(1, 0) == 0
+; run: %ult_sextend_i8_i64(-1, 0) == 0
+; run: %ult_sextend_i8_i64(0, -1) == 1
+; run: %ult_sextend_i8_i64(-1, -1) == 0
+; run: %ult_sextend_i8_i64(-128, 127) == 0
+; run: %ult_sextend_i8_i64(127, -128) == 1
+
+function %uge_uextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp uge v2, v3
+ return v4
+}
+
+; run: %uge_uextend_i8_i64(0, 0) == 1
+; run: %uge_uextend_i8_i64(0, 1) == 0
+; run: %uge_uextend_i8_i64(1, 0) == 1
+; run: %uge_uextend_i8_i64(-1, 0) == 1
+; run: %uge_uextend_i8_i64(0, -1) == 0
+; run: %uge_uextend_i8_i64(-1, -1) == 1
+; run: %uge_uextend_i8_i64(-128, 127) == 1
+; run: %uge_uextend_i8_i64(127, -128) == 0
+
+function %ule_uextend_i8_i64(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp ule v2, v3
+ return v4
+}
+
+; run: %ule_uextend_i8_i64(0, 0) == 1
+; run: %ule_uextend_i8_i64(0, 1) == 1
+; run: %ule_uextend_i8_i64(1, 0) == 0
+; run: %ule_uextend_i8_i64(-1, 0) == 0
+; run: %ule_uextend_i8_i64(0, -1) == 1
+; run: %ule_uextend_i8_i64(-1, -1) == 1
+; run: %ule_uextend_i8_i64(-128, 127) == 0
+; run: %ule_uextend_i8_i64(127, -128) == 1
+
+function %sge_uextend_i8_i16(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i16 v0
+ v3 = uextend.i16 v1
+ v4 = icmp sge v2, v3
+ return v4
+}
+
+; run: %sge_uextend_i8_i16(0, 0) == 1
+; run: %sge_uextend_i8_i16(0, 1) == 0
+; run: %sge_uextend_i8_i16(1, 0) == 1
+; run: %sge_uextend_i8_i16(-1, 0) == 1
+; run: %sge_uextend_i8_i16(0, -1) == 0
+; run: %sge_uextend_i8_i16(-1, -1) == 1
+; run: %sge_uextend_i8_i16(-128, 127) == 1
+; run: %sge_uextend_i8_i16(127, -128) == 0
+
+function %sgt_uextend_i8_i16(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i16 v0
+ v3 = uextend.i16 v1
+ v4 = icmp sgt v2, v3
+ return v4
+}
+
+; run: %sgt_uextend_i8_i16(0, 0) == 0
+; run: %sgt_uextend_i8_i16(0, 1) == 0
+; run: %sgt_uextend_i8_i16(1, 0) == 1
+; run: %sgt_uextend_i8_i16(-1, 0) == 1
+; run: %sgt_uextend_i8_i16(0, -1) == 0
+; run: %sgt_uextend_i8_i16(-1, -1) == 0
+; run: %sgt_uextend_i8_i16(-128, 127) == 1
+; run: %sgt_uextend_i8_i16(127, -128) == 0
+
+function %sle_uextend_i8_i16(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i16 v0
+ v3 = uextend.i16 v1
+ v4 = icmp sle v2, v3
+ return v4
+}
+
+; run: %sle_uextend_i8_i16(0, 0) == 1
+; run: %sle_uextend_i8_i16(0, 1) == 1
+; run: %sle_uextend_i8_i16(1, 0) == 0
+; run: %sle_uextend_i8_i16(-1, 0) == 0
+; run: %sle_uextend_i8_i16(0, -1) == 1
+; run: %sle_uextend_i8_i16(-1, -1) == 1
+; run: %sle_uextend_i8_i16(-128, 127) == 0
+; run: %sle_uextend_i8_i16(127, -128) == 1
+
+function %slt_uextend_i8_i16(i8, i8) -> i8 {
+block0(v0: i8, v1: i8):
+ v2 = uextend.i16 v0
+ v3 = uextend.i16 v1
+ v4 = icmp slt v2, v3
+ return v4
+}
+
+; run: %slt_uextend_i8_i16(0, 0) == 0
+; run: %slt_uextend_i8_i16(0, 1) == 1
+; run: %slt_uextend_i8_i16(1, 0) == 0
+; run: %slt_uextend_i8_i16(-1, 0) == 0
+; run: %slt_uextend_i8_i16(0, -1) == 1
+; run: %slt_uextend_i8_i16(-1, -1) == 0
+; run: %slt_uextend_i8_i16(-128, 127) == 0
+; run: %slt_uextend_i8_i16(127, -128) == 1
+
+function %sge_sextend_i8_i64_different_input_types(i8, i16) -> i8 {
+block0(v0: i8, v1: i16):
+ v2 = sextend.i64 v0
+ v3 = sextend.i64 v1
+ v4 = icmp sge v2, v3
+ return v4
+}
+
+; run: %sge_sextend_i8_i64_different_input_types(0, 0) == 1
+; run: %sge_sextend_i8_i64_different_input_types(0, 1) == 0
+; run: %sge_sextend_i8_i64_different_input_types(1, 0) == 1
+; run: %sge_sextend_i8_i64_different_input_types(-1, 0) == 0
+; run: %sge_sextend_i8_i64_different_input_types(0, -1) == 1
+; run: %sge_sextend_i8_i64_different_input_types(-1, -1) == 1
+; run: %sge_sextend_i8_i64_different_input_types(-128, 32767) == 0
+; run: %sge_sextend_i8_i64_different_input_types(127, -32768) == 1
+
+function %uge_uextend_i8_i64_different_input_types(i8, i16) -> i8 {
+block0(v0: i8, v1: i16):
+ v2 = uextend.i64 v0
+ v3 = uextend.i64 v1
+ v4 = icmp uge v2, v3
+ return v4
+}
+
+; run: %uge_uextend_i8_i64_different_input_types(0, 0) == 1
+; run: %uge_uextend_i8_i64_different_input_types(0, 1) == 0
+; run: %uge_uextend_i8_i64_different_input_types(1, 0) == 1
+; run: %uge_uextend_i8_i64_different_input_types(-1, 0) == 1
+; run: %uge_uextend_i8_i64_different_input_types(0, -1) == 0
+; run: %uge_uextend_i8_i64_different_input_types(-1, -1) == 0
+; run: %uge_uextend_i8_i64_different_input_types(-128, 32767) == 0
+; run: %uge_uextend_i8_i64_different_input_types(127, -32768) == 0
+
+function %uge_sextend_i64_i128(i64, i64) -> i8 {
+block0(v0: i64, v1: i64):
+ v2 = sextend.i128 v0
+ v3 = sextend.i128 v1
+ v4 = icmp uge v2, v3
+ return v4
+}
+
+; run: %uge_sextend_i64_i128(0, 0) == 1
+; run: %uge_sextend_i64_i128(0, 1) == 0
+; run: %uge_sextend_i64_i128(1, 0) == 1
+; run: %uge_sextend_i64_i128(-1, 0) == 1
+; run: %uge_sextend_i64_i128(0, -1) == 0
+; run: %uge_sextend_i64_i128(-1, -1) == 1
+; run: %uge_sextend_i64_i128(-9223372036854775808, 0x7fffffffffffffff) == 1
+; run: %uge_sextend_i64_i128(0x7fffffffffffffff, -9223372036854775808) == 0
+
+function %sgt_uextend_i64_i128(i64, i64) -> i8 {
+block0(v0: i64, v1: i64):
+ v2 = uextend.i128 v0
+ v3 = uextend.i128 v1
+ v4 = icmp sgt v2, v3
+ return v4
+}
+
+; run: %sgt_uextend_i64_i128(0, 0) == 0
+; run: %sgt_uextend_i64_i128(0, 1) == 0
+; run: %sgt_uextend_i64_i128(1, 0) == 1
+; run: %sgt_uextend_i64_i128(-1, 0) == 1
+; run: %sgt_uextend_i64_i128(0, -1) == 0
+; run: %sgt_uextend_i64_i128(-1, -1) == 0
+; run: %sgt_uextend_i64_i128(-9223372036854775808, 0x7fffffffffffffff) == 1
+; run: %sgt_uextend_i64_i128(0x7fffffffffffffff, -9223372036854775808) == 0
diff --git a/cranelift/filetests/filetests/runtests/fold-bitops.clif b/cranelift/filetests/filetests/runtests/fold-bitops.clif
index 2fb246b9a5..25981ccfda 100644
--- a/cranelift/filetests/filetests/runtests/fold-bitops.clif
+++ b/cranelift/filetests/filetests/runtests/fold-bitops.clif
@@ -392,3 +392,132 @@ block0(v0: i64, v1: i64):
}
; run: %not_sub_not_i64(9223372036854775807, 1) == -9223372036854775808
; run: %not_sub_not_i64(-9223372036854775808, -1) == 9223372036854775807
+
+function %band_bnot_bor_xy_i32(i32, i32) -> i32 {
+block0(v0: i32, v1: i32):
+ v2 = bnot v0
+ v3 = bor v0, v1
+ v4 = band v2, v3
+ return v4
+}
+
+; run: %band_bnot_bor_xy_i32(0, 0) == 0
+; run: %band_bnot_bor_xy_i32(-1, 0) == 0
+; run: %band_bnot_bor_xy_i32(0, -1) == -1
+; run: %band_bnot_bor_xy_i32(-1, -1) == 0
+; run: %band_bnot_bor_xy_i32(-2147483648, 2147483647) == 2147483647
+; run: %band_bnot_bor_xy_i32(1431655765, 0xaaaaaaaa) == -1431655766
+; run: %band_bnot_bor_xy_i32(240, 204) == 12
+
+function %band_bnot_bor_yx_i32(i32, i32) -> i32 {
+block0(v0: i32, v1: i32):
+ v2 = bnot v0
+ v3 = bor v1, v0
+ v4 = band v2, v3
+ return v4
+}
+
+; run: %band_bnot_bor_yx_i32(0, 0) == 0
+; run: %band_bnot_bor_yx_i32(-1, 0) == 0
+; run: %band_bnot_bor_yx_i32(0, -1) == -1
+; run: %band_bnot_bor_yx_i32(-1, -1) == 0
+; run: %band_bnot_bor_yx_i32(-2147483648, 2147483647) == 2147483647
+; run: %band_bnot_bor_yx_i32(1431655765, 0xaaaaaaaa) == -1431655766
+; run: %band_bnot_bor_yx_i32(240, 204) == 12
+
+function %band_bor_bnot_x_i32(i32, i32) -> i32 {
+block0(v0: i32, v1: i32):
+ v2 = bor v0, v1
+ v3 = bnot v0
+ v4 = band v2, v3
+ return v4
+}
+
+; run: %band_bor_bnot_x_i32(0, 0) == 0
+; run: %band_bor_bnot_x_i32(-1, 0) == 0
+; run: %band_bor_bnot_x_i32(0, -1) == -1
+; run: %band_bor_bnot_x_i32(-1, -1) == 0
+; run: %band_bor_bnot_x_i32(-2147483648, 2147483647) == 2147483647
+; run: %band_bor_bnot_x_i32(1431655765, 0xaaaaaaaa) == -1431655766
+; run: %band_bor_bnot_x_i32(240, 204) == 12
+
+function %band_bor_bnot_y_i32(i32, i32) -> i32 {
+block0(v0: i32, v1: i32):
+ v2 = bor v0, v1
+ v3 = bnot v1
+ v4 = band v2, v3
+ return v4
+}
+
+; run: %band_bor_bnot_y_i32(0, 0) == 0
+; run: %band_bor_bnot_y_i32(-1, 0) == -1
+; run: %band_bor_bnot_y_i32(0, -1) == 0
+; run: %band_bor_bnot_y_i32(-1, -1) == 0
+; run: %band_bor_bnot_y_i32(-2147483648, 2147483647) == -2147483648
+; run: %band_bor_bnot_y_i32(1431655765, 0xaaaaaaaa) == 1431655765
+; run: %band_bor_bnot_y_i32(240, 204) == 48
+
+function %bnot_xor_constant_i64(i64) -> i64 {
+block0(v0: i64):
+ v1 = bnot v0
+ v2 = iconst.i64 85
+ v3 = bxor v1, v2
+ return v3
+}
+
+; run: %bnot_xor_constant_i64(0) == -86
+; run: %bnot_xor_constant_i64(1) == -85
+; run: %bnot_xor_constant_i64(-1) == 85
+; run: %bnot_xor_constant_i64(-9223372036854775808) == 0x7fffffffffffffaa
+; run: %bnot_xor_constant_i64(0x7fffffffffffffff) == -9223372036854775723
+; run: %bnot_xor_constant_i64(85) == -1
+; run: %bnot_xor_constant_i64(-86) == 0
+
+function %bnot_xor_constant_i8(i8) -> i8 {
+block0(v0: i8):
+ v1 = bnot v0
+ v2 = iconst.i8 85
+ v3 = bxor v1, v2
+ return v3
+}
+
+; run: %bnot_xor_constant_i8(0) == -86
+; run: %bnot_xor_constant_i8(1) == -85
+; run: %bnot_xor_constant_i8(-1) == 85
+; run: %bnot_xor_constant_i8(-128) == 42
+; run: %bnot_xor_constant_i8(127) == -43
+; run: %bnot_xor_constant_i8(85) == -1
+; run: %bnot_xor_constant_i8(-86) == 0
+
+function %band_bnot_band_bor_to_xor_i32(i32, i32) -> i32 {
+block0(v0: i32, v1: i32):
+ v2 = band v0, v1
+ v3 = bnot v2
+ v4 = bor v0, v1
+ v5 = band v3, v4
+ return v5
+}
+
+; run: %band_bnot_band_bor_to_xor_i32(0, 0) == 0
+; run: %band_bnot_band_bor_to_xor_i32(-1, 0) == -1
+; run: %band_bnot_band_bor_to_xor_i32(0, -1) == -1
+; run: %band_bnot_band_bor_to_xor_i32(-1, -1) == 0
+; run: %band_bnot_band_bor_to_xor_i32(-2147483648, 2147483647) == -1
+; run: %band_bnot_band_bor_to_xor_i32(1431655765, 0xaaaaaaaa) == -1
+; run: %band_bnot_band_bor_to_xor_i32(240, 204) == 60
+
+function %bor_bnot_band_absorb_i32(i32, i32) -> i32 {
+block0(v0: i32, v1: i32):
+ v2 = band v0, v1
+ v3 = bnot v2
+ v4 = bor v3, v0
+ return v4
+}
+
+; run: %bor_bnot_band_absorb_i32(0, 0) == -1
+; run: %bor_bnot_band_absorb_i32(-1, 0) == -1
+; run: %bor_bnot_band_absorb_i32(0, -1) == -1
+; run: %bor_bnot_band_absorb_i32(-1, -1) == -1
+; run: %bor_bnot_band_absorb_i32(-2147483648, 2147483647) == -1
+; run: %bor_bnot_band_absorb_i32(1431655765, 0xaaaaaaaa) == -1
+; run: %bor_bnot_band_absorb_i32(240, 204) == -1
diff --git a/cranelift/filetests/filetests/runtests/i128-bitops.clif b/cranelift/filetests/filetests/runtests/i128-bitops.clif
index 06340db1df..430aa9c99f 100644
--- a/cranelift/filetests/filetests/runtests/i128-bitops.clif
+++ b/cranelift/filetests/filetests/runtests/i128-bitops.clif
@@ -8,6 +8,16 @@ set enable_multi_ret_implicit_sret
target s390x
+set opt_level=speed
+set enable_multi_ret_implicit_sret=false
+set enable_llvm_abi_extensions=true
+target aarch64
+target x86_64
+target riscv64
+target riscv64 has_c has_zcb
+set enable_multi_ret_implicit_sret
+target s390x
+
function %bnot_i128(i128) -> i128 {
block0(v0: i128):
v1 = bnot v0
@@ -57,3 +67,31 @@ block0(v0: i128, v1: i128):
; run: %bxor_i128(-1, 0xFFFFFFFF_FFFFFFFF_00000000_00000000) == 0x00000000_00000000_FFFFFFFF_FFFFFFFF
; run: %bxor_i128(0xFEDCBA98_76543210_01234567_89ABCDEF, 0x01234567_89ABCDEF_FEDCBA98_76543210) == -1
; run: %bxor_i128(0x9440A07D_9440A07D_8FA50A64_8FA50A64, 0x4A8A5F82_4A8A5F82_4F5AE48A_4F5AE48A) == 0xDECAFFFF_DECAFFFF_C0FFEEEE_C0FFEEEE
+
+function %bor_bnot_band_absorb_i128(i128, i128) -> i128 {
+block0(v0: i128, v1: i128):
+ v2 = band v0, v1
+ v3 = bnot v2
+ v4 = bor v3, v0
+ return v4
+}
+
+; run: %bor_bnot_band_absorb_i128(0, 0) == -1
+; run: %bor_bnot_band_absorb_i128(-1, 0) == -1
+; run: %bor_bnot_band_absorb_i128(0, -1) == -1
+; run: %bor_bnot_band_absorb_i128(-1, -1) == -1
+; run: %bor_bnot_band_absorb_i128(0x80000000000000000000000000000000, 0x7fffffffffffffffffffffffffffffff) == -1
+
+function %bnot_xor_constant_i128_guard(i128) -> i128 {
+block0(v0: i128):
+ v1 = bnot v0
+ v2 = iconst.i64 85
+ v3 = uextend.i128 v2
+ v4 = bxor v1, v3
+ return v4
+}
+
+; run: %bnot_xor_constant_i128_guard(0) == -86
+; run: %bnot_xor_constant_i128_guard(-1) == 85
+; run: %bnot_xor_constant_i128_guard(0x80000000000000000000000000000000) == 0x7fffffffffffffffffffffffffffffaa
+; run: %bnot_xor_constant_i128_guard(0x7fffffffffffffffffffffffffffffff) == -170141183460469231731687303715884105643
diff --git a/cranelift/filetests/filetests/runtests/icmp.clif b/cranelift/filetests/filetests/runtests/icmp.clif
index b20f8213e5..df09e489ad 100644
--- a/cranelift/filetests/filetests/runtests/icmp.clif
+++ b/cranelift/filetests/filetests/runtests/icmp.clif
@@ -527,3 +527,39 @@ block0(v0: i32, v1: i32, v2: i32):
; run: %eq_rotr_shared(1, 1, 1) == [1, -2147483648]
; run: %eq_rotr_shared(1, 2, 1) == [0, -2147483648]
; run: %eq_rotr_shared(7, 7, 32) == [1, 7]
+
+function %bor_ne_zero_i32(i32, i32) -> i8 {
+block0(v0: i32, v1: i32):
+ v2 = iconst.i32 0
+ v3 = icmp ne v0, v2
+ v4 = icmp ne v1, v2
+ v5 = bor v3, v4
+ return v5
+}
+
+; run: %bor_ne_zero_i32(0, 0) == 0
+; run: %bor_ne_zero_i32(0, 1) == 1
+; run: %bor_ne_zero_i32(1, 0) == 1
+; run: %bor_ne_zero_i32(-1, 0) == 1
+; run: %bor_ne_zero_i32(0, -1) == 1
+; run: %bor_ne_zero_i32(-1, -1) == 1
+; run: %bor_ne_zero_i32(-2147483648, 2147483647) == 1
+; run: %bor_ne_zero_i32(1431655765, 0xaaaaaaaa) == 1
+
+function %band_eq_zero_i32(i32, i32) -> i8 {
+block0(v0: i32, v1: i32):
+ v2 = iconst.i32 0
+ v3 = icmp eq v0, v2
+ v4 = icmp eq v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; run: %band_eq_zero_i32(0, 0) == 1
+; run: %band_eq_zero_i32(0, 1) == 0
+; run: %band_eq_zero_i32(1, 0) == 0
+; run: %band_eq_zero_i32(-1, 0) == 0
+; run: %band_eq_zero_i32(0, -1) == 0
+; run: %band_eq_zero_i32(-1, -1) == 0
+; run: %band_eq_zero_i32(-2147483648, 2147483647) == 0
+; run: %band_eq_zero_i32(1431655765, 0xaaaaaaaa) == 0
diff --git a/cranelift/filetests/filetests/runtests/select.clif b/cranelift/filetests/filetests/runtests/select.clif
index 97f6a52f92..0c5af919a7 100644
--- a/cranelift/filetests/filetests/runtests/select.clif
+++ b/cranelift/filetests/filetests/runtests/select.clif
@@ -1290,3 +1290,144 @@ block0(v0: i32, v1: i32):
; run: %select_nonzero_count_ishl(7, 0) == 7
; run: %select_nonzero_count_ishl(7, 1) == 7
; run: %select_nonzero_count_ishl(7, 2) == 28
+
+function %bor_select_constants_right_i64(i8) -> i64 {
+block0(v0: i8):
+ v1 = iconst.i64 17
+ v2 = iconst.i64 33
+ v3 = select v0, v1, v2
+ v4 = iconst.i64 5
+ v5 = bor v3, v4
+ return v5
+}
+
+; run: %bor_select_constants_right_i64(0) == 37
+; run: %bor_select_constants_right_i64(1) == 21
+; run: %bor_select_constants_right_i64(2) == 21
+; run: %bor_select_constants_right_i64(-1) == 21
+; run: %bor_select_constants_right_i64(-128) == 21
+
+function %bor_select_constants_left_i64(i8) -> i64 {
+block0(v0: i8):
+ v1 = iconst.i64 17
+ v2 = iconst.i64 33
+ v3 = select v0, v1, v2
+ v4 = iconst.i64 5
+ v5 = bor v4, v3
+ return v5
+}
+
+; run: %bor_select_constants_left_i64(0) == 37
+; run: %bor_select_constants_left_i64(1) == 21
+; run: %bor_select_constants_left_i64(2) == 21
+; run: %bor_select_constants_left_i64(-1) == 21
+; run: %bor_select_constants_left_i64(-128) == 21
+
+function %bxor_select_constants_right_i64(i8) -> i64 {
+block0(v0: i8):
+ v1 = iconst.i64 17
+ v2 = iconst.i64 33
+ v3 = select v0, v1, v2
+ v4 = iconst.i64 5
+ v5 = bxor v3, v4
+ return v5
+}
+
+; run: %bxor_select_constants_right_i64(0) == 36
+; run: %bxor_select_constants_right_i64(1) == 20
+; run: %bxor_select_constants_right_i64(2) == 20
+; run: %bxor_select_constants_right_i64(-1) == 20
+; run: %bxor_select_constants_right_i64(-128) == 20
+
+function %bxor_select_constants_left_i64(i8) -> i64 {
+block0(v0: i8):
+ v1 = iconst.i64 17
+ v2 = iconst.i64 33
+ v3 = select v0, v1, v2
+ v4 = iconst.i64 5
+ v5 = bxor v4, v3
+ return v5
+}
+
+; run: %bxor_select_constants_left_i64(0) == 36
+; run: %bxor_select_constants_left_i64(1) == 20
+; run: %bxor_select_constants_left_i64(2) == 20
+; run: %bxor_select_constants_left_i64(-1) == 20
+; run: %bxor_select_constants_left_i64(-128) == 20
+
+function %isub_select_constants_left_i64(i8) -> i64 {
+block0(v0: i8):
+ v1 = iconst.i64 17
+ v2 = iconst.i64 33
+ v3 = select v0, v1, v2
+ v4 = iconst.i64 85
+ v5 = isub v4, v3
+ return v5
+}
+
+; run: %isub_select_constants_left_i64(0) == 52
+; run: %isub_select_constants_left_i64(1) == 68
+; run: %isub_select_constants_left_i64(2) == 68
+; run: %isub_select_constants_left_i64(-1) == 68
+; run: %isub_select_constants_left_i64(-128) == 68
+
+function %isub_select_constants_right_i64(i8) -> i64 {
+block0(v0: i8):
+ v1 = iconst.i64 17
+ v2 = iconst.i64 33
+ v3 = select v0, v1, v2
+ v4 = iconst.i64 85
+ v5 = isub v3, v4
+ return v5
+}
+
+; run: %isub_select_constants_right_i64(0) == -52
+; run: %isub_select_constants_right_i64(1) == -68
+; run: %isub_select_constants_right_i64(2) == -68
+; run: %isub_select_constants_right_i64(-1) == -68
+; run: %isub_select_constants_right_i64(-128) == -68
+
+function %isub_select_constants_left_i8_wrapping(i8) -> i8 {
+block0(v0: i8):
+ v1 = iconst.i8 127
+ v2 = iconst.i8 -128
+ v3 = select v0, v1, v2
+ v4 = iconst.i8 1
+ v5 = isub v4, v3
+ return v5
+}
+
+; run: %isub_select_constants_left_i8_wrapping(0) == -127
+; run: %isub_select_constants_left_i8_wrapping(1) == -126
+; run: %isub_select_constants_left_i8_wrapping(2) == -126
+; run: %isub_select_constants_left_i8_wrapping(-1) == -126
+
+function %isub_select_constants_right_i8_wrapping(i8) -> i8 {
+block0(v0: i8):
+ v1 = iconst.i8 127
+ v2 = iconst.i8 -128
+ v3 = select v0, v1, v2
+ v4 = iconst.i8 1
+ v5 = isub v3, v4
+ return v5
+}
+
+; run: %isub_select_constants_right_i8_wrapping(0) == 127
+; run: %isub_select_constants_right_i8_wrapping(1) == 126
+; run: %isub_select_constants_right_i8_wrapping(2) == 126
+; run: %isub_select_constants_right_i8_wrapping(-1) == 126
+
+function %bor_select_nonconstant_branch_i64(i8, i64) -> i64 {
+block0(v0: i8, v1: i64):
+ v2 = iconst.i64 17
+ v3 = select v0, v2, v1
+ v4 = iconst.i64 5
+ v5 = bor v3, v4
+ return v5
+}
+
+; run: %bor_select_nonconstant_branch_i64(0, 0) == 5
+; run: %bor_select_nonconstant_branch_i64(0, -1) == -1
+; run: %bor_select_nonconstant_branch_i64(0, 128) == 133
+; run: %bor_select_nonconstant_branch_i64(1, 0) == 21
+; run: %bor_select_nonconstant_branch_i64(-1, 128) == 21
diff --git a/cranelift/filetests/filetests/runtests/shifts.clif b/cranelift/filetests/filetests/runtests/shifts.clif
index d96ed909d9..1674863372 100644
--- a/cranelift/filetests/filetests/runtests/shifts.clif
+++ b/cranelift/filetests/filetests/runtests/shifts.clif
@@ -1302,3 +1302,165 @@ block0(v0: i8):
; run: %select_constant_shift_masked_i8(1) == 12
; run: %select_constant_shift_masked_i8(2) == 12
; run: %select_constant_shift_masked_i8(-1) == 12
+
+function %bor_sshr_sshr_same_count_i32(i32, i32, i8) -> i32 {
+block0(v0: i32, v1: i32, v2: i8):
+ v3 = sshr v0, v2
+ v4 = sshr v1, v2
+ v5 = bor v3, v4
+ return v5
+}
+
+; run: %bor_sshr_sshr_same_count_i32(0, 0, 0) == 0
+; run: %bor_sshr_sshr_same_count_i32(-1, -2147483648, 0) == -1
+; run: %bor_sshr_sshr_same_count_i32(-1, -2147483648, 1) == -1
+; run: %bor_sshr_sshr_same_count_i32(-2147483648, 2147483647, 1) == -1
+; run: %bor_sshr_sshr_same_count_i32(-1, -2147483648, 31) == -1
+; run: %bor_sshr_sshr_same_count_i32(-1, -2147483648, 32) == -1
+; run: %bor_sshr_sshr_same_count_i32(-1, -2147483648, 33) == -1
+; run: %bor_sshr_sshr_same_count_i32(-1, -2147483648, -1) == -1
+; run: %bor_sshr_sshr_same_count_i32(1431655765, 0xaaaaaaaa, 7) == -1
+
+function %bor_ushr_ushr_same_count_i32(i32, i32, i8) -> i32 {
+block0(v0: i32, v1: i32, v2: i8):
+ v3 = ushr v0, v2
+ v4 = ushr v1, v2
+ v5 = bor v3, v4
+ return v5
+}
+
+; run: %bor_ushr_ushr_same_count_i32(0, 0, 0) == 0
+; run: %bor_ushr_ushr_same_count_i32(-1, -2147483648, 0) == -1
+; run: %bor_ushr_ushr_same_count_i32(-1, -2147483648, 1) == 2147483647
+; run: %bor_ushr_ushr_same_count_i32(-2147483648, 2147483647, 1) == 2147483647
+; run: %bor_ushr_ushr_same_count_i32(-1, -2147483648, 31) == 1
+; run: %bor_ushr_ushr_same_count_i32(-1, -2147483648, 32) == -1
+; run: %bor_ushr_ushr_same_count_i32(-1, -2147483648, 33) == 2147483647
+; run: %bor_ushr_ushr_same_count_i32(-1, -2147483648, -1) == 1
+; run: %bor_ushr_ushr_same_count_i32(1431655765, 0xaaaaaaaa, 7) == 33554431
+
+function %band_sshr_sshr_same_count_i32(i32, i32, i8) -> i32 {
+block0(v0: i32, v1: i32, v2: i8):
+ v3 = sshr v0, v2
+ v4 = sshr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; run: %band_sshr_sshr_same_count_i32(0, 0, 0) == 0
+; run: %band_sshr_sshr_same_count_i32(-1, -2147483648, 0) == -2147483648
+; run: %band_sshr_sshr_same_count_i32(-1, -2147483648, 1) == -1073741824
+; run: %band_sshr_sshr_same_count_i32(-2147483648, 2147483647, 1) == 0
+; run: %band_sshr_sshr_same_count_i32(-1, -2147483648, 31) == -1
+; run: %band_sshr_sshr_same_count_i32(-1, -2147483648, 32) == -2147483648
+; run: %band_sshr_sshr_same_count_i32(-1, -2147483648, 33) == -1073741824
+; run: %band_sshr_sshr_same_count_i32(-1, -2147483648, -1) == -1
+; run: %band_sshr_sshr_same_count_i32(1431655765, 0xaaaaaaaa, 7) == 0
+
+function %band_ushr_ushr_same_count_i32(i32, i32, i8) -> i32 {
+block0(v0: i32, v1: i32, v2: i8):
+ v3 = ushr v0, v2
+ v4 = ushr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; run: %band_ushr_ushr_same_count_i32(0, 0, 0) == 0
+; run: %band_ushr_ushr_same_count_i32(-1, -2147483648, 0) == -2147483648
+; run: %band_ushr_ushr_same_count_i32(-1, -2147483648, 1) == 1073741824
+; run: %band_ushr_ushr_same_count_i32(-2147483648, 2147483647, 1) == 0
+; run: %band_ushr_ushr_same_count_i32(-1, -2147483648, 31) == 1
+; run: %band_ushr_ushr_same_count_i32(-1, -2147483648, 32) == -2147483648
+; run: %band_ushr_ushr_same_count_i32(-1, -2147483648, 33) == 1073741824
+; run: %band_ushr_ushr_same_count_i32(-1, -2147483648, -1) == 1
+; run: %band_ushr_ushr_same_count_i32(1431655765, 0xaaaaaaaa, 7) == 0
+
+function %band_sshr_ushr_same_count_i32(i32, i32, i8) -> i32 {
+block0(v0: i32, v1: i32, v2: i8):
+ v3 = sshr v0, v2
+ v4 = ushr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; run: %band_sshr_ushr_same_count_i32(0, 0, 0) == 0
+; run: %band_sshr_ushr_same_count_i32(-1, -2147483648, 0) == -2147483648
+; run: %band_sshr_ushr_same_count_i32(-1, -2147483648, 1) == 1073741824
+; run: %band_sshr_ushr_same_count_i32(-2147483648, 2147483647, 1) == 0
+; run: %band_sshr_ushr_same_count_i32(-1, -2147483648, 31) == 1
+; run: %band_sshr_ushr_same_count_i32(-1, -2147483648, 32) == -2147483648
+; run: %band_sshr_ushr_same_count_i32(-1, -2147483648, 33) == 1073741824
+; run: %band_sshr_ushr_same_count_i32(-1, -2147483648, -1) == 1
+; run: %band_sshr_ushr_same_count_i32(1431655765, 0xaaaaaaaa, 7) == 0
+
+function %band_ushr_sshr_same_count_i32(i32, i32, i8) -> i32 {
+block0(v0: i32, v1: i32, v2: i8):
+ v3 = ushr v0, v2
+ v4 = sshr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; run: %band_ushr_sshr_same_count_i32(0, 0, 0) == 0
+; run: %band_ushr_sshr_same_count_i32(-1, -2147483648, 0) == -2147483648
+; run: %band_ushr_sshr_same_count_i32(-1, -2147483648, 1) == 1073741824
+; run: %band_ushr_sshr_same_count_i32(-2147483648, 2147483647, 1) == 0
+; run: %band_ushr_sshr_same_count_i32(-1, -2147483648, 31) == 1
+; run: %band_ushr_sshr_same_count_i32(-1, -2147483648, 32) == -2147483648
+; run: %band_ushr_sshr_same_count_i32(-1, -2147483648, 33) == 1073741824
+; run: %band_ushr_sshr_same_count_i32(-1, -2147483648, -1) == 1
+; run: %band_ushr_sshr_same_count_i32(1431655765, 0xaaaaaaaa, 7) == 0
+
+function %band_ushr_different_counts_i32(i32, i32, i8, i8) -> i32 {
+block0(v0: i32, v1: i32, v2: i8, v3: i8):
+ v4 = ushr v0, v2
+ v5 = ushr v1, v3
+ v6 = band v4, v5
+ return v6
+}
+
+; run: %band_ushr_different_counts_i32(-1, -2147483648, 1, 2) == 536870912
+; run: %band_ushr_different_counts_i32(-1, -2147483648, 31, 0) == 0
+; run: %band_ushr_different_counts_i32(1431655765, 0xaaaaaaaa, 3, 4) == 178956970
+
+function %masked_ishl_low_mask_i32(i32, i8) -> i32 {
+block0(v0: i32, v1: i8):
+ v2 = iconst.i32 255
+ v3 = band v0, v2
+ v4 = ishl v3, v1
+ v5 = band v4, v2
+ return v5
+}
+
+; run: %masked_ishl_low_mask_i32(0, 0) == 0
+; run: %masked_ishl_low_mask_i32(-1, 0) == 255
+; run: %masked_ishl_low_mask_i32(-1, 1) == 254
+; run: %masked_ishl_low_mask_i32(1, 7) == 128
+; run: %masked_ishl_low_mask_i32(2, 1) == 4
+; run: %masked_ishl_low_mask_i32(2, 2) == 8
+; run: %masked_ishl_low_mask_i32(256, 0) == 0
+; run: %masked_ishl_low_mask_i32(257, 1) == 2
+; run: %masked_ishl_low_mask_i32(-1, 32) == 255
+; run: %masked_ishl_low_mask_i32(-1, 33) == 254
+; run: %masked_ishl_low_mask_i32(-1, -1) == 0
+
+function %masked_ishl_noncontiguous_mask_i32(i32, i8) -> i32 {
+block0(v0: i32, v1: i8):
+ v2 = iconst.i32 5
+ v3 = band v0, v2
+ v4 = ishl v3, v1
+ v5 = band v4, v2
+ return v5
+}
+
+; run: %masked_ishl_noncontiguous_mask_i32(0, 0) == 0
+; run: %masked_ishl_noncontiguous_mask_i32(-1, 0) == 5
+; run: %masked_ishl_noncontiguous_mask_i32(-1, 1) == 0
+; run: %masked_ishl_noncontiguous_mask_i32(1, 7) == 0
+; run: %masked_ishl_noncontiguous_mask_i32(2, 1) == 0
+; run: %masked_ishl_noncontiguous_mask_i32(2, 2) == 0
+; run: %masked_ishl_noncontiguous_mask_i32(256, 0) == 0
+; run: %masked_ishl_noncontiguous_mask_i32(257, 1) == 0
+; run: %masked_ishl_noncontiguous_mask_i32(-1, 32) == 5
+; run: %masked_ishl_noncontiguous_mask_i32(-1, 33) == 0
+; run: %masked_ishl_noncontiguous_mask_i32(-1, -1) == 0
diff --git a/cranelift/filetests/filetests/runtests/simd-band.clif b/cranelift/filetests/filetests/runtests/simd-band.clif
index 87fb65d5ab..09777768c3 100644
--- a/cranelift/filetests/filetests/runtests/simd-band.clif
+++ b/cranelift/filetests/filetests/runtests/simd-band.clif
@@ -69,3 +69,26 @@ block0(v0:f64x2, v1:f64x2):
; run: %band_f64x2(0xFEDCBA98_76543210_01234567_89ABCDEF, 0x01234567_89ABCDEF_FEDCBA98_76543210) == 0x00000000_00000000_00000000_00000000
; run: %band_f64x2(0xFEEEFFFF_FEEEFFFF_F1FFFEFE_F1FFFEFE, 0xDFDBFFFF_DFDBFFFF_CEFFEFEF_CEFFEFEF) == 0xDECAFFFF_DECAFFFF_C0FFEEEE_C0FFEEEE
+
+function %band_bnot_band_bor_to_xor_i32x4(i32x4, i32x4) -> i32x4 {
+block0(v0: i32x4, v1: i32x4):
+ v2 = band v0, v1
+ v3 = bnot v2
+ v4 = bor v0, v1
+ v5 = band v3, v4
+ return v5
+}
+
+; run: %band_bnot_band_bor_to_xor_i32x4([0 -1 -2147483648 1431655765], [0 -1 2147483647 0xaaaaaaaa]) == [0 0 -1 -1]
+; run: %band_bnot_band_bor_to_xor_i32x4([0 1 240 -1], [-1 0 204 0]) == [-1 1 60 -1]
+
+function %bor_bnot_band_absorb_i32x4(i32x4, i32x4) -> i32x4 {
+block0(v0: i32x4, v1: i32x4):
+ v2 = band v0, v1
+ v3 = bnot v2
+ v4 = bor v3, v0
+ return v4
+}
+
+; run: %bor_bnot_band_absorb_i32x4([0 -1 -2147483648 1431655765], [0 -1 2147483647 0xaaaaaaaa]) == [-1 -1 -1 -1]
+; run: %bor_bnot_band_absorb_i32x4([0 1 240 -1], [-1 0 204 0]) == [-1 -1 -1 -1]
diff --git a/cranelift/filetests/filetests/runtests/simd-ushr.clif b/cranelift/filetests/filetests/runtests/simd-ushr.clif
index 60abb64e37..3354782750 100644
--- a/cranelift/filetests/filetests/runtests/simd-ushr.clif
+++ b/cranelift/filetests/filetests/runtests/simd-ushr.clif
@@ -131,3 +131,93 @@ block0(v0: i64x2):
; run: %i64x2_ushr_const([0x1 0xf]) == [0 0]
; run: %i64x2_ushr_const([0x100000000 0]) == [1 0]
; run: %i64x2_ushr_const([-1 -1]) == [0xffffffff 0xffffffff]
+
+function %bor_sshr_sshr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 {
+block0(v0: i32x4, v1: i32x4, v2: i32):
+ v3 = sshr v0, v2
+ v4 = sshr v1, v2
+ v5 = bor v3, v4
+ return v5
+}
+
+; run: %bor_sshr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 0) == [-1 -1 -1 -1]
+; run: %bor_sshr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 1) == [-1 -1 -1 -1]
+; run: %bor_sshr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 31) == [-1 -1 -1 -1]
+; run: %bor_sshr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 32) == [-1 -1 -1 -1]
+; run: %bor_sshr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 33) == [-1 -1 -1 -1]
+; run: %bor_sshr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], -1) == [-1 -1 -1 -1]
+
+function %bor_ushr_ushr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 {
+block0(v0: i32x4, v1: i32x4, v2: i32):
+ v3 = ushr v0, v2
+ v4 = ushr v1, v2
+ v5 = bor v3, v4
+ return v5
+}
+
+; run: %bor_ushr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 0) == [-1 -1 -1 -1]
+; run: %bor_ushr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 1) == [2147483647 2147483647 2147483647 2147483647]
+; run: %bor_ushr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 31) == [1 1 1 1]
+; run: %bor_ushr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 32) == [-1 -1 -1 -1]
+; run: %bor_ushr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 33) == [2147483647 2147483647 2147483647 2147483647]
+; run: %bor_ushr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], -1) == [1 1 1 1]
+
+function %band_sshr_sshr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 {
+block0(v0: i32x4, v1: i32x4, v2: i32):
+ v3 = sshr v0, v2
+ v4 = sshr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; run: %band_sshr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 0) == [-2147483648 0 0 0]
+; run: %band_sshr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 1) == [-1073741824 0 0 0]
+; run: %band_sshr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 31) == [-1 0 0 0]
+; run: %band_sshr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 32) == [-2147483648 0 0 0]
+; run: %band_sshr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 33) == [-1073741824 0 0 0]
+; run: %band_sshr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], -1) == [-1 0 0 0]
+
+function %band_ushr_ushr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 {
+block0(v0: i32x4, v1: i32x4, v2: i32):
+ v3 = ushr v0, v2
+ v4 = ushr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; run: %band_ushr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 0) == [-2147483648 0 0 0]
+; run: %band_ushr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 1) == [1073741824 0 0 0]
+; run: %band_ushr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 31) == [1 0 0 0]
+; run: %band_ushr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 32) == [-2147483648 0 0 0]
+; run: %band_ushr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 33) == [1073741824 0 0 0]
+; run: %band_ushr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], -1) == [1 0 0 0]
+
+function %band_sshr_ushr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 {
+block0(v0: i32x4, v1: i32x4, v2: i32):
+ v3 = sshr v0, v2
+ v4 = ushr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; run: %band_sshr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 0) == [-2147483648 0 0 0]
+; run: %band_sshr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 1) == [1073741824 0 0 0]
+; run: %band_sshr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 31) == [1 0 0 0]
+; run: %band_sshr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 32) == [-2147483648 0 0 0]
+; run: %band_sshr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 33) == [1073741824 0 0 0]
+; run: %band_sshr_ushr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], -1) == [1 0 0 0]
+
+function %band_ushr_sshr_same_count_i32x4(i32x4, i32x4, i32) -> i32x4 {
+block0(v0: i32x4, v1: i32x4, v2: i32):
+ v3 = ushr v0, v2
+ v4 = sshr v1, v2
+ v5 = band v3, v4
+ return v5
+}
+
+; run: %band_ushr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 0) == [-2147483648 0 0 0]
+; run: %band_ushr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 1) == [1073741824 0 0 0]
+; run: %band_ushr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 31) == [1 0 0 0]
+; run: %band_ushr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 32) == [-2147483648 0 0 0]
+; run: %band_ushr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], 33) == [1073741824 0 0 0]
+; run: %band_ushr_sshr_same_count_i32x4([-1 -2147483648 0 1431655765], [-2147483648 2147483647 -1 0xaaaaaaaa], -1) == [1 0 0 0]