From 337a31133bfe5b116c1005b7ebe766d499314098 Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Mon, 18 Oct 2010 21:22:31 +0000 Subject: [PATCH] Don't recompute MachineRegisterInfo in the Optimize* method. llvm-svn: 116750 --- llvm/include/llvm/Target/TargetInstrInfo.h | 1 + llvm/lib/CodeGen/PeepholeOptimizer.cpp | 2 +- llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp | 12 ++++++------ llvm/lib/Target/ARM/ARMBaseInstrInfo.h | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/llvm/include/llvm/Target/TargetInstrInfo.h b/llvm/include/llvm/Target/TargetInstrInfo.h index a2654c97de2a..6615ee4aacd0 100644 --- a/llvm/include/llvm/Target/TargetInstrInfo.h +++ b/llvm/include/llvm/Target/TargetInstrInfo.h @@ -600,6 +600,7 @@ public: /// *only* if a transformation took place. virtual bool OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, int Mask, int Value, + const MachineRegisterInfo *MRI, MachineBasicBlock::iterator &) const { return false; } diff --git a/llvm/lib/CodeGen/PeepholeOptimizer.cpp b/llvm/lib/CodeGen/PeepholeOptimizer.cpp index b24569233820..7ae6d5f78a68 100644 --- a/llvm/lib/CodeGen/PeepholeOptimizer.cpp +++ b/llvm/lib/CodeGen/PeepholeOptimizer.cpp @@ -247,7 +247,7 @@ bool PeepholeOptimizer::OptimizeCmpInstr(MachineInstr *MI, return false; // Attempt to optimize the comparison instruction. - if (TII->OptimizeCompareInstr(MI, SrcReg, CmpMask, CmpValue, NextIter)) { + if (TII->OptimizeCompareInstr(MI, SrcReg, CmpMask, CmpValue, MRI, NextIter)) { ++NumEliminated; return true; } diff --git a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp index 26b4f0e54c12..aca292abea56 100644 --- a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp +++ b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp @@ -1490,13 +1490,13 @@ static bool isSuitableForMask(MachineInstr *&MI, unsigned SrcReg, /// iterator *only* if a transformation took place. bool ARMBaseInstrInfo:: OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, int CmpMask, - int CmpValue, MachineBasicBlock::iterator &MII) const { + int CmpValue, const MachineRegisterInfo *MRI, + MachineBasicBlock::iterator &MII) const { if (CmpValue != 0) return false; - MachineRegisterInfo &MRI = CmpInstr->getParent()->getParent()->getRegInfo(); - MachineRegisterInfo::def_iterator DI = MRI.def_begin(SrcReg); - if (llvm::next(DI) != MRI.def_end()) + MachineRegisterInfo::def_iterator DI = MRI->def_begin(SrcReg); + if (llvm::next(DI) != MRI->def_end()) // Only support one definition. return false; @@ -1506,8 +1506,8 @@ OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, int CmpMask, if (CmpMask != ~0) { if (!isSuitableForMask(MI, SrcReg, CmpMask, false)) { MI = 0; - for (MachineRegisterInfo::use_iterator UI = MRI.use_begin(SrcReg), - UE = MRI.use_end(); UI != UE; ++UI) { + 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; if (!isSuitableForMask(PotentialAND, SrcReg, CmpMask, true)) diff --git a/llvm/lib/Target/ARM/ARMBaseInstrInfo.h b/llvm/lib/Target/ARM/ARMBaseInstrInfo.h index cbfd7529b13a..36be3366d29a 100644 --- a/llvm/lib/Target/ARM/ARMBaseInstrInfo.h +++ b/llvm/lib/Target/ARM/ARMBaseInstrInfo.h @@ -341,6 +341,7 @@ public: /// that we can remove a "comparison with zero". virtual bool OptimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg, int CmpMask, int CmpValue, + const MachineRegisterInfo *MRI, MachineBasicBlock::iterator &MII) const; virtual unsigned getNumMicroOps(const MachineInstr *MI,