|
222 | 222 | (rule (simplify (fcvt_from_sint ty (sextend _ val))) |
223 | 223 | (fcvt_from_sint ty val)) |
224 | 224 |
|
225 | | - |
226 | | -;; or(x, C) + (-C) --> and(x, ~C) |
227 | | -(rule |
228 | | - (simplify (iadd ty |
229 | | - (bor ty x (iconst_s ty n)) |
230 | | - (iconst_s ty m))) |
231 | | - (if-let m (i64_checked_neg n)) |
232 | | - (band ty x (iconst ty (imm64_masked ty (i64_cast_unsigned (i64_not n)))))) |
233 | | - |
234 | | -;; (x + y) - (x | y) --> x & y |
235 | | -(rule (simplify (isub ty (iadd ty x y) (bor ty x y))) (band ty x y)) |
236 | | - |
237 | | -;; x * (1 << y) == x << y |
238 | | -(rule (simplify (imul ty x (ishl ty (iconst_s ty 1) y))) (ishl ty x y)) |
239 | | - |
240 | | -;; (x - y) + x --> x |
241 | | -(rule (simplify (iadd ty (isub ty x y) y)) x) |
242 | | -(rule (simplify (iadd ty y (isub ty x y))) x) |
243 | | - |
244 | | -;; (x + y) - y --> x |
245 | | -(rule (simplify (isub ty (iadd ty x y) x)) y) |
246 | | -(rule (simplify (isub ty (iadd ty x y) y)) x) |
247 | | - |
248 | | -;; (x - y) - x => -y |
249 | | -(rule (simplify (isub ty (isub ty x y) x))(ineg ty y)) |
250 | | - |
251 | | -;; (x * C) (==/!=) D --> x (==/!=) (D / C) when C is odd and divides D |
252 | | -(rule |
253 | | - (simplify (ne ty (iconst_u ty1 x) (imul ty1 y (iconst_u ty1 z)))) |
254 | | - (if-let 0 (u64_checked_rem x z)) |
255 | | - (if-let 1 (u64_rem z 2)) |
256 | | - (ne ty y (iconst ty1 (imm64 (u64_div x z))))) |
257 | | -(rule |
258 | | - (simplify (ne ty (iconst_u ty1 x) (imul ty1 (iconst_u ty1 y) z))) |
259 | | - (if-let 0 (u64_checked_rem x y)) |
260 | | - (if-let 1 (u64_rem y 2)) |
261 | | - (ne ty z (iconst ty1 (imm64 (u64_div x y))))) |
262 | | -(rule |
263 | | - (simplify (ne ty (imul ty1 x (iconst_u ty1 y)) (iconst_u ty1 z))) |
264 | | - (if-let 0 (u64_checked_rem z y)) |
265 | | - (if-let 1 (u64_rem y 2)) |
266 | | - (ne ty x (iconst ty1 (imm64 (u64_div z y))))) |
267 | | -(rule |
268 | | - (simplify (ne ty (imul ty1 (iconst_u ty1 x) y) (iconst_u ty1 z))) |
269 | | - (if-let 0 (u64_checked_rem z x)) |
270 | | - (if-let 1 (u64_rem x 2)) |
271 | | - (ne ty y (iconst ty1 (imm64 (u64_div z x))))) |
272 | | - |
273 | | - |
274 | | -(rule |
275 | | - (simplify (eq ty (iconst_u ty1 x) (imul ty1 y (iconst_u ty1 z)))) |
276 | | - (if-let 0 (u64_checked_rem x z)) |
277 | | - (if-let 1 (u64_rem z 2)) |
278 | | - (eq ty y (iconst ty1 (imm64 (u64_div x z))))) |
279 | | -(rule |
280 | | - (simplify (eq ty (iconst_u ty1 x) (imul ty1 (iconst_u ty1 y) z))) |
281 | | - (if-let 0 (u64_checked_rem x y)) |
282 | | - (if-let 1 (u64_rem y 2)) |
283 | | - (eq ty z (iconst ty1 (imm64 (u64_div x y))))) |
284 | | -(rule |
285 | | - (simplify (eq ty (imul ty1 x (iconst_u ty1 y)) (iconst_u ty1 z))) |
286 | | - (if-let 0 (u64_checked_rem z y)) |
287 | | - (if-let 1 (u64_rem y 2)) |
288 | | - (eq ty x (iconst ty1 (imm64 (u64_div z y))))) |
289 | | -(rule |
290 | | - (simplify (eq ty (imul ty1 (iconst_u ty1 x) y) (iconst_u ty1 z))) |
291 | | - (if-let 0 (u64_checked_rem z x)) |
292 | | - (if-let 1 (u64_rem x 2)) |
293 | | - (eq ty y (iconst ty1 (imm64 (u64_div z x))))) |
294 | | - |
295 | | -;; (x + y) + (-y) ==> x |
296 | | -;; and equivalent operand-order variants. |
297 | | -(rule (simplify (iadd ty (iadd ty x y) (ineg ty y))) x) |
298 | | -(rule (simplify (iadd ty (ineg ty y) (iadd ty x y))) x) |
299 | | -(rule (simplify (iadd ty (iadd ty y x) (ineg ty y))) x) |
300 | | -(rule (simplify (iadd ty (ineg ty y) (iadd ty y x))) x) |
301 | | - |
302 | | -;; (x | y) - (x & y) ==> (x ^ y) |
303 | | -(rule (simplify (isub ty (bor ty x y) (band ty x y))) (bxor ty x y)) |
304 | | -(rule (simplify (isub ty (bor ty x y) (band ty y x))) (bxor ty x y)) |
305 | | -(rule (simplify (isub ty (bor ty y x) (band ty x y))) (bxor ty x y)) |
306 | | -(rule (simplify (isub ty (bor ty y x) (band ty y x))) (bxor ty x y)) |
307 | | - |
308 | | -;; (x + y) - (x & y) ==> (x | y) |
309 | | -(rule (simplify (isub ty (iadd ty x y) (band ty x y))) (bor ty x y)) |
310 | | -(rule (simplify (isub ty (iadd ty x y) (band ty y x))) (bor ty x y)) |
311 | | -(rule (simplify (isub ty (iadd ty y x) (band ty x y))) (bor ty x y)) |
312 | | -(rule (simplify (isub ty (iadd ty y x) (band ty y x))) (bor ty x y)) |
313 | | - |
314 | | -;; (x | y) - (x ^ y) ==> (x & y) |
315 | | -(rule (simplify (isub ty (bor ty x y) (bxor ty x y))) (band ty x y)) |
316 | | -(rule (simplify (isub ty (bor ty x y) (bxor ty y x))) (band ty x y)) |
317 | | -(rule (simplify (isub ty (bor ty y x) (bxor ty x y))) (band ty x y)) |
318 | | -(rule (simplify (isub ty (bor ty y x) (bxor ty y x))) (band ty x y)) |
319 | | - |
320 | | -;; (~x) + x == -1 |
321 | | -;; Keep the generic fold for <=64-bit types, and handle i128 explicitly. |
322 | | -(rule (simplify (iadd (fits_in_64 ty) (bnot ty x) x)) (iconst_s ty -1)) |
323 | | -(rule (simplify (iadd (fits_in_64 ty) x (bnot ty x))) (iconst_s ty -1)) |
324 | | - |
325 | | -(rule (simplify (iadd $I128 (bnot $I128 x) x)) (sextend $I128 (iconst_s $I64 -1))) |
326 | | -(rule (simplify (iadd $I128 x (bnot $I128 x))) (sextend $I128 (iconst_s $I64 -1))) |
0 commit comments