From 5637379000b9a40f2bfee8ea238dc0d3955535ce Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Sat, 11 Feb 2012 00:44:19 +0000 Subject: Allow Post-RA LICM to hoist reserved register reads. When using register masks, registers like %rip are clobbered by the register mask. LICM should still be able to hoist instructions reading %rip from a loop containing calls. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150288 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MachineLICM.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/CodeGen/MachineLICM.cpp b/lib/CodeGen/MachineLICM.cpp index fda60563ed..47eb685db3 100644 --- a/lib/CodeGen/MachineLICM.cpp +++ b/lib/CodeGen/MachineLICM.cpp @@ -68,6 +68,7 @@ namespace { MachineRegisterInfo *MRI; const InstrItineraryData *InstrItins; bool PreRegAlloc; + BitVector ReservedRegs; // Various analyses that we use... AliasAnalysis *AA; // Alias analysis info. @@ -337,6 +338,8 @@ bool MachineLICM::runOnMachineFunction(MachineFunction &MF) { for (TargetRegisterInfo::regclass_iterator I = TRI->regclass_begin(), E = TRI->regclass_end(); I != E; ++I) RegLimit[(*I)->getID()] = TRI->getRegPressureLimit(*I, MF); + } else { + ReservedRegs = TRI->getReservedRegs(MF); } // Get our Loop information... @@ -426,6 +429,9 @@ void MachineLICM::ProcessMI(MachineInstr *MI, "Not expecting virtual register!"); if (!MO.isDef()) { + // Allow reserved register reads to be hoisted. + if (ReservedRegs.test(Reg)) + continue; if (Reg && (PhysRegDefs.test(Reg) || PhysRegClobbers.test(Reg))) // If it's using a non-loop-invariant register, then it's obviously not // safe to hoist. @@ -531,6 +537,11 @@ void MachineLICM::HoistRegionPostRA() { const MachineOperand &MO = MI->getOperand(j); if (!MO.isReg() || MO.isDef() || !MO.getReg()) continue; + // Allow hoisting of reserved register reads that aren't call preserved. + // For example %rip. + // IsLoopInvariantInst() already checks MRI->isConstantPhysReg(). + if (ReservedRegs.test(MO.getReg())) + continue; if (PhysRegDefs.test(MO.getReg()) || PhysRegClobbers.test(MO.getReg())) { // If it's using a non-loop-invariant register, then it's obviously -- cgit v1.2.3