|
46 | 46 | (iadd x y))) |
47 | 47 | (x64_add ty x y)) |
48 | 48 |
|
49 | | -;; Add a register and an immediate. |
| 49 | +;; The above case handles when the rhs is an immediate or a sinkable load, but |
| 50 | +;; additionally add lhs meets these criteria. |
50 | 51 |
|
51 | 52 | (rule -4 (lower (has_type (fits_in_64 ty) |
52 | | - (iadd x (simm32_from_value y)))) |
53 | | - (x64_add ty x y)) |
54 | | - |
55 | | -(rule -3 (lower (has_type (fits_in_64 ty) |
56 | 53 | (iadd (simm32_from_value x) y))) |
57 | 54 | (x64_add ty y x)) |
58 | | - |
59 | | -;; Add a register and memory. |
60 | | - |
61 | | -(rule -2 (lower (has_type (fits_in_64 ty) |
62 | | - (iadd x (sinkable_load y)))) |
63 | | - (x64_add ty |
64 | | - x |
65 | | - (sink_load_to_gpr_mem_imm y))) |
66 | | - |
67 | | -(rule -1 (lower (has_type (fits_in_64 ty) |
| 55 | +(rule -3 (lower (has_type (fits_in_64 ty) |
68 | 56 | (iadd (sinkable_load x) y))) |
69 | | - (x64_add ty |
70 | | - y |
71 | | - (sink_load_to_gpr_mem_imm x))) |
| 57 | + (x64_add ty y x)) |
72 | 58 |
|
73 | 59 | ;; SSE. |
74 | 60 |
|
|
144 | 130 | (isub x y))) |
145 | 131 | (x64_sub ty x y)) |
146 | 132 |
|
147 | | -;; Sub a register and an immediate. |
148 | | -(rule -2 (lower (has_type (fits_in_64 ty) |
149 | | - (isub x (simm32_from_value y)))) |
150 | | - (x64_sub ty x y)) |
151 | | - |
152 | | -;; Sub a register and memory. |
153 | | -(rule -1 (lower (has_type (fits_in_64 ty) |
154 | | - (isub x (sinkable_load y)))) |
155 | | - (x64_sub ty x |
156 | | - (sink_load_to_gpr_mem_imm y))) |
157 | | - |
158 | 133 | ;; SSE. |
159 | 134 |
|
160 | 135 | (rule (lower (has_type (multi_lane 8 16) |
|
216 | 191 | (if (ty_int_ref_scalar_64 ty)) |
217 | 192 | (x64_and ty x y)) |
218 | 193 |
|
219 | | -;; And with a memory operand. |
220 | | - |
221 | | -(rule 1 (lower (has_type ty (band x (sinkable_load y)))) |
222 | | - (if (ty_int_ref_scalar_64 ty)) |
223 | | - (x64_and ty x |
224 | | - (sink_load_to_gpr_mem_imm y))) |
225 | | - |
226 | | -(rule 2 (lower (has_type ty (band (sinkable_load x) y))) |
227 | | - (if (ty_int_ref_scalar_64 ty)) |
228 | | - (x64_and ty |
229 | | - y |
230 | | - (sink_load_to_gpr_mem_imm x))) |
231 | | - |
232 | | -;; And with an immediate. |
| 194 | +;; The above case automatically handles when the rhs is an immediate or a |
| 195 | +;; sinkable load, but additionally handle the lhs here. |
233 | 196 |
|
234 | | -(rule 3 (lower (has_type ty (band x (simm32_from_value y)))) |
| 197 | +(rule 1 (lower (has_type ty (band (sinkable_load x) y))) |
235 | 198 | (if (ty_int_ref_scalar_64 ty)) |
236 | | - (x64_and ty x y)) |
| 199 | + (x64_and ty y x)) |
237 | 200 |
|
238 | | -(rule 4 (lower (has_type ty (band (simm32_from_value x) y))) |
| 201 | +(rule 2 (lower (has_type ty (band (simm32_from_value x) y))) |
239 | 202 | (if (ty_int_ref_scalar_64 ty)) |
240 | 203 | (x64_and ty y x)) |
241 | 204 |
|
|
308 | 271 | (if (ty_int_ref_scalar_64 ty)) |
309 | 272 | (x64_or ty x y)) |
310 | 273 |
|
311 | | -;; Or with a memory operand. |
312 | | - |
313 | | -(rule 1 (lower (has_type ty (bor x (sinkable_load y)))) |
314 | | - (if (ty_int_ref_scalar_64 ty)) |
315 | | - (x64_or ty x |
316 | | - (sink_load_to_gpr_mem_imm y))) |
| 274 | +;; Handle immediates/sinkable loads on the lhs in addition to the automatic |
| 275 | +;; handling of the rhs above |
317 | 276 |
|
318 | | -(rule 2 (lower (has_type ty (bor (sinkable_load x) y))) |
| 277 | +(rule 1 (lower (has_type ty (bor (sinkable_load x) y))) |
319 | 278 | (if (ty_int_ref_scalar_64 ty)) |
320 | | - (x64_or ty y |
321 | | - (sink_load_to_gpr_mem_imm x))) |
322 | | - |
323 | | -;; Or with an immediate. |
324 | | - |
325 | | -(rule 3 (lower (has_type ty (bor x (simm32_from_value y)))) |
326 | | - (if (ty_int_ref_scalar_64 ty)) |
327 | | - (x64_or ty x y)) |
| 279 | + (x64_or ty y x)) |
328 | 280 |
|
329 | | -(rule 4 (lower (has_type ty (bor (simm32_from_value x) y))) |
| 281 | +(rule 2 (lower (has_type ty (bor (simm32_from_value x) y))) |
330 | 282 | (if (ty_int_ref_scalar_64 ty)) |
331 | 283 | (x64_or ty y x)) |
332 | 284 |
|
|
371 | 323 | (if (ty_int_ref_scalar_64 ty)) |
372 | 324 | (x64_xor ty x y)) |
373 | 325 |
|
374 | | -;; Xor with a memory operand. |
| 326 | +;; Handle xor with lhs immediates/sinkable loads in addition to the automatic |
| 327 | +;; handling of the rhs above. |
375 | 328 |
|
376 | | -(rule 1 (lower (has_type ty (bxor x (sinkable_load y)))) |
| 329 | +(rule 1 (lower (has_type ty (bxor (sinkable_load x) y))) |
377 | 330 | (if (ty_int_ref_scalar_64 ty)) |
378 | | - (x64_xor ty x |
379 | | - (sink_load_to_gpr_mem_imm y))) |
380 | | - |
381 | | -(rule 2 (lower (has_type ty (bxor (sinkable_load x) y))) |
382 | | - (if (ty_int_ref_scalar_64 ty)) |
383 | | - (x64_xor ty y |
384 | | - (sink_load_to_gpr_mem_imm x))) |
385 | | - |
386 | | -;; Xor with an immediate. |
387 | | - |
388 | | -(rule 3 (lower (has_type ty (bxor x (simm32_from_value y)))) |
389 | | - (if (ty_int_ref_scalar_64 ty)) |
390 | | - (x64_xor ty x y)) |
| 331 | + (x64_xor ty y x)) |
391 | 332 |
|
392 | 333 | (rule 4 (lower (has_type ty (bxor (simm32_from_value x) y))) |
393 | 334 | (if (ty_int_ref_scalar_64 ty)) |
|
841 | 782 | (rule -5 (lower (has_type (fits_in_64 ty) (imul x y))) |
842 | 783 | (x64_mul ty x y)) |
843 | 784 |
|
844 | | -;; Multiply a register and an immediate. |
845 | | - |
846 | | -(rule -3 (lower (has_type (fits_in_64 ty) |
847 | | - (imul x (simm32_from_value y)))) |
848 | | - (x64_mul ty x y)) |
| 785 | +;; Handle multiplication where the lhs is an immediate or sinkable load in |
| 786 | +;; addition to the automatic rhs handling above. |
849 | 787 |
|
850 | 788 | (rule -4 (lower (has_type (fits_in_64 ty) |
851 | 789 | (imul (simm32_from_value x) y))) |
852 | 790 | (x64_mul ty y x)) |
853 | | - |
854 | | -;; Multiply a register and a memory load. |
855 | | - |
856 | | -(rule -2 (lower (has_type (fits_in_64 ty) |
857 | | - (imul x (sinkable_load y)))) |
858 | | - (x64_mul ty |
859 | | - x |
860 | | - (sink_load_to_gpr_mem_imm y))) |
861 | | - |
862 | | -(rule -1 (lower (has_type (fits_in_64 ty) |
| 791 | +(rule -3 (lower (has_type (fits_in_64 ty) |
863 | 792 | (imul (sinkable_load x) y))) |
864 | | - (x64_mul ty y |
865 | | - (sink_load_to_gpr_mem_imm x))) |
| 793 | + (x64_mul ty y x)) |
866 | 794 |
|
867 | 795 | ;; `i128`. |
868 | 796 |
|
|
1459 | 1387 | (x64_add_with_flags_paired ty a b) |
1460 | 1388 | (trap_if (CC.B) tc))) |
1461 | 1389 |
|
1462 | | -;; Add a register and an immediate. |
| 1390 | +;; Handle lhs immediates/sinkable loads in addition to the automatic rhs |
| 1391 | +;; handling of above. |
1463 | 1392 |
|
1464 | 1393 | (rule 1 (lower (has_type (fits_in_64 ty) |
1465 | | - (uadd_overflow_trap a (simm32_from_value b) tc))) |
1466 | | - (with_flags |
1467 | | - (x64_add_with_flags_paired ty a b) |
1468 | | - (trap_if (CC.B) tc))) |
1469 | | - |
1470 | | -(rule 2 (lower (has_type (fits_in_64 ty) |
1471 | 1394 | (uadd_overflow_trap (simm32_from_value a) b tc))) |
1472 | 1395 | (with_flags |
1473 | 1396 | (x64_add_with_flags_paired ty b a) |
1474 | 1397 | (trap_if (CC.B) tc))) |
1475 | 1398 |
|
1476 | | -;; Add a register and memory. |
1477 | | - |
1478 | | -(rule 3 (lower (has_type (fits_in_64 ty) |
1479 | | - (uadd_overflow_trap a (sinkable_load b) tc))) |
1480 | | - (with_flags |
1481 | | - (x64_add_with_flags_paired ty a (sink_load_to_gpr_mem_imm b)) |
1482 | | - (trap_if (CC.B) tc))) |
1483 | | - |
1484 | | -(rule 4 (lower (has_type (fits_in_64 ty) |
| 1399 | +(rule 2 (lower (has_type (fits_in_64 ty) |
1485 | 1400 | (uadd_overflow_trap (sinkable_load a) b tc))) |
1486 | 1401 | (with_flags |
1487 | | - (x64_add_with_flags_paired ty b (sink_load_to_gpr_mem_imm a)) |
| 1402 | + (x64_add_with_flags_paired ty b a) |
1488 | 1403 | (trap_if (CC.B) tc))) |
1489 | 1404 |
|
1490 | 1405 | ;;;; Rules for `resumable_trap` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
3603 | 3518 | ;; Case 3: when presented with `load + scalar_to_vector`, coalesce into a single |
3604 | 3519 | ;; MOVSS/MOVSD instruction. |
3605 | 3520 | (rule 2 (lower (scalar_to_vector (and (sinkable_load src) (value_type (ty_32 _))))) |
3606 | | - (x64_movss_load (sink_load_to_xmm_mem src))) |
| 3521 | + (x64_movss_load src)) |
3607 | 3522 | (rule 3 (lower (scalar_to_vector (and (sinkable_load src) (value_type (ty_64 _))))) |
3608 | | - (x64_movsd_load (sink_load_to_xmm_mem src))) |
| 3523 | + (x64_movsd_load src)) |
3609 | 3524 |
|
3610 | 3525 | ;; Rules for `splat` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
3611 | 3526 |
|
|
0 commit comments