Blame SOURCES/gcc48-rh1537828-2.patch

4dd737
commit f7765f70e0e254fd9ce4469c7281c69cd06c9467
4dd737
Author: law <law@138bc75d-0d04-0410-961f-82ee72b054a4>
4dd737
Date:   Wed Jan 24 21:57:16 2018 +0000
4dd737
4dd737
            PR target/83994
4dd737
            * i386.c (get_probe_interval): Move to earlier point.
4dd737
            (ix86_compute_frame_layout): If -fstack-clash-protection and
4dd737
            the frame is larger than the probe interval, then use pushes
4dd737
            to save registers rather than reg->mem moves.
4dd737
            (ix86_expand_prologue): Remove conditional for int_registers_saved
4dd737
            assertion.
4dd737
4dd737
            PR target/83994
4dd737
            * gcc.target/i386/pr83994.c: New test.
4dd737
4dd737
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
4dd737
index 15cfe83..5230227 100644
4dd737
--- a/gcc/config/i386/i386.c
4dd737
+++ b/gcc/config/i386/i386.c
4dd737
@@ -9371,6 +9371,18 @@ ix86_builtin_setjmp_frame_value (void)
4dd737
   return stack_realign_fp ? hard_frame_pointer_rtx : virtual_stack_vars_rtx;
4dd737
 }
4dd737
 
4dd737
+/* Return the probing interval for -fstack-clash-protection.  */
4dd737
+
4dd737
+static HOST_WIDE_INT
4dd737
+get_probe_interval (void)
4dd737
+{
4dd737
+  if (flag_stack_clash_protection)
4dd737
+    return (HOST_WIDE_INT_1U
4dd737
+	    << PARAM_VALUE (PARAM_STACK_CLASH_PROTECTION_PROBE_INTERVAL));
4dd737
+  else
4dd737
+    return (HOST_WIDE_INT_1U << STACK_CHECK_PROBE_INTERVAL_EXP);
4dd737
+}
4dd737
+
4dd737
 /* When using -fsplit-stack, the allocation routines set a field in
4dd737
    the TCB to the bottom of the stack plus this much space, measured
4dd737
    in bytes.  */
4dd737
@@ -9545,7 +9557,15 @@ ix86_compute_frame_layout (struct ix86_frame *frame)
4dd737
   to_allocate = offset - frame->sse_reg_save_offset;
4dd737
 
4dd737
   if ((!to_allocate && frame->nregs <= 1)
4dd737
-      || (TARGET_64BIT && to_allocate >= (HOST_WIDE_INT) 0x80000000))
4dd737
+      || (TARGET_64BIT && to_allocate >= (HOST_WIDE_INT) 0x80000000)
4dd737
+      /* If stack clash probing needs a loop, then it needs a
4dd737
+	 scratch register.  But the returned register is only guaranteed
4dd737
+	 to be safe to use after register saves are complete.  So if
4dd737
+	 stack clash protections are enabled and the allocated frame is
4dd737
+	 larger than the probe interval, then use pushes to save
4dd737
+	 callee saved registers.  */
4dd737
+      || (flag_stack_clash_protection && to_allocate > get_probe_interval ()))
4dd737
+
4dd737
     frame->save_regs_using_mov = false;
4dd737
 
4dd737
   if (ix86_using_red_zone ()
4dd737
@@ -10181,18 +10201,6 @@ release_scratch_register_on_entry (struct scratch_reg *sr)
4dd737
     }
4dd737
 }
4dd737
 
4dd737
-/* Return the probing interval for -fstack-clash-protection.  */
4dd737
-
4dd737
-static HOST_WIDE_INT
4dd737
-get_probe_interval (void)
4dd737
-{
4dd737
-  if (flag_stack_clash_protection)
4dd737
-    return (HOST_WIDE_INT_1U
4dd737
-	    << PARAM_VALUE (PARAM_STACK_CLASH_PROTECTION_PROBE_INTERVAL));
4dd737
-  else
4dd737
-    return (HOST_WIDE_INT_1U << STACK_CHECK_PROBE_INTERVAL_EXP);
4dd737
-}
4dd737
-
4dd737
 /* Emit code to adjust the stack pointer by SIZE bytes while probing it.
4dd737
 
4dd737
    This differs from the next routine in that it tries hard to prevent
4dd737
@@ -11064,12 +11072,11 @@ ix86_expand_prologue (void)
4dd737
       && (flag_stack_check == STATIC_BUILTIN_STACK_CHECK
4dd737
 	  || flag_stack_clash_protection))
4dd737
     {
4dd737
-      /* This assert wants to verify that integer registers were saved
4dd737
-	 prior to probing.  This is necessary when probing may be implemented
4dd737
-	 as a function call (Windows).  It is not necessary for stack clash
4dd737
-	 protection probing.  */
4dd737
-      if (!flag_stack_clash_protection)
4dd737
-	gcc_assert (int_registers_saved);
4dd737
+      /* We expect the GP registers to be saved when probes are used
4dd737
+	 as the probing sequences might need a scratch register and
4dd737
+	 the routine to allocate one assumes the integer registers
4dd737
+	 have already been saved.  */
4dd737
+      gcc_assert (int_registers_saved);
4dd737
 
4dd737
       if (flag_stack_clash_protection)
4dd737
 	{
4dd737
diff --git a/gcc/testsuite/gcc.target/i386/pr83994.c b/gcc/testsuite/gcc.target/i386/pr83994.c
4dd737
new file mode 100644
4dd737
index 0000000..dc0b7cb
4dd737
--- /dev/null
4dd737
+++ b/gcc/testsuite/gcc.target/i386/pr83994.c
4dd737
@@ -0,0 +1,16 @@
4dd737
+/* { dg-do compile } */
4dd737
+/* { dg-options "-O2 -march=i686 -fpic -fstack-clash-protection" } */
4dd737
+/* { dg-require-effective-target ia32 } */
4dd737
+
4dd737
+void f1 (char *);
4dd737
+
4dd737
+__attribute__ ((regparm (3)))
4dd737
+int
4dd737
+f2 (int arg1, int arg2, int arg3)
4dd737
+{
4dd737
+  char buf[16384];
4dd737
+  f1 (buf);
4dd737
+  f1 (buf);
4dd737
+  return 0;
4dd737
+}
4dd737
+