e987aff
commit e7519110827a59eb7275591db640bdbdfd31ba15
e987aff
Author: law <law@138bc75d-0d04-0410-961f-82ee72b054a4>
e987aff
Date:   Wed Sep 20 05:43:28 2017 +0000
e987aff
e987aff
            * combine-stack-adj.c (combine_stack_adjustments_for_block): Do
e987aff
            nothing for stack adjustments with REG_STACK_CHECK.
e987aff
            * sched-deps.c (parse_add_or_inc): Reject insns with
e987aff
            REG_STACK_CHECK from dependency breaking.
e987aff
            * config/i386/i386.c (pro_epilogue_adjust_stack): Return insn.
e987aff
            (ix86_adjust_satck_and_probe_stack_clash): Add REG_STACK_NOTEs.
e987aff
            * reg-notes.def (STACK_CHECK): New note.
e987aff
    
e987aff
            * gcc.target/i386/stack-check-11.c: New test.
e987aff
    
e987aff
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@252999 138bc75d-0d04-0410-961f-82ee72b054a4
e987aff
e987aff
diff --git a/gcc/combine-stack-adj.c b/gcc/combine-stack-adj.c
e987aff
index 9ec14a3e443..82d6dba856f 100644
e987aff
--- a/gcc/combine-stack-adj.c
e987aff
+++ b/gcc/combine-stack-adj.c
e987aff
@@ -508,6 +508,8 @@ combine_stack_adjustments_for_block (basic_block bb)
e987aff
 	continue;
e987aff
 
e987aff
       set = single_set_for_csa (insn);
e987aff
+      if (set && find_reg_note (insn, REG_STACK_CHECK, NULL_RTX))
e987aff
+	set = NULL_RTX;
e987aff
       if (set)
e987aff
 	{
e987aff
 	  rtx dest = SET_DEST (set);
e987aff
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
e987aff
index 088dca2001f..5aff9b9d113 100644
e987aff
--- a/gcc/config/i386/i386.c
e987aff
+++ b/gcc/config/i386/i386.c
e987aff
@@ -12900,7 +12900,7 @@ ix86_add_queued_cfa_restore_notes (rtx insn)
e987aff
    zero if %r11 register is live and cannot be freely used and positive
e987aff
    otherwise.  */
e987aff
 
e987aff
-static void
e987aff
+static rtx
e987aff
 pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset,
e987aff
 			   int style, bool set_cfa)
e987aff
 {
e987aff
@@ -12987,6 +12987,7 @@ pro_epilogue_adjust_stack (rtx dest, rtx src, rtx offset,
e987aff
       m->fs.sp_offset = ooffset - INTVAL (offset);
e987aff
       m->fs.sp_valid = valid;
e987aff
     }
e987aff
+  return insn;
e987aff
 }
e987aff
 
e987aff
 /* Find an available register to be used as dynamic realign argument
e987aff
@@ -13333,9 +13334,11 @@ ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size)
e987aff
       for (i = probe_interval; i <= size; i += probe_interval)
e987aff
 	{
e987aff
 	  /* Allocate PROBE_INTERVAL bytes.  */
e987aff
-	  pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
e987aff
-				     GEN_INT (-probe_interval), -1,
e987aff
-				     m->fs.cfa_reg == stack_pointer_rtx);
e987aff
+	  rtx insn
e987aff
+	    = pro_epilogue_adjust_stack (stack_pointer_rtx, stack_pointer_rtx,
e987aff
+					 GEN_INT (-PROBE_INTERVAL), -1,
e987aff
+					 m->fs.cfa_reg == stack_pointer_rtx);
e987aff
+	  add_reg_note (insn, REG_STACK_CHECK, const0_rtx);
e987aff
 
e987aff
 	  /* And probe at *sp.  */
e987aff
 	  emit_stack_probe (stack_pointer_rtx);
e987aff
diff --git a/gcc/reg-notes.def b/gcc/reg-notes.def
e987aff
index 8734d26e5b4..18cf7e3cfc0 100644
e987aff
--- a/gcc/reg-notes.def
e987aff
+++ b/gcc/reg-notes.def
e987aff
@@ -223,6 +223,10 @@ REG_NOTE (ARGS_SIZE)
e987aff
    pseudo reg.  */
e987aff
 REG_NOTE (RETURNED)
e987aff
 
e987aff
+/* Indicates the instruction is a stack check probe that should not
e987aff
+   be combined with other stack adjustments.  */
e987aff
+REG_NOTE (STACK_CHECK)
e987aff
+
e987aff
 /* Used to mark a call with the function decl called by the call.
e987aff
    The decl might not be available in the call due to splitting of the call
e987aff
    insn.  This note is a SYMBOL_REF.  */
e987aff
diff --git a/gcc/sched-deps.c b/gcc/sched-deps.c
e987aff
index b2393bf28fb..564f3fb1559 100644
e987aff
--- a/gcc/sched-deps.c
e987aff
+++ b/gcc/sched-deps.c
e987aff
@@ -4717,6 +4717,11 @@ parse_add_or_inc (struct mem_inc_info *mii, rtx_insn *insn, bool before_mem)
e987aff
   if (RTX_FRAME_RELATED_P (insn) || !pat)
e987aff
     return false;
e987aff
 
e987aff
+  /* Do not allow breaking data dependencies for insns that are marked
e987aff
+     with REG_STACK_CHECK.  */
e987aff
+  if (find_reg_note (insn, REG_STACK_CHECK, NULL))
e987aff
+    return false;
e987aff
+
e987aff
   /* Result must be single reg.  */
e987aff
   if (!REG_P (SET_DEST (pat)))
e987aff
     return false;
e987aff
diff --git a/gcc/testsuite/gcc.target/i386/stack-check-11.c b/gcc/testsuite/gcc.target/i386/stack-check-11.c
e987aff
new file mode 100644
e987aff
index 00000000000..183103f01e5
e987aff
--- /dev/null
e987aff
+++ b/gcc/testsuite/gcc.target/i386/stack-check-11.c
e987aff
@@ -0,0 +1,16 @@
e987aff
+/* { dg-do compile } */
e987aff
+/* { dg-options "-O2 -fstack-clash-protection" } */
e987aff
+/* { dg-require-effective-target supports_stack_clash_protection } */
e987aff
+
e987aff
+extern void arf (unsigned long int *, unsigned long int *);
e987aff
+void
e987aff
+frob ()
e987aff
+{
e987aff
+  unsigned long int num[859];
e987aff
+  unsigned long int den[859];
e987aff
+  arf (den, num);
e987aff
+}
e987aff
+
e987aff
+/* { dg-final { scan-assembler-times "subq" 4 } } */
e987aff
+/* { dg-final { scan-assembler-times "orq" 3 } } */
e987aff
+