Blame SOURCES/gcc48-rh1469697-21.patch

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