ARM: fix folding of stack-adjustment (yet again).
authorTim Northover <tnorthover@apple.com>
Sun, 8 Dec 2013 15:56:50 +0000 (15:56 +0000)
committerTim Northover <tnorthover@apple.com>
Sun, 8 Dec 2013 15:56:50 +0000 (15:56 +0000)
When trying to eliminate an "sub sp, sp, #N" instruction by folding
it into an existing push/pop using dummy registers, we need to account
for the fact that this might affect precisely how "fp" gets set in the
prologue.

We were attempting this, but assuming that *whenever* we performed a
fold it would make a difference. This is false, for example, in:
    push {r4, r7, lr}
    add fp, sp, #4
    vpush {d8}
    sub sp, sp, #8

we can fold the "sub" into the "vpush", forming "vpush {d7, d8}".
However, in that case the "add fp" instruction mustn't change, which
we were getting wrong before.

Should fix PR18160.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196725 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMFrameLowering.cpp
test/CodeGen/ARM/fold-stack-adjust.ll

index 79e5de14ddd837d28f0e3b043f1ffb7b70e7f3b8..ceff79068521c8713059a0323f5d7487d81d22a5 100644 (file)
@@ -256,9 +256,10 @@ void ARMFrameLowering::emitPrologue(MachineFunction &MF) const {
 
   if (NumBytes) {
     // Adjust SP after all the callee-save spills.
-    if (tryFoldSPUpdateIntoPushPop(STI, MF, LastPush, NumBytes))
-      FramePtrOffsetInPush += NumBytes;
-    else
+    if (tryFoldSPUpdateIntoPushPop(STI, MF, LastPush, NumBytes)) {
+      if (LastPush == FramePtrPush)
+        FramePtrOffsetInPush += NumBytes;
+    } else
       emitSPUpdate(isARM, MBB, MBBI, dl, TII, -NumBytes,
                    MachineInstr::FrameSetup);
 
index 8c60bca1db05fe00ec7ce630e53d1f900fca89fb..67fd129fd1c90ff7cc15863213dbd4a52f4a536d 100644 (file)
@@ -137,6 +137,15 @@ define void @test_fold_point(i1 %tst) minsize {
 ; CHECK: {{LBB[0-9]+_2}}:
 ; CHECK-NEXT: vpop {d7, d8}
 ; CHECK-NEXT: pop {r4, pc}
+
+  ; With a guaranteed frame-pointer, we want to make sure that its offset in the
+  ; push block is correct, even if a few registers have been tacked onto a later
+  ; vpush (PR18160).
+; CHECK-IOS-LABEL: test_fold_point:
+; CHECK-IOS: push {r4, r7, lr}
+; CHECK-IOS-NEXT: add r7, sp, #4
+; CHECK-IOS-NEXT: vpush {d7, d8}
+
   ; We want some memory so there's a stack adjustment to fold...
   %var = alloca i8, i32 8