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
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());
}
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
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}