llvm.org GIT mirror llvm / 1b26fdb
Merging r196046: ------------------------------------------------------------------------ r196046 | tnorthover | 2013-12-01 06:16:24 -0800 (Sun, 01 Dec 2013) | 8 lines ARM: fix bug in -Oz stack adjustment folding Previously, we clobbered callee-saved registers when folding an "add sp, #N" into a "pop {rD, ...}" instruction. This change checks whether a register we're going to add to the "pop" could actually be live outside the function before doing so and should fix the issue. This should fix PR18081. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_34@196074 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 6 years ago
5 changed file(s) with 28 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
19121912
19131913 MachineBasicBlock *MBB = MI->getParent();
19141914 const TargetRegisterInfo *TRI = MF.getRegInfo().getTargetRegisterInfo();
1915 const MCPhysReg *CSRegs = TRI->getCalleeSavedRegs(&MF);
19151916
19161917 // Now try to find enough space in the reglist to allocate NumBytes.
19171918 for (unsigned CurReg = FirstReg - 1; CurReg >= RD0Reg && RegsNeeded;
1918 --CurReg, --RegsNeeded) {
1919 --CurReg) {
19191920 if (!IsPop) {
19201921 // Pushing any register is completely harmless, mark the
19211922 // register involved as undef since we don't care about it in
19221923 // the slightest.
19231924 RegList.push_back(MachineOperand::CreateReg(CurReg, false, false,
19241925 false, false, true));
1926 --RegsNeeded;
19251927 continue;
19261928 }
19271929
1928 // However, we can only pop an extra register if it's not live. Otherwise we
1929 // might clobber a return value register. We assume that once we find a live
1930 // return register all lower ones will be too so there's no use proceeding.
1931 if (MBB->computeRegisterLiveness(TRI, CurReg, MI) !=
1932 MachineBasicBlock::LQR_Dead)
1933 return false;
1930 // However, we can only pop an extra register if it's not live. For
1931 // registers live within the function we might clobber a return value
1932 // register; the other way a register can be live here is if it's
1933 // callee-saved.
1934 if (isCalleeSavedRegister(CurReg, CSRegs) ||
1935 MBB->computeRegisterLiveness(TRI, CurReg, MI) !=
1936 MachineBasicBlock::LQR_Dead) {
1937 // VFP pops don't allow holes in the register list, so any skip is fatal
1938 // for our transformation. GPR pops do, so we should just keep looking.
1939 if (IsVFPPushPop)
1940 return false;
1941 else
1942 continue;
1943 }
19341944
19351945 // Mark the unimportant registers as in the POP.
19361946 RegList.push_back(MachineOperand::CreateReg(CurReg, true, false, false,
19371947 true));
1948 --RegsNeeded;
19381949 }
19391950
19401951 if (RegsNeeded > 0)
6969 default:
7070 return false;
7171 }
72 }
73
74 static inline bool isCalleeSavedRegister(unsigned Reg,
75 const MCPhysReg *CSRegs) {
76 for (unsigned i = 0; CSRegs[i]; ++i)
77 if (Reg == CSRegs[i])
78 return true;
79 return false;
7280 }
7381
7482 class ARMBaseRegisterInfo : public ARMGenRegisterInfo {
7979 bool
8080 ARMFrameLowering::canSimplifyCallFramePseudos(const MachineFunction &MF) const {
8181 return hasReservedCallFrame(MF) || MF.getFrameInfo()->hasVarSizedObjects();
82 }
83
84 static bool isCalleeSavedRegister(unsigned Reg, const uint16_t *CSRegs) {
85 for (unsigned i = 0; CSRegs[i]; ++i)
86 if (Reg == CSRegs[i])
87 return true;
88 return false;
8982 }
9083
9184 static bool isCSRestore(MachineInstr *MI,
214214 AFI->setShouldRestoreSPFromFP(true);
215215 }
216216
217 static bool isCalleeSavedRegister(unsigned Reg, const uint16_t *CSRegs) {
218 for (unsigned i = 0; CSRegs[i]; ++i)
219 if (Reg == CSRegs[i])
220 return true;
221 return false;
222 }
223
224217 static bool isCSRestore(MachineInstr *MI, const uint16_t *CSRegs) {
225218 if (MI->getOpcode() == ARM::tLDRspi &&
226219 MI->getOperand(1).isFI() &&
1414 ; CHECK-NOT: sub sp, sp,
1515 ; ...
1616 ; CHECK-NOT: add sp, sp,
17 ; CHECK: pop.w {r7, r8, r9, r10, r11, pc}
17 ; CHECK: pop.w {r0, r1, r2, r3, r11, pc}
1818
1919 ; CHECK-T1-LABEL: check_simple:
2020 ; CHECK-T1: push {r3, r4, r5, r6, r7, lr}
2222 ; CHECK-T1-NOT: sub sp, sp,
2323 ; ...
2424 ; CHECK-T1-NOT: add sp, sp,
25 ; CHECK-T1: pop {r3, r4, r5, r6, r7, pc}
25 ; CHECK-T1: pop {r0, r1, r2, r3, r7, pc}
2626
2727 ; iOS always has a frame pointer and messing with the push affects
2828 ; how it's set in the prologue. Make sure we get that right.