|
75 | 75 | (rule (simplify (bxor bigty (uextend _ x@(value_type smallty)) (uextend _ y@(value_type smallty))))
|
76 | 76 | (uextend bigty (bxor smallty x y)))
|
77 | 77 |
|
78 |
| -;; Matches values where `ireducing` them will not actually introduce another |
79 |
| -;; instruction, since other rules will collapse them with the reduction. |
80 |
| -(decl pure multi will_simplify_with_ireduce_rec (u8 Value) Value) |
81 |
| -(rule (will_simplify_with_ireduce_rec _ x@(uextend _ _)) x) |
82 |
| -(rule (will_simplify_with_ireduce_rec _ x@(sextend _ _)) x) |
83 |
| -(rule (will_simplify_with_ireduce_rec _ x@(iconst _ _)) x) |
84 |
| -(rule (will_simplify_with_ireduce_rec depth x@(unary_op _ _ a)) |
85 |
| - (if-let _ (u8_lt 0 depth)) |
86 |
| - (if-let _ (reducible_modular_op x)) |
87 |
| - (if-let _ (will_simplify_with_ireduce_rec (u8_sub depth 1) a)) |
88 |
| - x) |
89 |
| -(rule (will_simplify_with_ireduce_rec depth x@(binary_op _ _ a b)) |
90 |
| - (if-let _ (u8_lt 0 depth)) |
91 |
| - (if-let _ (reducible_modular_op x)) |
92 |
| - (if-let _ (will_simplify_with_ireduce_rec (u8_sub depth 1) a)) |
93 |
| - (if-let _ (will_simplify_with_ireduce_rec (u8_sub depth 1) b)) |
94 |
| - x) |
95 |
| - |
96 |
| -(decl pure multi will_simplify_with_ireduce (Value) Value) |
97 |
| -(rule (will_simplify_with_ireduce x) |
98 |
| - (will_simplify_with_ireduce_rec 2 x)) |
99 |
| - |
| 78 | +;; Replace `(small)(x OP y)` with `(small)x OP (small)y` in cases where that's |
| 79 | +;; legal. |
100 | 80 | ;; Matches values where the high bits of the input don't affect lower bits of
|
101 | 81 | ;; the output, and thus the inputs can be reduced before the operation rather
|
102 | 82 | ;; than doing the wide operation then reducing afterwards.
|
103 |
| -(decl pure multi reducible_modular_op (Value) Value) |
104 |
| -(rule (reducible_modular_op x@(ineg _ _)) x) |
105 |
| -(rule (reducible_modular_op x@(bnot _ _)) x) |
106 |
| -(rule (reducible_modular_op x@(iadd _ _ _)) x) |
107 |
| -(rule (reducible_modular_op x@(isub _ _ _)) x) |
108 |
| -(rule (reducible_modular_op x@(imul _ _ _)) x) |
109 |
| -(rule (reducible_modular_op x@(bor _ _ _)) x) |
110 |
| -(rule (reducible_modular_op x@(bxor _ _ _)) x) |
111 |
| -(rule (reducible_modular_op x@(band _ _ _)) x) |
| 83 | +(rule (simplify (ireduce ty (ineg _ x))) (ineg ty (ireduce ty x))) |
| 84 | +(rule (simplify (ireduce ty (bnot _ x))) (bnot ty (ireduce ty x))) |
112 | 85 |
|
113 |
| -;; Replace `(small)(x OP y)` with `(small)x OP (small)y` in cases where that's |
114 |
| -;; legal and it reduces the total number of instructions since the reductions |
115 |
| -;; to the arguments simplify further. |
116 |
| -(rule (simplify (ireduce smallty val@(unary_op _ op x))) |
117 |
| - (if-let _ (reducible_modular_op val)) |
118 |
| - (if-let _ (will_simplify_with_ireduce x)) |
119 |
| - (unary_op smallty op (ireduce smallty x))) |
120 |
| -(rule (simplify (ireduce smallty val@(binary_op _ op x y))) |
121 |
| - (if-let _ (reducible_modular_op val)) |
122 |
| - (if-let _ (will_simplify_with_ireduce x)) |
123 |
| - (if-let _ (will_simplify_with_ireduce y)) |
124 |
| - (binary_op smallty op (ireduce smallty x) (ireduce smallty y))) |
| 86 | +(rule (simplify (ireduce ty (iadd _ x y))) (iadd ty (ireduce ty x) (ireduce ty y))) |
| 87 | +(rule (simplify (ireduce ty (isub _ x y))) (isub ty (ireduce ty x) (ireduce ty y))) |
| 88 | +(rule (simplify (ireduce ty (imul _ x y))) (imul ty (ireduce ty x) (ireduce ty y))) |
| 89 | +(rule (simplify (ireduce ty (bor _ x y))) (bor ty (ireduce ty x) (ireduce ty y))) |
| 90 | +(rule (simplify (ireduce ty (bxor _ x y))) (bxor ty (ireduce ty x) (ireduce ty y))) |
| 91 | +(rule (simplify (ireduce ty (band _ x y))) (band ty (ireduce ty x) (ireduce ty y))) |
0 commit comments