@@ -1402,6 +1402,135 @@ bool AVRExpandPseudo::expand<AVR::LSLWRd>(Block &MBB, BlockIt MBBI) {
1402
1402
return true ;
1403
1403
}
1404
1404
1405
+ template <>
1406
+ bool AVRExpandPseudo::expand<AVR::LSLW4Rd>(Block &MBB, BlockIt MBBI) {
1407
+ MachineInstr &MI = *MBBI;
1408
+ Register DstLoReg, DstHiReg;
1409
+ Register DstReg = MI.getOperand (0 ).getReg ();
1410
+ bool DstIsDead = MI.getOperand (0 ).isDead ();
1411
+ bool DstIsKill = MI.getOperand (1 ).isKill ();
1412
+ bool ImpIsDead = MI.getOperand (2 ).isDead ();
1413
+ TRI->splitReg (DstReg, DstLoReg, DstHiReg);
1414
+
1415
+ // swap Rh
1416
+ // swap Rl
1417
+ buildMI (MBB, MBBI, AVR::SWAPRd)
1418
+ .addReg (DstHiReg, RegState::Define | getDeadRegState (DstIsDead))
1419
+ .addReg (DstHiReg, getKillRegState (DstIsKill));
1420
+ buildMI (MBB, MBBI, AVR::SWAPRd)
1421
+ .addReg (DstLoReg, RegState::Define | getDeadRegState (DstIsDead))
1422
+ .addReg (DstLoReg, getKillRegState (DstIsKill));
1423
+
1424
+ // andi Rh, 0xf0
1425
+ auto MI0 =
1426
+ buildMI (MBB, MBBI, AVR::ANDIRdK)
1427
+ .addReg (DstHiReg, RegState::Define | getDeadRegState (DstIsDead))
1428
+ .addReg (DstHiReg, getKillRegState (DstIsKill))
1429
+ .addImm (0xf0 );
1430
+ // SREG is implicitly dead.
1431
+ MI0->getOperand (3 ).setIsDead ();
1432
+
1433
+ // eor Rh, Rl
1434
+ auto MI1 =
1435
+ buildMI (MBB, MBBI, AVR::EORRdRr)
1436
+ .addReg (DstHiReg, RegState::Define | getDeadRegState (DstIsDead))
1437
+ .addReg (DstHiReg, getKillRegState (DstIsKill))
1438
+ .addReg (DstLoReg, getKillRegState (DstIsKill));
1439
+ // SREG is implicitly dead.
1440
+ MI1->getOperand (3 ).setIsDead ();
1441
+
1442
+ // andi Rl, 0xf0
1443
+ auto MI2 =
1444
+ buildMI (MBB, MBBI, AVR::ANDIRdK)
1445
+ .addReg (DstLoReg, RegState::Define | getDeadRegState (DstIsDead))
1446
+ .addReg (DstLoReg, getKillRegState (DstIsKill))
1447
+ .addImm (0xf0 );
1448
+ // SREG is implicitly dead.
1449
+ MI2->getOperand (3 ).setIsDead ();
1450
+
1451
+ // eor Rh, Rl
1452
+ auto MI3 =
1453
+ buildMI (MBB, MBBI, AVR::EORRdRr)
1454
+ .addReg (DstHiReg, RegState::Define | getDeadRegState (DstIsDead))
1455
+ .addReg (DstHiReg, getKillRegState (DstIsKill))
1456
+ .addReg (DstLoReg, getKillRegState (DstIsKill));
1457
+ if (ImpIsDead)
1458
+ MI3->getOperand (3 ).setIsDead ();
1459
+
1460
+ MI.eraseFromParent ();
1461
+ return true ;
1462
+ }
1463
+
1464
+ template <>
1465
+ bool AVRExpandPseudo::expand<AVR::LSLW8Rd>(Block &MBB, BlockIt MBBI) {
1466
+ MachineInstr &MI = *MBBI;
1467
+ Register DstLoReg, DstHiReg;
1468
+ Register DstReg = MI.getOperand (0 ).getReg ();
1469
+ bool DstIsDead = MI.getOperand (0 ).isDead ();
1470
+ bool DstIsKill = MI.getOperand (1 ).isKill ();
1471
+ bool ImpIsDead = MI.getOperand (2 ).isDead ();
1472
+ TRI->splitReg (DstReg, DstLoReg, DstHiReg);
1473
+
1474
+ // mov Rh, Rl
1475
+ buildMI (MBB, MBBI, AVR::MOVRdRr)
1476
+ .addReg (DstHiReg, RegState::Define | getDeadRegState (DstIsDead))
1477
+ .addReg (DstLoReg, getKillRegState (DstIsKill));
1478
+
1479
+ // clr Rl
1480
+ auto MIBLO =
1481
+ buildMI (MBB, MBBI, AVR::EORRdRr)
1482
+ .addReg (DstLoReg, RegState::Define | getDeadRegState (DstIsDead))
1483
+ .addReg (DstLoReg, getKillRegState (DstIsKill))
1484
+ .addReg (DstLoReg, getKillRegState (DstIsKill));
1485
+ if (ImpIsDead)
1486
+ MIBLO->getOperand (3 ).setIsDead ();
1487
+
1488
+ MI.eraseFromParent ();
1489
+ return true ;
1490
+ }
1491
+
1492
+ template <>
1493
+ bool AVRExpandPseudo::expand<AVR::LSLW12Rd>(Block &MBB, BlockIt MBBI) {
1494
+ MachineInstr &MI = *MBBI;
1495
+ Register DstLoReg, DstHiReg;
1496
+ Register DstReg = MI.getOperand (0 ).getReg ();
1497
+ bool DstIsDead = MI.getOperand (0 ).isDead ();
1498
+ bool DstIsKill = MI.getOperand (1 ).isKill ();
1499
+ bool ImpIsDead = MI.getOperand (2 ).isDead ();
1500
+ TRI->splitReg (DstReg, DstLoReg, DstHiReg);
1501
+
1502
+ // mov Rh, Rl
1503
+ buildMI (MBB, MBBI, AVR::MOVRdRr)
1504
+ .addReg (DstHiReg, RegState::Define | getDeadRegState (DstIsDead))
1505
+ .addReg (DstLoReg, getKillRegState (DstIsKill));
1506
+
1507
+ // swap Rh
1508
+ buildMI (MBB, MBBI, AVR::SWAPRd)
1509
+ .addReg (DstHiReg, RegState::Define | getDeadRegState (DstIsDead))
1510
+ .addReg (DstHiReg, getKillRegState (DstIsKill));
1511
+
1512
+ // andi Rh, 0xf0
1513
+ auto MI0 =
1514
+ buildMI (MBB, MBBI, AVR::ANDIRdK)
1515
+ .addReg (DstHiReg, RegState::Define | getDeadRegState (DstIsDead))
1516
+ .addReg (DstHiReg, getKillRegState (DstIsKill))
1517
+ .addImm (0xf0 );
1518
+ // SREG is implicitly dead.
1519
+ MI0->getOperand (3 ).setIsDead ();
1520
+
1521
+ // clr Rl
1522
+ auto MI1 =
1523
+ buildMI (MBB, MBBI, AVR::EORRdRr)
1524
+ .addReg (DstLoReg, RegState::Define | getDeadRegState (DstIsDead))
1525
+ .addReg (DstLoReg, getKillRegState (DstIsKill))
1526
+ .addReg (DstLoReg, getKillRegState (DstIsKill));
1527
+ if (ImpIsDead)
1528
+ MI1->getOperand (3 ).setIsDead ();
1529
+
1530
+ MI.eraseFromParent ();
1531
+ return true ;
1532
+ }
1533
+
1405
1534
template <>
1406
1535
bool AVRExpandPseudo::expand<AVR::LSRWRd>(Block &MBB, BlockIt MBBI) {
1407
1536
MachineInstr &MI = *MBBI;
@@ -1433,6 +1562,135 @@ bool AVRExpandPseudo::expand<AVR::LSRWRd>(Block &MBB, BlockIt MBBI) {
1433
1562
return true ;
1434
1563
}
1435
1564
1565
+ template <>
1566
+ bool AVRExpandPseudo::expand<AVR::LSRW4Rd>(Block &MBB, BlockIt MBBI) {
1567
+ MachineInstr &MI = *MBBI;
1568
+ Register DstLoReg, DstHiReg;
1569
+ Register DstReg = MI.getOperand (0 ).getReg ();
1570
+ bool DstIsDead = MI.getOperand (0 ).isDead ();
1571
+ bool DstIsKill = MI.getOperand (1 ).isKill ();
1572
+ bool ImpIsDead = MI.getOperand (2 ).isDead ();
1573
+ TRI->splitReg (DstReg, DstLoReg, DstHiReg);
1574
+
1575
+ // swap Rh
1576
+ // swap Rl
1577
+ buildMI (MBB, MBBI, AVR::SWAPRd)
1578
+ .addReg (DstHiReg, RegState::Define | getDeadRegState (DstIsDead))
1579
+ .addReg (DstHiReg, getKillRegState (DstIsKill));
1580
+ buildMI (MBB, MBBI, AVR::SWAPRd)
1581
+ .addReg (DstLoReg, RegState::Define | getDeadRegState (DstIsDead))
1582
+ .addReg (DstLoReg, getKillRegState (DstIsKill));
1583
+
1584
+ // andi Rl, 0xf
1585
+ auto MI0 =
1586
+ buildMI (MBB, MBBI, AVR::ANDIRdK)
1587
+ .addReg (DstLoReg, RegState::Define | getDeadRegState (DstIsDead))
1588
+ .addReg (DstLoReg, getKillRegState (DstIsKill))
1589
+ .addImm (0xf );
1590
+ // SREG is implicitly dead.
1591
+ MI0->getOperand (3 ).setIsDead ();
1592
+
1593
+ // eor Rl, Rh
1594
+ auto MI1 =
1595
+ buildMI (MBB, MBBI, AVR::EORRdRr)
1596
+ .addReg (DstLoReg, RegState::Define | getDeadRegState (DstIsDead))
1597
+ .addReg (DstLoReg, getKillRegState (DstIsKill))
1598
+ .addReg (DstHiReg, getKillRegState (DstIsKill));
1599
+ // SREG is implicitly dead.
1600
+ MI1->getOperand (3 ).setIsDead ();
1601
+
1602
+ // andi Rh, 0xf
1603
+ auto MI2 =
1604
+ buildMI (MBB, MBBI, AVR::ANDIRdK)
1605
+ .addReg (DstHiReg, RegState::Define | getDeadRegState (DstIsDead))
1606
+ .addReg (DstHiReg, getKillRegState (DstIsKill))
1607
+ .addImm (0xf );
1608
+ // SREG is implicitly dead.
1609
+ MI2->getOperand (3 ).setIsDead ();
1610
+
1611
+ // eor Rl, Rh
1612
+ auto MI3 =
1613
+ buildMI (MBB, MBBI, AVR::EORRdRr)
1614
+ .addReg (DstLoReg, RegState::Define | getDeadRegState (DstIsDead))
1615
+ .addReg (DstLoReg, getKillRegState (DstIsKill))
1616
+ .addReg (DstHiReg, getKillRegState (DstIsKill));
1617
+ if (ImpIsDead)
1618
+ MI3->getOperand (3 ).setIsDead ();
1619
+
1620
+ MI.eraseFromParent ();
1621
+ return true ;
1622
+ }
1623
+
1624
+ template <>
1625
+ bool AVRExpandPseudo::expand<AVR::LSRW8Rd>(Block &MBB, BlockIt MBBI) {
1626
+ MachineInstr &MI = *MBBI;
1627
+ Register DstLoReg, DstHiReg;
1628
+ Register DstReg = MI.getOperand (0 ).getReg ();
1629
+ bool DstIsDead = MI.getOperand (0 ).isDead ();
1630
+ bool DstIsKill = MI.getOperand (1 ).isKill ();
1631
+ bool ImpIsDead = MI.getOperand (2 ).isDead ();
1632
+ TRI->splitReg (DstReg, DstLoReg, DstHiReg);
1633
+
1634
+ // Move upper byte to lower byte.
1635
+ buildMI (MBB, MBBI, AVR::MOVRdRr)
1636
+ .addReg (DstLoReg, RegState::Define | getDeadRegState (DstIsDead))
1637
+ .addReg (DstHiReg);
1638
+
1639
+ // Clear upper byte.
1640
+ auto MIBHI =
1641
+ buildMI (MBB, MBBI, AVR::EORRdRr)
1642
+ .addReg (DstHiReg, RegState::Define | getDeadRegState (DstIsDead))
1643
+ .addReg (DstHiReg, getKillRegState (DstIsKill))
1644
+ .addReg (DstHiReg, getKillRegState (DstIsKill));
1645
+ if (ImpIsDead)
1646
+ MIBHI->getOperand (3 ).setIsDead ();
1647
+
1648
+ MI.eraseFromParent ();
1649
+ return true ;
1650
+ }
1651
+
1652
+ template <>
1653
+ bool AVRExpandPseudo::expand<AVR::LSRW12Rd>(Block &MBB, BlockIt MBBI) {
1654
+ MachineInstr &MI = *MBBI;
1655
+ Register DstLoReg, DstHiReg;
1656
+ Register DstReg = MI.getOperand (0 ).getReg ();
1657
+ bool DstIsDead = MI.getOperand (0 ).isDead ();
1658
+ bool DstIsKill = MI.getOperand (1 ).isKill ();
1659
+ bool ImpIsDead = MI.getOperand (2 ).isDead ();
1660
+ TRI->splitReg (DstReg, DstLoReg, DstHiReg);
1661
+
1662
+ // Move upper byte to lower byte.
1663
+ buildMI (MBB, MBBI, AVR::MOVRdRr)
1664
+ .addReg (DstLoReg, RegState::Define | getDeadRegState (DstIsDead))
1665
+ .addReg (DstHiReg);
1666
+
1667
+ // swap Rl
1668
+ buildMI (MBB, MBBI, AVR::SWAPRd)
1669
+ .addReg (DstLoReg, RegState::Define | getDeadRegState (DstIsDead))
1670
+ .addReg (DstLoReg, getKillRegState (DstIsKill));
1671
+
1672
+ // andi Rl, 0xf
1673
+ auto MI0 =
1674
+ buildMI (MBB, MBBI, AVR::ANDIRdK)
1675
+ .addReg (DstLoReg, RegState::Define | getDeadRegState (DstIsDead))
1676
+ .addReg (DstLoReg, getKillRegState (DstIsKill))
1677
+ .addImm (0xf );
1678
+ // SREG is implicitly dead.
1679
+ MI0->getOperand (3 ).setIsDead ();
1680
+
1681
+ // Clear upper byte.
1682
+ auto MIBHI =
1683
+ buildMI (MBB, MBBI, AVR::EORRdRr)
1684
+ .addReg (DstHiReg, RegState::Define | getDeadRegState (DstIsDead))
1685
+ .addReg (DstHiReg, getKillRegState (DstIsKill))
1686
+ .addReg (DstHiReg, getKillRegState (DstIsKill));
1687
+ if (ImpIsDead)
1688
+ MIBHI->getOperand (3 ).setIsDead ();
1689
+
1690
+ MI.eraseFromParent ();
1691
+ return true ;
1692
+ }
1693
+
1436
1694
template <>
1437
1695
bool AVRExpandPseudo::expand<AVR::RORWRd>(Block &MBB, BlockIt MBBI) {
1438
1696
llvm_unreachable (" RORW unimplemented" );
@@ -1476,6 +1734,39 @@ bool AVRExpandPseudo::expand<AVR::ASRWRd>(Block &MBB, BlockIt MBBI) {
1476
1734
return true ;
1477
1735
}
1478
1736
1737
+ template <>
1738
+ bool AVRExpandPseudo::expand<AVR::ASRW8Rd>(Block &MBB, BlockIt MBBI) {
1739
+ MachineInstr &MI = *MBBI;
1740
+ Register DstLoReg, DstHiReg;
1741
+ Register DstReg = MI.getOperand (0 ).getReg ();
1742
+ bool DstIsDead = MI.getOperand (0 ).isDead ();
1743
+ bool DstIsKill = MI.getOperand (1 ).isKill ();
1744
+ bool ImpIsDead = MI.getOperand (2 ).isDead ();
1745
+ TRI->splitReg (DstReg, DstLoReg, DstHiReg);
1746
+
1747
+ // Move upper byte to lower byte.
1748
+ buildMI (MBB, MBBI, AVR::MOVRdRr)
1749
+ .addReg (DstLoReg, RegState::Define | getDeadRegState (DstIsDead))
1750
+ .addReg (DstHiReg, getKillRegState (DstIsKill));
1751
+
1752
+ // Move the sign bit to the C flag.
1753
+ buildMI (MBB, MBBI, AVR::ADDRdRr).addReg (DstHiReg)
1754
+ .addReg (DstHiReg, RegState::Define | getDeadRegState (DstIsDead))
1755
+ .addReg (DstHiReg, getKillRegState (DstIsKill));
1756
+
1757
+ // Set upper byte to 0 or -1.
1758
+ auto MIBHI =
1759
+ buildMI (MBB, MBBI, AVR::SBCRdRr)
1760
+ .addReg (DstHiReg, RegState::Define | getDeadRegState (DstIsDead))
1761
+ .addReg (DstHiReg, getKillRegState (DstIsKill))
1762
+ .addReg (DstHiReg, getKillRegState (DstIsKill));
1763
+ if (ImpIsDead)
1764
+ MIBHI->getOperand (3 ).setIsDead ();
1765
+
1766
+ MI.eraseFromParent ();
1767
+ return true ;
1768
+ }
1769
+
1479
1770
template <>
1480
1771
bool AVRExpandPseudo::expand<AVR::LSLB7Rd>(Block &MBB, BlockIt MBBI) {
1481
1772
MachineInstr &MI = *MBBI;
@@ -1798,10 +2089,17 @@ bool AVRExpandPseudo::expandMI(Block &MBB, BlockIt MBBI) {
1798
2089
EXPAND (AVR::ROLBRd);
1799
2090
EXPAND (AVR::RORBRd);
1800
2091
EXPAND (AVR::LSLWRd);
2092
+ EXPAND (AVR::LSLW4Rd);
2093
+ EXPAND (AVR::LSLW8Rd);
2094
+ EXPAND (AVR::LSLW12Rd);
1801
2095
EXPAND (AVR::LSRWRd);
2096
+ EXPAND (AVR::LSRW4Rd);
2097
+ EXPAND (AVR::LSRW8Rd);
2098
+ EXPAND (AVR::LSRW12Rd);
1802
2099
EXPAND (AVR::RORWRd);
1803
2100
EXPAND (AVR::ROLWRd);
1804
2101
EXPAND (AVR::ASRWRd);
2102
+ EXPAND (AVR::ASRW8Rd);
1805
2103
EXPAND (AVR::LSLB7Rd);
1806
2104
EXPAND (AVR::LSRB7Rd);
1807
2105
EXPAND (AVR::ASRB7Rd);
0 commit comments