|
309 | 309 |
|
310 | 310 | // Lowering loads
|
311 | 311 | (Load <t> ptr mem) && (is64BitInt(t) || isPtr(t)) -> (MOVDload ptr mem)
|
312 |
| -(Load <t> ptr mem) && is32BitInt(t) -> (MOVWZload ptr mem) |
313 |
| -(Load <t> ptr mem) && is16BitInt(t) -> (MOVHZload ptr mem) |
314 |
| -(Load <t> ptr mem) && (t.IsBoolean() || is8BitInt(t)) -> (MOVBZload ptr mem) |
| 312 | +(Load <t> ptr mem) && is32BitInt(t) && isSigned(t) -> (MOVWload ptr mem) |
| 313 | +(Load <t> ptr mem) && is32BitInt(t) && !isSigned(t) -> (MOVWZload ptr mem) |
| 314 | +(Load <t> ptr mem) && is16BitInt(t) && isSigned(t) -> (MOVHload ptr mem) |
| 315 | +(Load <t> ptr mem) && is16BitInt(t) && !isSigned(t) -> (MOVHZload ptr mem) |
| 316 | +(Load <t> ptr mem) && is8BitInt(t) && isSigned(t) -> (MOVBload ptr mem) |
| 317 | +(Load <t> ptr mem) && (t.IsBoolean() || (is8BitInt(t) && !isSigned(t))) -> (MOVBZload ptr mem) |
315 | 318 | (Load <t> ptr mem) && is32BitFloat(t) -> (FMOVSload ptr mem)
|
316 | 319 | (Load <t> ptr mem) && is64BitFloat(t) -> (FMOVDload ptr mem)
|
317 | 320 |
|
|
442 | 445 | // ***************************
|
443 | 446 | // TODO: Should the optimizations be a separate pass?
|
444 | 447 |
|
| 448 | +// if a register move has only 1 use, just use the same register without emitting instruction |
| 449 | +// MOVDnop doesn't emit instruction, only for ensuring the type. |
| 450 | +(MOVDreg x) && x.Uses == 1 -> (MOVDnop x) |
| 451 | + |
445 | 452 | // Fold sign extensions into conditional moves of constants.
|
446 | 453 | // Designed to remove the MOVBZreg inserted by the If lowering.
|
447 |
| -(MOVBZreg x:(MOVDLT (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
448 |
| -(MOVBZreg x:(MOVDLE (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
449 |
| -(MOVBZreg x:(MOVDGT (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
450 |
| -(MOVBZreg x:(MOVDGE (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
451 |
| -(MOVBZreg x:(MOVDEQ (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
452 |
| -(MOVBZreg x:(MOVDNE (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
453 |
| -(MOVBZreg x:(MOVDGTnoinv (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
454 |
| -(MOVBZreg x:(MOVDGEnoinv (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
| 454 | +(MOVBZreg x:(MOVDLT (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
| 455 | +(MOVBZreg x:(MOVDLE (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
| 456 | +(MOVBZreg x:(MOVDGT (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
| 457 | +(MOVBZreg x:(MOVDGE (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
| 458 | +(MOVBZreg x:(MOVDEQ (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
| 459 | +(MOVBZreg x:(MOVDNE (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
| 460 | +(MOVBZreg x:(MOVDGTnoinv (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
| 461 | +(MOVBZreg x:(MOVDGEnoinv (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
455 | 462 |
|
456 | 463 | // Fold boolean tests into blocks.
|
457 | 464 | (NE (CMPWconst [0] (MOVDLT (MOVDconst [0]) (MOVDconst [1]) cmp)) yes no) -> (LT cmp yes no)
|
|
584 | 591 | (MOVDNE x y (InvertFlags cmp)) -> (MOVDNE x y cmp)
|
585 | 592 |
|
586 | 593 | // don't extend after proper load
|
587 |
| -(MOVBreg x:(MOVBload _ _)) -> x |
588 |
| -(MOVBZreg x:(MOVBZload _ _)) -> x |
589 |
| -(MOVHreg x:(MOVBload _ _)) -> x |
590 |
| -(MOVHreg x:(MOVBZload _ _)) -> x |
591 |
| -(MOVHreg x:(MOVHload _ _)) -> x |
592 |
| -(MOVHZreg x:(MOVBZload _ _)) -> x |
593 |
| -(MOVHZreg x:(MOVHZload _ _)) -> x |
594 |
| -(MOVWreg x:(MOVBload _ _)) -> x |
595 |
| -(MOVWreg x:(MOVBZload _ _)) -> x |
596 |
| -(MOVWreg x:(MOVHload _ _)) -> x |
597 |
| -(MOVWreg x:(MOVHZload _ _)) -> x |
598 |
| -(MOVWreg x:(MOVWload _ _)) -> x |
599 |
| -(MOVWZreg x:(MOVBZload _ _)) -> x |
600 |
| -(MOVWZreg x:(MOVHZload _ _)) -> x |
601 |
| -(MOVWZreg x:(MOVWZload _ _)) -> x |
| 594 | +(MOVBreg x:(MOVBload _ _)) -> (MOVDreg x) |
| 595 | +(MOVBZreg x:(MOVBZload _ _)) -> (MOVDreg x) |
| 596 | +(MOVHreg x:(MOVBload _ _)) -> (MOVDreg x) |
| 597 | +(MOVHreg x:(MOVBZload _ _)) -> (MOVDreg x) |
| 598 | +(MOVHreg x:(MOVHload _ _)) -> (MOVDreg x) |
| 599 | +(MOVHZreg x:(MOVBZload _ _)) -> (MOVDreg x) |
| 600 | +(MOVHZreg x:(MOVHZload _ _)) -> (MOVDreg x) |
| 601 | +(MOVWreg x:(MOVBload _ _)) -> (MOVDreg x) |
| 602 | +(MOVWreg x:(MOVBZload _ _)) -> (MOVDreg x) |
| 603 | +(MOVWreg x:(MOVHload _ _)) -> (MOVDreg x) |
| 604 | +(MOVWreg x:(MOVHZload _ _)) -> (MOVDreg x) |
| 605 | +(MOVWreg x:(MOVWload _ _)) -> (MOVDreg x) |
| 606 | +(MOVWZreg x:(MOVBZload _ _)) -> (MOVDreg x) |
| 607 | +(MOVWZreg x:(MOVHZload _ _)) -> (MOVDreg x) |
| 608 | +(MOVWZreg x:(MOVWZload _ _)) -> (MOVDreg x) |
602 | 609 |
|
603 | 610 | // don't extend if argument is already extended
|
604 |
| -(MOVBreg x:(Arg <t>)) && is8BitInt(t) && isSigned(t) -> x |
605 |
| -(MOVBZreg x:(Arg <t>)) && is8BitInt(t) && !isSigned(t) -> x |
606 |
| -(MOVHreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t)) && isSigned(t) -> x |
607 |
| -(MOVHZreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t)) && !isSigned(t) -> x |
608 |
| -(MOVWreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && isSigned(t) -> x |
609 |
| -(MOVWZreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && !isSigned(t) -> x |
| 611 | +(MOVBreg x:(Arg <t>)) && is8BitInt(t) && isSigned(t) -> (MOVDreg x) |
| 612 | +(MOVBZreg x:(Arg <t>)) && is8BitInt(t) && !isSigned(t) -> (MOVDreg x) |
| 613 | +(MOVHreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t)) && isSigned(t) -> (MOVDreg x) |
| 614 | +(MOVHZreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t)) && !isSigned(t) -> (MOVDreg x) |
| 615 | +(MOVWreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && isSigned(t) -> (MOVDreg x) |
| 616 | +(MOVWZreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && !isSigned(t) -> (MOVDreg x) |
610 | 617 |
|
611 | 618 | // fold double extensions
|
612 |
| -(MOVBreg x:(MOVBreg _)) -> x |
613 |
| -(MOVBZreg x:(MOVBZreg _)) -> x |
614 |
| -(MOVHreg x:(MOVBreg _)) -> x |
615 |
| -(MOVHreg x:(MOVBZreg _)) -> x |
616 |
| -(MOVHreg x:(MOVHreg _)) -> x |
617 |
| -(MOVHZreg x:(MOVBZreg _)) -> x |
618 |
| -(MOVHZreg x:(MOVHZreg _)) -> x |
619 |
| -(MOVWreg x:(MOVBreg _)) -> x |
620 |
| -(MOVWreg x:(MOVBZreg _)) -> x |
621 |
| -(MOVWreg x:(MOVHreg _)) -> x |
622 |
| -(MOVWreg x:(MOVHreg _)) -> x |
623 |
| -(MOVWreg x:(MOVWreg _)) -> x |
624 |
| -(MOVWZreg x:(MOVBZreg _)) -> x |
625 |
| -(MOVWZreg x:(MOVHZreg _)) -> x |
626 |
| -(MOVWZreg x:(MOVWZreg _)) -> x |
| 619 | +(MOVBreg x:(MOVBreg _)) -> (MOVDreg x) |
| 620 | +(MOVBZreg x:(MOVBZreg _)) -> (MOVDreg x) |
| 621 | +(MOVHreg x:(MOVBreg _)) -> (MOVDreg x) |
| 622 | +(MOVHreg x:(MOVBZreg _)) -> (MOVDreg x) |
| 623 | +(MOVHreg x:(MOVHreg _)) -> (MOVDreg x) |
| 624 | +(MOVHZreg x:(MOVBZreg _)) -> (MOVDreg x) |
| 625 | +(MOVHZreg x:(MOVHZreg _)) -> (MOVDreg x) |
| 626 | +(MOVWreg x:(MOVBreg _)) -> (MOVDreg x) |
| 627 | +(MOVWreg x:(MOVBZreg _)) -> (MOVDreg x) |
| 628 | +(MOVWreg x:(MOVHreg _)) -> (MOVDreg x) |
| 629 | +(MOVWreg x:(MOVHreg _)) -> (MOVDreg x) |
| 630 | +(MOVWreg x:(MOVWreg _)) -> (MOVDreg x) |
| 631 | +(MOVWZreg x:(MOVBZreg _)) -> (MOVDreg x) |
| 632 | +(MOVWZreg x:(MOVHZreg _)) -> (MOVDreg x) |
| 633 | +(MOVWZreg x:(MOVWZreg _)) -> (MOVDreg x) |
627 | 634 |
|
628 | 635 | // fold extensions into constants
|
629 | 636 | (MOVBreg (MOVDconst [c])) -> (MOVDconst [int64(int8(c))])
|
|
653 | 660 | (MOVWZreg x:(MOVWZloadidx [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWZloadidx <v.Type> [off] {sym} ptr idx mem)
|
654 | 661 |
|
655 | 662 | // replace load from same location as preceding store with copy
|
656 |
| -(MOVBZload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x |
657 |
| -(MOVHZload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x |
658 |
| -(MOVWZload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x |
659 |
| -(MOVDload [off] {sym} ptr (MOVDstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x |
| 663 | +(MOVBZload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDreg x) |
| 664 | +(MOVHZload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDreg x) |
| 665 | +(MOVWZload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDreg x) |
| 666 | +(MOVDload [off] {sym} ptr (MOVDstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDreg x) |
660 | 667 |
|
661 | 668 | // Don't extend before storing
|
662 | 669 | (MOVWstore [off] {sym} ptr (MOVWreg x) mem) -> (MOVWstore [off] {sym} ptr x mem)
|
|
0 commit comments