diff options
| author | Dylan McKay <dylanmckay34@gmail.com> | 2016-12-30 00:21:56 +0000 |
|---|---|---|
| committer | Dylan McKay <dylanmckay34@gmail.com> | 2016-12-30 00:21:56 +0000 |
| commit | 453d04296921c53d0c257800f2a4f05f989a2d4f (patch) | |
| tree | 742930990d243efd434ea770330f04e8fc5b8ded /llvm/lib/Target | |
| parent | 0e7c84c682df71836d1cea80d8e5e11ada29af25 (diff) | |
| download | bcm5719-llvm-453d04296921c53d0c257800f2a4f05f989a2d4f.tar.gz bcm5719-llvm-453d04296921c53d0c257800f2a4f05f989a2d4f.zip | |
[AVR] Optimize 16-bit ORs with '0'
Summary: Fixes PR 31344
Authored by Anmol P. Paralkar
Reviewers: dylanmckay
Subscribers: fhahn, llvm-commits
Differential Revision: https://reviews.llvm.org/D28121
llvm-svn: 290732
Diffstat (limited to 'llvm/lib/Target')
| -rw-r--r-- | llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp b/llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp index 36f24a2b4ae..65a58cd31c3 100644 --- a/llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp +++ b/llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp @@ -74,6 +74,7 @@ private: bool expandArith(unsigned OpLo, unsigned OpHi, Block &MBB, BlockIt MBBI); bool expandLogic(unsigned Op, Block &MBB, BlockIt MBBI); bool expandLogicImm(unsigned Op, Block &MBB, BlockIt MBBI); + bool isLogicImmOpRedundant(unsigned Op, unsigned ImmVal) const; template<typename Func> bool expandAtomic(Block &MBB, BlockIt MBBI, Func f); @@ -200,6 +201,16 @@ expandLogic(unsigned Op, Block &MBB, BlockIt MBBI) { } bool AVRExpandPseudo:: + isLogicImmOpRedundant(unsigned Op, unsigned ImmVal) const { + + // ORI Rd, 0x0 is redundant. + if (Op == AVR::ORIRdK && ImmVal == 0x0) + return true; + + return false; +} + +bool AVRExpandPseudo:: expandLogicImm(unsigned Op, Block &MBB, BlockIt MBBI) { MachineInstr &MI = *MBBI; unsigned DstLoReg, DstHiReg; @@ -212,21 +223,25 @@ expandLogicImm(unsigned Op, Block &MBB, BlockIt MBBI) { unsigned Hi8 = (Imm >> 8) & 0xff; TRI->splitReg(DstReg, DstLoReg, DstHiReg); - auto MIBLO = buildMI(MBB, MBBI, Op) - .addReg(DstLoReg, RegState::Define | getDeadRegState(DstIsDead)) - .addReg(DstLoReg, getKillRegState(SrcIsKill)) - .addImm(Lo8); + if (!isLogicImmOpRedundant(Op, Lo8)) { + auto MIBLO = buildMI(MBB, MBBI, Op) + .addReg(DstLoReg, RegState::Define | getDeadRegState(DstIsDead)) + .addReg(DstLoReg, getKillRegState(SrcIsKill)) + .addImm(Lo8); - // SREG is always implicitly dead - MIBLO->getOperand(3).setIsDead(); + // SREG is always implicitly dead + MIBLO->getOperand(3).setIsDead(); + } - auto MIBHI = buildMI(MBB, MBBI, Op) - .addReg(DstHiReg, RegState::Define | getDeadRegState(DstIsDead)) - .addReg(DstHiReg, getKillRegState(SrcIsKill)) - .addImm(Hi8); + if (!isLogicImmOpRedundant(Op, Hi8)) { + auto MIBHI = buildMI(MBB, MBBI, Op) + .addReg(DstHiReg, RegState::Define | getDeadRegState(DstIsDead)) + .addReg(DstHiReg, getKillRegState(SrcIsKill)) + .addImm(Hi8); - if (ImpIsDead) - MIBHI->getOperand(3).setIsDead(); + if (ImpIsDead) + MIBHI->getOperand(3).setIsDead(); + } MI.eraseFromParent(); return true; |

