diff options
| author | Gabor Greif <ggreif@gmail.com> | 2010-09-29 10:12:08 +0000 |
|---|---|---|
| committer | Gabor Greif <ggreif@gmail.com> | 2010-09-29 10:12:08 +0000 |
| commit | d36e3e8850c51b16703f8855b1351973d8021270 (patch) | |
| tree | b30866af5a5c72c24a7753c499453004e444fc15 /llvm/lib | |
| parent | 16be34dec04dd1f8f8f75934135944ba3042e274 (diff) | |
| download | bcm5719-llvm-d36e3e8850c51b16703f8855b1351973d8021270.tar.gz bcm5719-llvm-d36e3e8850c51b16703f8855b1351973d8021270.zip | |
improve heuristics to find the 'and' corresponding to 'tst' to also catch opportunities on thumb2
added some doxygen on the way
llvm-svn: 115033
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp index c38b89534bf..26558d900d8 100644 --- a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp +++ b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp @@ -1433,16 +1433,29 @@ AnalyzeCompare(const MachineInstr *MI, unsigned &SrcReg, int &CmpMask, return false; } -static bool isSuitableForMask(const MachineInstr &MI, unsigned SrcReg, +/// isSuitableForMask - Identify a suitable 'and' instruction that +/// operates on the given source register and applies the same mask +/// as a 'tst' instruction. Provide a limited look-through for copies. +/// When successful, MI will hold the found instruction. +static bool isSuitableForMask(MachineInstr *&MI, unsigned SrcReg, int CmpMask, bool CommonUse) { - switch (MI.getOpcode()) { + switch (MI->getOpcode()) { case ARM::ANDri: case ARM::t2ANDri: - if (CmpMask != MI.getOperand(2).getImm()) + if (CmpMask != MI->getOperand(2).getImm()) return false; - if (SrcReg == MI.getOperand(CommonUse ? 1 : 0).getReg()) + if (SrcReg == MI->getOperand(CommonUse ? 1 : 0).getReg()) return true; break; + case ARM::COPY: { + // Walk down one instruction which is potentially an 'and'. + const MachineInstr &Copy = *MI; + MachineBasicBlock::iterator AND(next(MachineBasicBlock::iterator(MI))); + if (AND == MI->getParent()->end()) return false; + MI = AND; + return isSuitableForMask(MI, Copy.getOperand(0).getReg(), + CmpMask, true); + } } return false; @@ -1467,16 +1480,15 @@ OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, int CmpMask, // Masked compares sometimes use the same register as the corresponding 'and'. if (CmpMask != ~0) { - if (!isSuitableForMask(*MI, SrcReg, CmpMask, false)) { + if (!isSuitableForMask(MI, SrcReg, CmpMask, false)) { MI = 0; for (MachineRegisterInfo::use_iterator UI = MRI.use_begin(SrcReg), UE = MRI.use_end(); UI != UE; ++UI) { if (UI->getParent() != CmpInstr->getParent()) continue; - MachineInstr &PotentialAND = *UI; + MachineInstr *PotentialAND = &*UI; if (!isSuitableForMask(PotentialAND, SrcReg, CmpMask, true)) continue; - SrcReg = PotentialAND.getOperand(0).getReg(); - MI = &PotentialAND; + MI = PotentialAND; break; } if (!MI) return false; |

