|
| 1 | +;; shootout-random fix |
| 2 | +;; There are arithmetic rules that cannot be transplanted by transopt |
| 3 | + |
| 4 | +;; General cases for `udiv` with constant divisors. |
| 5 | +(rule (simplify_skeleton (udiv x (iconst_u $I32 (u64_extract_non_zero (u32_from_u64 d))))) |
| 6 | + (if-let false (u32_is_power_of_two d)) |
| 7 | + (apply_div_const_magic_u32 (Opcode.Udiv) x d)) |
| 8 | +(rule (simplify_skeleton (udiv x (iconst_u $I64 (u64_extract_non_zero d)))) |
| 9 | + (if-let false (u64_is_power_of_two d)) |
| 10 | + (apply_div_const_magic_u64 (Opcode.Udiv) x d)) |
| 11 | + |
| 12 | +;; General cases for `sdiv` with constant divisors. |
| 13 | +(rule (simplify_skeleton (sdiv x (iconst_s $I32 (i64_extract_non_zero (i32_from_i64 d))))) |
| 14 | + (if-let false (i64_is_any_sign_power_of_two d)) |
| 15 | + (apply_div_const_magic_s32 (Opcode.Sdiv) x d)) |
| 16 | +(rule (simplify_skeleton (sdiv x (iconst_s $I64 (i64_extract_non_zero d)))) |
| 17 | + (if-let false (i64_is_any_sign_power_of_two d)) |
| 18 | + (apply_div_const_magic_s64 (Opcode.Sdiv) x d)) |
| 19 | + |
| 20 | +;; General cases for `urem` with constant divisors. |
| 21 | +(rule (simplify_skeleton (urem x (iconst_u $I32 (u64_extract_non_zero (u32_from_u64 d))))) |
| 22 | + (if-let false (u32_is_power_of_two d)) |
| 23 | + (apply_div_const_magic_u32 (Opcode.Urem) x d)) |
| 24 | +(rule (simplify_skeleton (urem x (iconst_u $I64 (u64_extract_non_zero d)))) |
| 25 | + (if-let false (u64_is_power_of_two d)) |
| 26 | + (apply_div_const_magic_u64 (Opcode.Urem) x d)) |
| 27 | + |
| 28 | +;; General cases for `srem` with constant divisors. |
| 29 | +(rule (simplify_skeleton (srem x (iconst_s $I32 (i64_extract_non_zero (i32_from_i64 d))))) |
| 30 | + (if-let false (i64_is_any_sign_power_of_two d)) |
| 31 | + (apply_div_const_magic_s32 (Opcode.Srem) x d)) |
| 32 | +(rule (simplify_skeleton (srem x (iconst_s $I64 (i64_extract_non_zero d)))) |
| 33 | + (if-let false (i64_is_any_sign_power_of_two d)) |
| 34 | + (apply_div_const_magic_s64 (Opcode.Srem) x d)) |
| 35 | + |
0 commit comments