XCore target: Optimise entsp / retsp selection
[oota-llvm.git] / lib / Target / XCore / XCoreFrameLowering.cpp
index 22d0e6604bddbf288f1767dc91992023997c6423..3d1fb9cafc13d6726ab5c25585de6ecc75688fd8 100644 (file)
@@ -427,12 +427,20 @@ processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
                                      RegScavenger *RS) const {
   XCoreFunctionInfo *XFI = MF.getInfo<XCoreFunctionInfo>();
 
+  bool LRUsed = MF.getRegInfo().isPhysRegUsed(XCore::LR);
+  // If we need to extend the stack it is more efficient to use entsp / retsp.
+  // We force the LR to be saved so these instructions are used.
+  if (!LRUsed && !MF.getFunction()->isVarArg() &&
+      MF.getFrameInfo()->estimateStackSize(MF))
+    LRUsed = true;
+
   // We will handling LR in the prologue/epilogue
   // and space on the stack ourselves.
-  if (MF.getRegInfo().isPhysRegUsed(XCore::LR)) {
+  if (LRUsed) {
     MF.getRegInfo().setPhysRegUnused(XCore::LR);
     XFI->createLRSpillSlot(MF);
   }
+
   // A callee save register is used to hold the FP.
   // This needs saving / restoring in the epilogue / prologue.
   if (hasFP(MF))