[llvm] r259553 - [X86] Fix the merging of SP updates in prologue/epilogue insertions.

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 2 12:11:17 PST 2016


Author: qcolombet
Date: Tue Feb  2 14:11:17 2016
New Revision: 259553

URL: http://llvm.org/viewvc/llvm-project?rev=259553&view=rev
Log:
[X86] Fix the merging of SP updates in prologue/epilogue insertions.
When the merging was involving LEAs, we were taking the wrong immediate
from the list of operands.

rdar://problem/24446069

Added:
    llvm/trunk/test/CodeGen/X86/merge-sp-update-lea.ll
Modified:
    llvm/trunk/lib/Target/X86/X86FrameLowering.cpp

Modified: llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FrameLowering.cpp?rev=259553&r1=259552&r2=259553&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FrameLowering.cpp Tue Feb  2 14:11:17 2016
@@ -376,12 +376,17 @@ int X86FrameLowering::mergeSPUpdates(Mac
   int Offset = 0;
 
   if ((Opc == X86::ADD64ri32 || Opc == X86::ADD64ri8 ||
-       Opc == X86::ADD32ri || Opc == X86::ADD32ri8 ||
-       Opc == X86::LEA32r || Opc == X86::LEA64_32r) &&
+       Opc == X86::ADD32ri || Opc == X86::ADD32ri8) &&
       PI->getOperand(0).getReg() == StackPtr){
     Offset += PI->getOperand(2).getImm();
     MBB.erase(PI);
     if (!doMergeWithPrevious) MBBI = NI;
+  } else if ((Opc == X86::LEA32r || Opc == X86::LEA64_32r) &&
+             PI->getOperand(0).getReg() == StackPtr) {
+    // For LEAs we have: def = lea SP, FI, noreg, Offset, noreg.
+    Offset += PI->getOperand(4).getImm();
+    MBB.erase(PI);
+    if (!doMergeWithPrevious) MBBI = NI;
   } else if ((Opc == X86::SUB64ri32 || Opc == X86::SUB64ri8 ||
               Opc == X86::SUB32ri || Opc == X86::SUB32ri8) &&
              PI->getOperand(0).getReg() == StackPtr) {

Added: llvm/trunk/test/CodeGen/X86/merge-sp-update-lea.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/merge-sp-update-lea.ll?rev=259553&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/merge-sp-update-lea.ll (added)
+++ llvm/trunk/test/CodeGen/X86/merge-sp-update-lea.ll Tue Feb  2 14:11:17 2016
@@ -0,0 +1,32 @@
+; RUN: llc %s -o - | FileCheck %s
+target datalayout = "e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128"
+target triple = "i386-apple-macosx"
+
+; Check that the merging of SP updates, when LEAs are involved, happen
+; correctly.
+; CHECK-LABEL: useLEA:
+; CHECK: calll L_realloc
+; Make sure that the offset we get here is 8 + 16.
+; We used to have 8 + 1 because we were not reading the right immediate form
+; the LEA instruction.
+; CHECK-NEXT: leal 24(%esp), %esp
+define noalias i8* @useLEA(i8* nocapture %p, i32 %nbytes) #0 {
+entry:
+  %cmp = icmp slt i32 %nbytes, 0
+  br i1 %cmp, label %cond.end.3, label %cond.false
+
+cond.false:                                       ; preds = %entry
+  %tobool = icmp ne i32 %nbytes, 0
+  %cond = select i1 %tobool, i32 %nbytes, i32 1
+  %call = tail call i8* @realloc(i8* %p, i32 %cond)
+  br label %cond.end.3
+
+cond.end.3:                                       ; preds = %entry, %cond.false
+  %cond4 = phi i8* [ %call, %cond.false ], [ null, %entry ]
+  ret i8* %cond4
+}
+
+; Function Attrs: nounwind optsize
+declare noalias i8* @realloc(i8* nocapture, i32)
+
+attributes #0 = { nounwind optsize ssp "disable-tail-calls"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "target-features"="+lea-sp" }




More information about the llvm-commits mailing list