|
312 | 312 |
|
313 | 313 | // Lowering loads
|
314 | 314 | (Load <t> ptr mem) && (is64BitInt(t) || isPtr(t)) -> (MOVDload ptr mem)
|
315 |
| -(Load <t> ptr mem) && is32BitInt(t) -> (MOVWZload ptr mem) |
316 |
| -(Load <t> ptr mem) && is16BitInt(t) -> (MOVHZload ptr mem) |
317 |
| -(Load <t> ptr mem) && (t.IsBoolean() || is8BitInt(t)) -> (MOVBZload ptr mem) |
| 315 | +(Load <t> ptr mem) && is32BitInt(t) && isSigned(t) -> (MOVWload ptr mem) |
| 316 | +(Load <t> ptr mem) && is32BitInt(t) && !isSigned(t) -> (MOVWZload ptr mem) |
| 317 | +(Load <t> ptr mem) && is16BitInt(t) && isSigned(t) -> (MOVHload ptr mem) |
| 318 | +(Load <t> ptr mem) && is16BitInt(t) && !isSigned(t) -> (MOVHZload ptr mem) |
| 319 | +(Load <t> ptr mem) && is8BitInt(t) && isSigned(t) -> (MOVBload ptr mem) |
| 320 | +(Load <t> ptr mem) && (t.IsBoolean() || (is8BitInt(t) && !isSigned(t))) -> (MOVBZload ptr mem) |
318 | 321 | (Load <t> ptr mem) && is32BitFloat(t) -> (FMOVSload ptr mem)
|
319 | 322 | (Load <t> ptr mem) && is64BitFloat(t) -> (FMOVDload ptr mem)
|
320 | 323 |
|
|
445 | 448 | // ***************************
|
446 | 449 | // TODO: Should the optimizations be a separate pass?
|
447 | 450 |
|
| 451 | +// if a register move has only 1 use, just use the same register without emitting instruction |
| 452 | +// MOVDnop doesn't emit instruction, only for ensuring the type. |
| 453 | +(MOVDreg x) && x.Uses == 1 -> (MOVDnop x) |
| 454 | + |
448 | 455 | // Fold sign extensions into conditional moves of constants.
|
449 | 456 | // Designed to remove the MOVBZreg inserted by the If lowering.
|
450 |
| -(MOVBZreg x:(MOVDLT (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
451 |
| -(MOVBZreg x:(MOVDLE (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
452 |
| -(MOVBZreg x:(MOVDGT (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
453 |
| -(MOVBZreg x:(MOVDGE (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
454 |
| -(MOVBZreg x:(MOVDEQ (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
455 |
| -(MOVBZreg x:(MOVDNE (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
456 |
| -(MOVBZreg x:(MOVDGTnoinv (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
457 |
| -(MOVBZreg x:(MOVDGEnoinv (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> x |
| 457 | +(MOVBZreg x:(MOVDLT (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
| 458 | +(MOVBZreg x:(MOVDLE (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
| 459 | +(MOVBZreg x:(MOVDGT (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
| 460 | +(MOVBZreg x:(MOVDGE (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
| 461 | +(MOVBZreg x:(MOVDEQ (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
| 462 | +(MOVBZreg x:(MOVDNE (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
| 463 | +(MOVBZreg x:(MOVDGTnoinv (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
| 464 | +(MOVBZreg x:(MOVDGEnoinv (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x) |
458 | 465 |
|
459 | 466 | // Fold boolean tests into blocks.
|
460 | 467 | (NE (CMPWconst [0] (MOVDLT (MOVDconst [0]) (MOVDconst [1]) cmp)) yes no) -> (LT cmp yes no)
|
|
572 | 579 | (MOVDNE x y (InvertFlags cmp)) -> (MOVDNE x y cmp)
|
573 | 580 |
|
574 | 581 | // don't extend after proper load
|
575 |
| -(MOVBreg x:(MOVBload _ _)) -> x |
576 |
| -(MOVBZreg x:(MOVBZload _ _)) -> x |
577 |
| -(MOVHreg x:(MOVBload _ _)) -> x |
578 |
| -(MOVHreg x:(MOVBZload _ _)) -> x |
579 |
| -(MOVHreg x:(MOVHload _ _)) -> x |
580 |
| -(MOVHZreg x:(MOVBZload _ _)) -> x |
581 |
| -(MOVHZreg x:(MOVHZload _ _)) -> x |
582 |
| -(MOVWreg x:(MOVBload _ _)) -> x |
583 |
| -(MOVWreg x:(MOVBZload _ _)) -> x |
584 |
| -(MOVWreg x:(MOVHload _ _)) -> x |
585 |
| -(MOVWreg x:(MOVHZload _ _)) -> x |
586 |
| -(MOVWreg x:(MOVWload _ _)) -> x |
587 |
| -(MOVWZreg x:(MOVBZload _ _)) -> x |
588 |
| -(MOVWZreg x:(MOVHZload _ _)) -> x |
589 |
| -(MOVWZreg x:(MOVWZload _ _)) -> x |
| 582 | +(MOVBreg x:(MOVBload _ _)) -> (MOVDreg x) |
| 583 | +(MOVBZreg x:(MOVBZload _ _)) -> (MOVDreg x) |
| 584 | +(MOVHreg x:(MOVBload _ _)) -> (MOVDreg x) |
| 585 | +(MOVHreg x:(MOVBZload _ _)) -> (MOVDreg x) |
| 586 | +(MOVHreg x:(MOVHload _ _)) -> (MOVDreg x) |
| 587 | +(MOVHZreg x:(MOVBZload _ _)) -> (MOVDreg x) |
| 588 | +(MOVHZreg x:(MOVHZload _ _)) -> (MOVDreg x) |
| 589 | +(MOVWreg x:(MOVBload _ _)) -> (MOVDreg x) |
| 590 | +(MOVWreg x:(MOVBZload _ _)) -> (MOVDreg x) |
| 591 | +(MOVWreg x:(MOVHload _ _)) -> (MOVDreg x) |
| 592 | +(MOVWreg x:(MOVHZload _ _)) -> (MOVDreg x) |
| 593 | +(MOVWreg x:(MOVWload _ _)) -> (MOVDreg x) |
| 594 | +(MOVWZreg x:(MOVBZload _ _)) -> (MOVDreg x) |
| 595 | +(MOVWZreg x:(MOVHZload _ _)) -> (MOVDreg x) |
| 596 | +(MOVWZreg x:(MOVWZload _ _)) -> (MOVDreg x) |
590 | 597 |
|
591 | 598 | // don't extend if argument is already extended
|
592 |
| -(MOVBreg x:(Arg <t>)) && is8BitInt(t) && isSigned(t) -> x |
593 |
| -(MOVBZreg x:(Arg <t>)) && is8BitInt(t) && !isSigned(t) -> x |
594 |
| -(MOVHreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t)) && isSigned(t) -> x |
595 |
| -(MOVHZreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t)) && !isSigned(t) -> x |
596 |
| -(MOVWreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && isSigned(t) -> x |
597 |
| -(MOVWZreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && !isSigned(t) -> x |
| 599 | +(MOVBreg x:(Arg <t>)) && is8BitInt(t) && isSigned(t) -> (MOVDreg x) |
| 600 | +(MOVBZreg x:(Arg <t>)) && is8BitInt(t) && !isSigned(t) -> (MOVDreg x) |
| 601 | +(MOVHreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t)) && isSigned(t) -> (MOVDreg x) |
| 602 | +(MOVHZreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t)) && !isSigned(t) -> (MOVDreg x) |
| 603 | +(MOVWreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && isSigned(t) -> (MOVDreg x) |
| 604 | +(MOVWZreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && !isSigned(t) -> (MOVDreg x) |
598 | 605 |
|
599 | 606 | // fold double extensions
|
600 |
| -(MOVBreg x:(MOVBreg _)) -> x |
601 |
| -(MOVBZreg x:(MOVBZreg _)) -> x |
602 |
| -(MOVHreg x:(MOVBreg _)) -> x |
603 |
| -(MOVHreg x:(MOVBZreg _)) -> x |
604 |
| -(MOVHreg x:(MOVHreg _)) -> x |
605 |
| -(MOVHZreg x:(MOVBZreg _)) -> x |
606 |
| -(MOVHZreg x:(MOVHZreg _)) -> x |
607 |
| -(MOVWreg x:(MOVBreg _)) -> x |
608 |
| -(MOVWreg x:(MOVBZreg _)) -> x |
609 |
| -(MOVWreg x:(MOVHreg _)) -> x |
610 |
| -(MOVWreg x:(MOVHreg _)) -> x |
611 |
| -(MOVWreg x:(MOVWreg _)) -> x |
612 |
| -(MOVWZreg x:(MOVBZreg _)) -> x |
613 |
| -(MOVWZreg x:(MOVHZreg _)) -> x |
614 |
| -(MOVWZreg x:(MOVWZreg _)) -> x |
| 607 | +(MOVBreg x:(MOVBreg _)) -> (MOVDreg x) |
| 608 | +(MOVBZreg x:(MOVBZreg _)) -> (MOVDreg x) |
| 609 | +(MOVHreg x:(MOVBreg _)) -> (MOVDreg x) |
| 610 | +(MOVHreg x:(MOVBZreg _)) -> (MOVDreg x) |
| 611 | +(MOVHreg x:(MOVHreg _)) -> (MOVDreg x) |
| 612 | +(MOVHZreg x:(MOVBZreg _)) -> (MOVDreg x) |
| 613 | +(MOVHZreg x:(MOVHZreg _)) -> (MOVDreg x) |
| 614 | +(MOVWreg x:(MOVBreg _)) -> (MOVDreg x) |
| 615 | +(MOVWreg x:(MOVBZreg _)) -> (MOVDreg x) |
| 616 | +(MOVWreg x:(MOVHreg _)) -> (MOVDreg x) |
| 617 | +(MOVWreg x:(MOVHreg _)) -> (MOVDreg x) |
| 618 | +(MOVWreg x:(MOVWreg _)) -> (MOVDreg x) |
| 619 | +(MOVWZreg x:(MOVBZreg _)) -> (MOVDreg x) |
| 620 | +(MOVWZreg x:(MOVHZreg _)) -> (MOVDreg x) |
| 621 | +(MOVWZreg x:(MOVWZreg _)) -> (MOVDreg x) |
615 | 622 |
|
616 | 623 | // fold extensions into constants
|
617 | 624 | (MOVBreg (MOVDconst [c])) -> (MOVDconst [int64(int8(c))])
|
|
641 | 648 | (MOVWZreg x:(MOVWZloadidx [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWZloadidx <v.Type> [off] {sym} ptr idx mem)
|
642 | 649 |
|
643 | 650 | // replace load from same location as preceding store with copy
|
644 |
| -(MOVBZload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x |
645 |
| -(MOVHZload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x |
646 |
| -(MOVWZload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x |
647 |
| -(MOVDload [off] {sym} ptr (MOVDstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x |
| 651 | +(MOVBZload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDreg x) |
| 652 | +(MOVHZload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDreg x) |
| 653 | +(MOVWZload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDreg x) |
| 654 | +(MOVDload [off] {sym} ptr (MOVDstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDreg x) |
648 | 655 |
|
649 | 656 | // Don't extend before storing
|
650 | 657 | (MOVWstore [off] {sym} ptr (MOVWreg x) mem) -> (MOVWstore [off] {sym} ptr x mem)
|
|
0 commit comments