Blame SOURCES/gcc48-rh1469697-21.patch

85359c
	PR middle-end/83654
85359c
	* explow.c (anti_adjust_stack_and_probe_stack_clash): Test a
85359c
	non-constant residual for zero at runtime and avoid probing in
85359c
	that case.  Reorganize code for trailing problem to mirror handling
85359c
	of the residual.
85359c
85359c
	PR middle-end/83654
85359c
	* gcc.target/i386/stack-check-18.c: New test.
85359c
	* gcc.target/i386/stack-check-19.c: New test.
85359c
85359c
diff --git a/gcc/explow.c b/gcc/explow.c
85359c
index b6c56602152..042e71904ec 100644
85359c
--- a/gcc/explow.c
85359c
+++ b/gcc/explow.c
85359c
@@ -1997,11 +1997,27 @@ anti_adjust_stack_and_probe_stack_clash (rtx size)
85359c
 
85359c
   if (residual != CONST0_RTX (Pmode))
85359c
     {
85359c
+      rtx label = NULL_RTX;
85359c
+      /* RESIDUAL could be zero at runtime and in that case *sp could
85359c
+	 hold live data.  Furthermore, we do not want to probe into the
85359c
+	 red zone.
85359c
+
85359c
+	 Go ahead and just guard the probe at *sp on RESIDUAL != 0 at
85359c
+	 runtime if RESIDUAL is not a compile time constant.  */
85359c
+      if (!CONST_INT_P (residual))
85359c
+	{
85359c
+	  label = gen_label_rtx ();
85359c
+	  emit_cmp_and_jump_insns (residual, CONST0_RTX (GET_MODE (residual)),
85359c
+				   EQ, NULL_RTX, Pmode, 1, label);
85359c
+	}
85359c
+
85359c
       rtx x = force_reg (Pmode, plus_constant (Pmode, residual,
85359c
 					       -GET_MODE_SIZE (word_mode)));
85359c
       anti_adjust_stack (residual);
85359c
       emit_stack_probe (gen_rtx_PLUS (Pmode, stack_pointer_rtx, x));
85359c
       emit_insn (gen_blockage ());
85359c
+      if (!CONST_INT_P (residual))
85359c
+	emit_label (label);
85359c
     }
85359c
 
85359c
   /* Some targets make optimistic assumptions in their prologues about
85359c
@@ -2014,28 +2030,20 @@ anti_adjust_stack_and_probe_stack_clash (rtx size)
85359c
 	 live data.  Furthermore, we don't want to probe into the red
85359c
 	 zone.
85359c
 
85359c
-	 Go ahead and just guard a probe at *sp on SIZE != 0 at runtime
85359c
+	 Go ahead and just guard the probe at *sp on SIZE != 0 at runtime
85359c
 	 if SIZE is not a compile time constant.  */
85359c
-
85359c
-      /* Ideally we would just probe at *sp.  However, if SIZE is not
85359c
-	 a compile-time constant, but is zero at runtime, then *sp
85359c
-	 might hold live data.  So probe at *sp if we know that
85359c
-	 an allocation was made, otherwise probe into the red zone
85359c
-	 which is obviously undesirable.  */
85359c
-      if (CONST_INT_P (size))
85359c
-	{
85359c
-	  emit_stack_probe (stack_pointer_rtx);
85359c
-	  emit_insn (gen_blockage ());
85359c
-	}
85359c
-      else
85359c
+      rtx label = NULL_RTX;
85359c
+      if (!CONST_INT_P (size))
85359c
 	{
85359c
-	  rtx label = gen_label_rtx ();
85359c
+	  label = gen_label_rtx ();
85359c
 	  emit_cmp_and_jump_insns (size, CONST0_RTX (GET_MODE (size)),
85359c
 				   EQ, NULL_RTX, Pmode, 1, label);
85359c
-	  emit_stack_probe (stack_pointer_rtx);
85359c
-	  emit_insn (gen_blockage ());
85359c
-	  emit_label (label);
85359c
 	}
85359c
+
85359c
+      emit_stack_probe (stack_pointer_rtx);
85359c
+      emit_insn (gen_blockage ());
85359c
+      if (!CONST_INT_P (size))
85359c
+	emit_label (label);
85359c
     }
85359c
 }
85359c
 
85359c
diff --git a/gcc/testsuite/gcc.target/i386/stack-check-18.c b/gcc/testsuite/gcc.target/i386/stack-check-18.c
85359c
new file mode 100644
85359c
index 00000000000..6dbff4402da
85359c
--- /dev/null
85359c
+++ b/gcc/testsuite/gcc.target/i386/stack-check-18.c
85359c
@@ -0,0 +1,23 @@
85359c
+/* { dg-do compile } */
85359c
+/* { dg-options "-O2 -fstack-clash-protection -mtune=generic -fdump-rtl-expand" } */
85359c
+/* { dg-require-effective-target supports_stack_clash_protection } */
85359c
+
85359c
+int f1 (char *);
85359c
+
85359c
+int
85359c
+f2 (void)
85359c
+{
85359c
+  const int size = 4096;
85359c
+  char buffer[size];
85359c
+  return f1 (buffer);
85359c
+}
85359c
+
85359c
+/* So we want to verify that at expand time that we probed the main
85359c
+   VLA allocation as well as the residuals.  Then we want to verify
85359c
+   there was only one probe in the final assembly (implying the
85359c
+   residual probe was optimized away).  */
85359c
+/* { dg-final { scan-rtl-dump-times "allocation and probing in loop" 1 "expand" } } */
85359c
+/* { dg-final { scan-rtl-dump-times "allocation and probing residuals" 1 "expand" } } */
85359c
+
85359c
+/* { dg-final { scan-assembler-times "or\[ql\]" 1 } } */
85359c
+
85359c
diff --git a/gcc/testsuite/gcc.target/i386/stack-check-19.c b/gcc/testsuite/gcc.target/i386/stack-check-19.c
85359c
new file mode 100644
85359c
index 00000000000..b92c126d57f
85359c
--- /dev/null
85359c
+++ b/gcc/testsuite/gcc.target/i386/stack-check-19.c
85359c
@@ -0,0 +1,29 @@
85359c
+/* { dg-do compile } */
85359c
+/* { dg-options "-O2 -fstack-clash-protection -mtune=generic -fdump-rtl-expand" } */
85359c
+/* { dg-require-effective-target supports_stack_clash_protection } */
85359c
+
85359c
+int f1 (char *);
85359c
+
85359c
+int
85359c
+f2 (const int size)
85359c
+{
85359c
+  char buffer[size];
85359c
+  return f1 (buffer);
85359c
+}
85359c
+
85359c
+/* So we want to verify that at expand time that we probed the main
85359c
+   VLA allocation as well as the residuals.  Then we want to verify
85359c
+   there are two probes in the final assembly code.  */
85359c
+/* { dg-final { scan-rtl-dump-times "allocation and probing in loop" 1 "expand" } } */
85359c
+/* { dg-final { scan-rtl-dump-times "allocation and probing residuals" 1 "expand" } } */
85359c
+/* { dg-final { scan-assembler-times "or\[ql\]" 2 } } */
85359c
+
85359c
+/* We also want to verify (indirectly) that the residual probe is
85359c
+   guarded.  We do that by checking the number of conditional
85359c
+   branches.  There should be 3.  One that bypasses the probe loop, one
85359c
+   in the probe loop and one that bypasses the residual probe.
85359c
+
85359c
+   These will all be equality tests.  */
85359c
+/* { dg-final { scan-assembler-times "(\?:je|jne)" 3 } } */
85359c
+
85359c
+