"growing" :)<div><br></div><div><br><br><div class="gmail_quote"><div dir="ltr">On Sun, Jun 18, 2017, 6:53 PM Tony Jiang via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">jtony created this revision.<br>
<br>
1. The available program storage region of the red zone to compilers is 288 bytes rather than 244 bytes.<br>
  1. The formula for negative number alignment calculation should be y = x & ~(n-1) rather than y = (x + (n-1)) & ~(n-1).<br>
<br>
<br>
<a href="https://reviews.llvm.org/D34337" rel="noreferrer" target="_blank">https://reviews.llvm.org/D34337</a><br>
<br>
Files:<br>
  lib/Target/PowerPC/PPCFrameLowering.cpp<br>
  test/CodeGen/PowerPC/svr4-redzone.ll<br>
  test/CodeGen/PowerPC/tailcall1-64.ll<br>
<br>
<br>
Index: test/CodeGen/PowerPC/tailcall1-64.ll<br>
===================================================================<br>
--- test/CodeGen/PowerPC/tailcall1-64.ll<br>
+++ test/CodeGen/PowerPC/tailcall1-64.ll<br>
@@ -1,11 +1,14 @@<br>
 ; RUN: llc -relocation-model=static -verify-machineinstrs < %s -march=ppc64 -tailcallopt | grep TC_RETURNd8<br>
+; RUN: llc -relocation-model=static -verify-machineinstrs -march=ppc64 < %s | FileCheck %s<br>
 define fastcc i32 @tailcallee(i32 %a1, i32 %a2, i32 %a3, i32 %a4) {<br>
 entry:<br>
        ret i32 %a3<br>
 }<br>
<br>
 define fastcc i32 @tailcaller(i32 %in1, i32 %in2) {<br>
 entry:<br>
-       %tmp11 = tail call fastcc i32 @tailcallee( i32 %in1, i32 %in2, i32 %in1, i32 %in2 )             ; <i32> [#uses=1]<br>
+       %tmp11 = tail call fastcc i32 @tailcallee( i32 %in1, i32 %in2, i32 %in1, i32 %in2 )<br>
        ret i32 %tmp11<br>
+; CHECK-NOT: stdu<br>
+; CHECK: b tailcallee<br>
 }<br>
Index: test/CodeGen/PowerPC/svr4-redzone.ll<br>
===================================================================<br>
--- test/CodeGen/PowerPC/svr4-redzone.ll<br>
+++ test/CodeGen/PowerPC/svr4-redzone.ll<br>
@@ -29,11 +29,11 @@<br>
<br>
 define i8* @bigstack() nounwind {<br>
 entry:<br>
- %0 = alloca i8, i32 230<br>
+ %0 = alloca i8, i32 290<br>
        ret i8* %0<br>
 }<br>
 ; PPC32-LABEL: bigstack:<br>
-; PPC32: stwu 1, -240(1)<br>
+; PPC32: stwu 1, -304(1)<br>
<br>
 ; PPC64-LABEL: bigstack:<br>
-; PPC64: stdu 1, -288(1)<br>
+; PPC64: stdu 1, -352(1)<br>
Index: lib/Target/PowerPC/PPCFrameLowering.cpp<br>
===================================================================<br>
--- lib/Target/PowerPC/PPCFrameLowering.cpp<br>
+++ lib/Target/PowerPC/PPCFrameLowering.cpp<br>
@@ -435,7 +435,7 @@<br>
<br>
   const PPCRegisterInfo *RegInfo = Subtarget.getRegisterInfo();<br>
<br>
-  // If we are a leaf function, and use up to 224 bytes of stack space,<br>
+  // If we are a leaf function, and use up to 288 bytes of stack space,<br>
   // don't have a frame pointer, calls, or dynamic alloca then we do not need<br>
   // to adjust the stack pointer (we fit in the Red Zone).<br>
   // The 32-bit SVR4 ABI has no Red Zone. However, it can still generate<br>
@@ -446,7 +446,7 @@<br>
       (Subtarget.isPPC64() ||                      // 32-bit SVR4, no stack-<br>
        !Subtarget.isSVR4ABI() ||                   //   allocated locals.<br>
         FrameSize == 0) &&<br>
-      FrameSize <= 224 &&                          // Fits in red zone.<br>
+      FrameSize <= 288 &&                          // Fits in red zone.<br>
       !MFI.hasVarSizedObjects() &&                 // No dynamic alloca.<br>
       !MFI.adjustsStack() &&                       // No calls.<br>
       !MustSaveLR(MF, LR) &&<br>
@@ -1869,8 +1869,12 @@<br>
   }<br>
<br>
   if (HasVRSaveArea) {<br>
-    // Insert alignment padding, we need 16-byte alignment.<br>
-    LowerBound = (LowerBound - 15) & ~(15);<br>
+    // Insert alignment padding, we need 16-byte alignment. Note: for postive<br>
+    // number the alignment formula is : y = x + (n-1) & ~(n-1). But since we<br>
+    // are using negative number here (the stack is growning down). We should<br>
+    // use formula : y = x & ~(n-1). Where x is the size before aligning, n is<br>
+    // the alignment size ( n = 16 here) and y is the size after aligning.<br>
+    LowerBound &= ~(15);<br>
<br>
     for (unsigned i = 0, e = VRegs.size(); i != e; ++i) {<br>
       int FI = VRegs[i].getFrameIdx();<br>
<br>
<br>
</blockquote></div></div>