Blame SOURCES/gcc48-rh1469697-21.patch

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