|
101 | 101 | (subsume x)) |
102 | 102 |
|
103 | 103 | ;; x ^ x == 0. |
104 | | -(rule (simplify (bxor (fits_in_64 ty) x x)) |
| 104 | +(rule (simplify (bxor (fits_in_64 (ty_int ty)) x x)) |
105 | 105 | (subsume (iconst ty (imm64 0)))) |
106 | 106 |
|
107 | 107 | ;; x ^ not(x) == not(x) ^ x == -1. |
|
167 | 167 | (iadd ty x x)) |
168 | 168 |
|
169 | 169 | ;; x*c == x<<log2(c) when c is a power of two. |
| 170 | +;; Note that the type of `iconst` must be the same as the type of `imul`, |
| 171 | +;; so these rules can only fire in situations where it's safe to construct an |
| 172 | +;; `iconst` of that type. |
170 | 173 | (rule (simplify (imul ty x (iconst _ (imm64_power_of_two c)))) |
171 | 174 | (ishl ty x (iconst ty (imm64 c)))) |
172 | 175 | (rule (simplify (imul ty (iconst _ (imm64_power_of_two c)) x)) |
|
252 | 255 | ;; `x == x` is always true for integers; `x != x` is false. Strict |
253 | 256 | ;; inequalities are false, and loose inequalities are true. |
254 | 257 | (rule (simplify |
255 | | - (icmp (ty_int ty) (IntCC.Equal) x x)) |
| 258 | + (icmp (fits_in_64 (ty_int ty)) (IntCC.Equal) x x)) |
256 | 259 | (iconst ty (imm64 1))) |
257 | 260 | (rule (simplify |
258 | | - (icmp (ty_int ty) (IntCC.NotEqual) x x)) |
| 261 | + (icmp (fits_in_64 (ty_int ty)) (IntCC.NotEqual) x x)) |
259 | 262 | (iconst ty (imm64 0))) |
260 | 263 | (rule (simplify |
261 | | - (icmp (ty_int ty) (IntCC.UnsignedGreaterThan) x x)) |
| 264 | + (icmp (fits_in_64 (ty_int ty)) (IntCC.UnsignedGreaterThan) x x)) |
262 | 265 | (iconst ty (imm64 0))) |
263 | 266 | (rule (simplify |
264 | | - (icmp (ty_int ty) (IntCC.UnsignedGreaterThanOrEqual) x x)) |
| 267 | + (icmp (fits_in_64 (ty_int ty)) (IntCC.UnsignedGreaterThanOrEqual) x x)) |
265 | 268 | (iconst ty (imm64 1))) |
266 | 269 | (rule (simplify |
267 | | - (icmp (ty_int ty) (IntCC.SignedGreaterThan) x x)) |
| 270 | + (icmp (fits_in_64 (ty_int ty)) (IntCC.SignedGreaterThan) x x)) |
268 | 271 | (iconst ty (imm64 0))) |
269 | 272 | (rule (simplify |
270 | | - (icmp (ty_int ty) (IntCC.SignedGreaterThanOrEqual) x x)) |
| 273 | + (icmp (fits_in_64 (ty_int ty)) (IntCC.SignedGreaterThanOrEqual) x x)) |
271 | 274 | (iconst ty (imm64 1))) |
272 | 275 | (rule (simplify |
273 | | - (icmp (ty_int ty) (IntCC.UnsignedLessThan) x x)) |
| 276 | + (icmp (fits_in_64 (ty_int ty)) (IntCC.UnsignedLessThan) x x)) |
274 | 277 | (iconst ty (imm64 0))) |
275 | 278 | (rule (simplify |
276 | | - (icmp (ty_int ty) (IntCC.UnsignedLessThanOrEqual) x x)) |
| 279 | + (icmp (fits_in_64 (ty_int ty)) (IntCC.UnsignedLessThanOrEqual) x x)) |
277 | 280 | (iconst ty (imm64 1))) |
278 | 281 | (rule (simplify |
279 | | - (icmp (ty_int ty) (IntCC.SignedLessThan) x x)) |
| 282 | + (icmp (fits_in_64 (ty_int ty)) (IntCC.SignedLessThan) x x)) |
280 | 283 | (iconst ty (imm64 0))) |
281 | 284 | (rule (simplify |
282 | | - (icmp (ty_int ty) (IntCC.SignedLessThanOrEqual) x x)) |
| 285 | + (icmp (fits_in_64 (ty_int ty)) (IntCC.SignedLessThanOrEqual) x x)) |
283 | 286 | (iconst ty (imm64 1))) |
284 | 287 |
|
285 | 288 | ;; (x ^ -1) can be replaced with the `bnot` instruction |
|
0 commit comments