summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/ARM/ARMFrameLowering.cpp
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2017-07-28 01:36:32 +0000
committerMatthias Braun <matze@braunis.de>2017-07-28 01:36:32 +0000
commitc618a466f14248f33b8e125abc7c901c1142bda6 (patch)
tree7841d897d2afe983190b8b0339dd1273d11235b6 /llvm/lib/Target/ARM/ARMFrameLowering.cpp
parentfe33551051450b9729a1876370bd082893cfb297 (diff)
downloadbcm5719-llvm-c618a466f14248f33b8e125abc7c901c1142bda6.tar.gz
bcm5719-llvm-c618a466f14248f33b8e125abc7c901c1142bda6.zip
ARMFrameLowering: Only set ExtraCSSpill for actually unused registers.
The code assumed that unclobbered/unspilled callee saved registers are unused in the function. This is not true for callee saved registers that are also used to pass parameters such as swiftself. rdar://33401922 llvm-svn: 309350
Diffstat (limited to 'llvm/lib/Target/ARM/ARMFrameLowering.cpp')
-rw-r--r--llvm/lib/Target/ARM/ARMFrameLowering.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/llvm/lib/Target/ARM/ARMFrameLowering.cpp b/llvm/lib/Target/ARM/ARMFrameLowering.cpp
index b204faa76f8..12e6e329a92 100644
--- a/llvm/lib/Target/ARM/ARMFrameLowering.cpp
+++ b/llvm/lib/Target/ARM/ARMFrameLowering.cpp
@@ -1743,7 +1743,6 @@ void ARMFrameLowering::determineCalleeSaves(MachineFunction &MF,
(MFI.adjustsStack() && !canSimplifyCallFramePseudos(MF)) ||
// For large argument stacks fp relative addressed may overflow.
(HasFP && (MaxFixedOffset - MaxFPOffset) >= (int)EstimatedRSStackSizeLimit);
- bool ExtraCSSpill = false;
if (BigFrameOffsets ||
!CanEliminateFrame || RegInfo->cannotEliminateFrame(MF)) {
AFI->setHasStackFrame(true);
@@ -1768,6 +1767,10 @@ void ARMFrameLowering::determineCalleeSaves(MachineFunction &MF,
CS1Spilled = true;
}
+ // This is true when we inserted a spill for an unused register that can now
+ // be used for register scavenging.
+ bool ExtraCSSpill = false;
+
if (AFI->isThumb1OnlyFunction()) {
// For Thumb1-only targets, we need some low registers when we save and
// restore the high registers (which aren't allocatable, but could be
@@ -1870,7 +1873,9 @@ void ARMFrameLowering::determineCalleeSaves(MachineFunction &MF,
SavedRegs.set(Reg);
NumGPRSpills++;
CS1Spilled = true;
- ExtraCSSpill = true;
+ assert(!MRI.isReserved(Reg) && "Should not be reserved");
+ if (!MRI.isPhysRegUsed(Reg))
+ ExtraCSSpill = true;
UnspilledCS1GPRs.erase(llvm::find(UnspilledCS1GPRs, Reg));
if (Reg == ARM::LR)
LRSpilled = true;
@@ -1889,7 +1894,8 @@ void ARMFrameLowering::determineCalleeSaves(MachineFunction &MF,
UnspilledCS1GPRs.erase(LRPos);
ForceLRSpill = false;
- ExtraCSSpill = true;
+ if (!MRI.isReserved(ARM::LR) && !MRI.isPhysRegUsed(ARM::LR))
+ ExtraCSSpill = true;
}
// If stack and double are 8-byte aligned and we are spilling an odd number
@@ -1909,7 +1915,7 @@ void ARMFrameLowering::determineCalleeSaves(MachineFunction &MF,
SavedRegs.set(Reg);
DEBUG(dbgs() << "Spilling " << PrintReg(Reg, TRI)
<< " to make up alignment\n");
- if (!MRI.isReserved(Reg))
+ if (!MRI.isReserved(Reg) && !MRI.isPhysRegUsed(Reg))
ExtraCSSpill = true;
break;
}
@@ -1919,7 +1925,7 @@ void ARMFrameLowering::determineCalleeSaves(MachineFunction &MF,
SavedRegs.set(Reg);
DEBUG(dbgs() << "Spilling " << PrintReg(Reg, TRI)
<< " to make up alignment\n");
- if (!MRI.isReserved(Reg))
+ if (!MRI.isReserved(Reg) && !MRI.isPhysRegUsed(Reg))
ExtraCSSpill = true;
}
}
@@ -1955,11 +1961,14 @@ void ARMFrameLowering::determineCalleeSaves(MachineFunction &MF,
}
}
}
- if (Extras.size() && NumExtras == 0) {
- for (unsigned i = 0, e = Extras.size(); i != e; ++i) {
- SavedRegs.set(Extras[i]);
+ if (NumExtras == 0) {
+ for (unsigned Reg : Extras) {
+ SavedRegs.set(Reg);
+ if (!MRI.isPhysRegUsed(Reg))
+ ExtraCSSpill = true;
}
- } else if (!AFI->isThumb1OnlyFunction()) {
+ }
+ if (!ExtraCSSpill && !AFI->isThumb1OnlyFunction()) {
// note: Thumb1 functions spill to R12, not the stack. Reserve a slot
// closest to SP or frame pointer.
assert(RS && "Register scavenging not provided");
OpenPOWER on IntegriCloud