diff options
author | Richard Sandiford <rsandifo@linux.vnet.ibm.com> | 2013-08-05 11:03:20 +0000 |
---|---|---|
committer | Richard Sandiford <rsandifo@linux.vnet.ibm.com> | 2013-08-05 11:03:20 +0000 |
commit | 9b05c709c65ba05645853ca49bc2a1ea8b554f37 (patch) | |
tree | c04c8f0d7f35c746616d7099f030b0ae55cc6a35 /lib/Target/SystemZ/SystemZElimCompare.cpp | |
parent | 0e4044c233d10596578df35bae2483fbe4e8a507 (diff) | |
download | llvm-9b05c709c65ba05645853ca49bc2a1ea8b554f37.tar.gz llvm-9b05c709c65ba05645853ca49bc2a1ea8b554f37.tar.bz2 llvm-9b05c709c65ba05645853ca49bc2a1ea8b554f37.tar.xz |
[SystemZ] Use LOAD AND TEST to eliminate comparisons against zero
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187720 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/SystemZ/SystemZElimCompare.cpp')
-rw-r--r-- | lib/Target/SystemZ/SystemZElimCompare.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/Target/SystemZ/SystemZElimCompare.cpp b/lib/Target/SystemZ/SystemZElimCompare.cpp index 9b0bdd8505..bcdc5b728f 100644 --- a/lib/Target/SystemZ/SystemZElimCompare.cpp +++ b/lib/Target/SystemZ/SystemZElimCompare.cpp @@ -46,6 +46,7 @@ namespace { bool runOnMachineFunction(MachineFunction &F); private: + bool convertToLoadAndTest(MachineInstr *MI); bool adjustCCMasksForInstr(MachineInstr *MI, MachineInstr *Compare, SmallVectorImpl<MachineInstr *> &CCUsers); bool optimizeCompareZero(MachineInstr *Compare, @@ -83,9 +84,34 @@ static bool resultTests(MachineInstr *MI, unsigned Reg, unsigned SubReg) { MI->getOperand(0).getSubReg() == SubReg) return true; + switch (MI->getOpcode()) { + case SystemZ::LR: + case SystemZ::LGR: + case SystemZ::LGFR: + case SystemZ::LTR: + case SystemZ::LTGR: + case SystemZ::LTGFR: + if (MI->getOperand(1).getReg() == Reg && + MI->getOperand(1).getSubReg() == SubReg) + return true; + } + return false; } +// If MI is a load instruction, try to convert it into a LOAD AND TEST. +// Return true on success. +bool SystemZElimCompare::convertToLoadAndTest(MachineInstr *MI) { + unsigned Opcode = TII->getLoadAndTest(MI->getOpcode()); + if (!Opcode) + return false; + + MI->setDesc(TII->get(Opcode)); + MachineInstrBuilder(*MI->getParent()->getParent(), MI) + .addReg(SystemZ::CC, RegState::ImplicitDefine); + return true; +} + // The CC users in CCUsers are testing the result of a comparison of some // value X against zero and we know that any CC value produced by MI // would also reflect the value of X. Try to adjust CCUsers so that @@ -184,17 +210,21 @@ optimizeCompareZero(MachineInstr *Compare, unsigned SrcSubReg = Compare->getOperand(0).getSubReg(); MachineBasicBlock *MBB = Compare->getParent(); MachineBasicBlock::iterator MBBI = Compare, MBBE = MBB->begin(); + bool SeenUseOfCC = false; while (MBBI != MBBE) { --MBBI; MachineInstr *MI = MBBI; if (resultTests(MI, SrcReg, SrcSubReg) && - adjustCCMasksForInstr(MI, Compare, CCUsers)) { + ((!SeenUseOfCC && convertToLoadAndTest(MI)) || + adjustCCMasksForInstr(MI, Compare, CCUsers))) { EliminatedComparisons += 1; return true; } if (MI->modifiesRegister(SrcReg, TRI) || MI->modifiesRegister(SystemZ::CC, TRI)) return false; + if (MI->readsRegister(SystemZ::CC, TRI)) + SeenUseOfCC = true; } return false; } |