| 
104 | 104 | (rule (simplify (bxor (fits_in_64 (ty_int ty)) x x))  | 
105 | 105 |       (subsume (iconst ty (imm64 0))))  | 
106 | 106 | 
 
  | 
107 |  | -;; x ^ not(x) == not(x) ^ x == -1.  | 
108 |  | -(rule (simplify (bxor $I32 x (bnot $I32 x))) (subsume (iconst $I32 (imm64 0xffff_ffff))))  | 
109 |  | -(rule (simplify (bxor $I32 (bnot $I32 x) x)) (subsume (iconst $I32 (imm64 0xffff_ffff))))  | 
110 |  | -(rule (simplify (bxor $I64 x (bnot $I64 x))) (subsume (iconst $I64 (imm64 0xffff_ffff_ffff_ffff))))  | 
111 |  | -(rule (simplify (bxor $I64 (bnot $I64 x) x)) (subsume (iconst $I64 (imm64 0xffff_ffff_ffff_ffff))))  | 
 | 107 | +;; x ^ not(x) == not(x) ^ x == x | not(x) == not(x) | x == -1.  | 
 | 108 | +;; This identity also holds for non-integer types, vectors, and wider types.  | 
 | 109 | +;; But `iconst` is only valid for integers up to 64 bits wide.  | 
 | 110 | +(rule (simplify (bxor (fits_in_64 (ty_int ty)) x (bnot ty x))) (subsume (iconst ty (imm64 (ty_mask ty)))))  | 
 | 111 | +(rule (simplify (bxor (fits_in_64 (ty_int ty)) (bnot ty x) x)) (subsume (iconst ty (imm64 (ty_mask ty)))))  | 
 | 112 | +(rule (simplify (bor (fits_in_64 (ty_int ty)) x (bnot ty x))) (subsume (iconst ty (imm64 (ty_mask ty)))))  | 
 | 113 | +(rule (simplify (bor (fits_in_64 (ty_int ty)) (bnot ty x) x)) (subsume (iconst ty (imm64 (ty_mask ty)))))  | 
112 | 114 | 
 
  | 
113 | 115 | ;; x & -1 == -1 & x == x & x == x.  | 
114 |  | -(rule (simplify (band ty x x)) x)  | 
115 |  | -(rule (simplify (band $I32 x (iconst $I32 (u64_from_imm64 0xffff_ffff)))) (subsume x))  | 
116 |  | -(rule (simplify (band $I32 (iconst $I32 (u64_from_imm64 0xffff_ffff)) x)) (subsume x))  | 
117 |  | -(rule (simplify (band $I64 x (iconst $I64 (u64_from_imm64 0xffff_ffff_ffff_ffff)))) (subsume x))  | 
118 |  | -(rule (simplify (band $I64 (iconst $I64 (u64_from_imm64 0xffff_ffff_ffff_ffff)) x)) (subsume x))  | 
 | 116 | +(rule (simplify (band ty x x)) (subsume x))  | 
 | 117 | +(rule (simplify (band ty x (iconst ty k)))  | 
 | 118 | +      (if-let -1 (i64_sextend_imm64 ty k))  | 
 | 119 | +      (subsume x))  | 
 | 120 | +(rule (simplify (band ty (iconst ty k) x))  | 
 | 121 | +      (if-let -1 (i64_sextend_imm64 ty k))  | 
 | 122 | +      (subsume x))  | 
119 | 123 | 
 
  | 
120 |  | -;; x & 0 == 0 & x == 0.  | 
 | 124 | +;; x & 0 == 0 & x == x & not(x) == not(x) & x == 0.  | 
121 | 125 | (rule (simplify (band ty _ zero @ (iconst ty (u64_from_imm64 0)))) (subsume zero))  | 
122 | 126 | (rule (simplify (band ty zero @ (iconst ty (u64_from_imm64 0)) _)) (subsume zero))  | 
 | 127 | +(rule (simplify (band (fits_in_64 (ty_int ty)) x (bnot ty x))) (subsume (iconst ty (imm64 0))))  | 
 | 128 | +(rule (simplify (band (fits_in_64 (ty_int ty)) (bnot ty x) x)) (subsume (iconst ty (imm64 0))))  | 
123 | 129 | 
 
  | 
124 | 130 | ;; not(not(x)) == x.  | 
125 | 131 | (rule (simplify (bnot ty (bnot ty x))) (subsume x))  | 
 | 
0 commit comments