Bug fix on function epilog optimization (ARM backend)

To save a 'add sp,#val' instruction by adding registers to the final pop instruction,
the first register transferred by this pop instruction need to be found.
If the function to be optimized has a non-void return value, the operand list contains
r0 (implicit) which prevents the optimization to take place.
Therefore implicit register references should be skipped in the search loop,
because this registers are never popped from the stack.

Patch by Rainer Herbertz (rOptimizer)!

Differential revision: https://reviews.llvm.org/D66730

llvm-svn: 370728
This commit is contained in:
Oliver Stannard 2019-09-03 09:51:19 +00:00
parent 855caf2335
commit 39bf484d92
2 changed files with 16 additions and 2 deletions

View File

@ -2420,7 +2420,8 @@ bool llvm::tryFoldSPUpdateIntoPushPop(const ARMSubtarget &Subtarget,
MachineOperand &MO = MI->getOperand(i);
RegList.push_back(MO);
if (MO.isReg() && TRI->getEncodingValue(MO.getReg()) < FirstRegEnc)
if (MO.isReg() && !MO.isImplicit() &&
TRI->getEncodingValue(MO.getReg()) < FirstRegEnc)
FirstRegEnc = TRI->getEncodingValue(MO.getReg());
}
@ -2430,7 +2431,7 @@ bool llvm::tryFoldSPUpdateIntoPushPop(const ARMSubtarget &Subtarget,
for (int CurRegEnc = FirstRegEnc - 1; CurRegEnc >= 0 && RegsNeeded;
--CurRegEnc) {
unsigned CurReg = RegClass->getRegister(CurRegEnc);
if (IsT1PushPop && CurReg > ARM::R7)
if (IsT1PushPop && CurRegEnc > TRI->getEncodingValue(ARM::R7))
continue;
if (!IsPop) {
// Pushing any register is completely harmless, mark the register involved

View File

@ -42,6 +42,19 @@ define void @check_simple() minsize {
ret void
}
define i32 @check_simple_ret() minsize {
; CHECK-FNSTART-LABEL: check_simple_ret:
; CHECK: push {r5, r6, r7, lr}
; CHECK-NOT: sub sp,
; ...
; CHECK-NOT: add sp,
; CHECK: pop {r2, r3, r7, pc}
%var = alloca i8, i32 8
call void @bar(i8* %var)
ret i32 0
}
define void @check_simple_too_big() minsize {
; CHECK-FNSTART-LABEL: check_simple_too_big:
; CHECK: push {r7, lr}