|
|
22033d |
commit 14041afe24556efd5845564aa183b6451fd9d6cc
|
|
|
22033d |
Author: law <law@138bc75d-0d04-0410-961f-82ee72b054a4>
|
|
|
22033d |
Date: Thu Feb 1 16:22:56 2018 +0000
|
|
|
22033d |
|
|
|
22033d |
PR target/84128
|
|
|
22033d |
* config/i386/i386.c (release_scratch_register_on_entry): Add new
|
|
|
22033d |
OFFSET and RELEASE_VIA_POP arguments. Use SP+OFFSET to restore
|
|
|
22033d |
the scratch if RELEASE_VIA_POP is false.
|
|
|
22033d |
(ix86_adjust_stack_and_probe_stack_clash): Un-constify SIZE.
|
|
|
22033d |
If we have to save a temporary register, decrement SIZE appropriately.
|
|
|
22033d |
Pass new arguments to release_scratch_register_on_entry.
|
|
|
22033d |
(ix86_adjust_stack_and_probe): Likewise.
|
|
|
22033d |
(ix86_emit_probe_stack_range): Pass new arguments to
|
|
|
22033d |
release_scratch_register_on_entry.
|
|
|
22033d |
|
|
|
22033d |
PR target/84128
|
|
|
22033d |
* gcc.target/i386/pr84128.c: New test.
|
|
|
22033d |
|
|
|
22033d |
diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
|
|
|
22033d |
index 2fe2a0c..c25d26c 100644
|
|
|
22033d |
--- a/gcc/config/i386/i386.c
|
|
|
22033d |
+++ b/gcc/config/i386/i386.c
|
|
|
22033d |
@@ -10182,22 +10182,39 @@ get_scratch_register_on_entry (struct scratch_reg *sr)
|
|
|
22033d |
}
|
|
|
22033d |
}
|
|
|
22033d |
|
|
|
22033d |
-/* Release a scratch register obtained from the preceding function. */
|
|
|
22033d |
+/* Release a scratch register obtained from the preceding function.
|
|
|
22033d |
+
|
|
|
22033d |
+ If RELEASE_VIA_POP is true, we just pop the register off the stack
|
|
|
22033d |
+ to release it. This is what non-Linux systems use with -fstack-check.
|
|
|
22033d |
+
|
|
|
22033d |
+ Otherwise we use OFFSET to locate the saved register and the
|
|
|
22033d |
+ allocated stack space becomes part of the local frame and is
|
|
|
22033d |
+ deallcated by the epilogue. */
|
|
|
22033d |
|
|
|
22033d |
static void
|
|
|
22033d |
-release_scratch_register_on_entry (struct scratch_reg *sr)
|
|
|
22033d |
+release_scratch_register_on_entry (struct scratch_reg *sr, HOST_WIDE_INT offset,
|
|
|
22033d |
+ bool release_via_pop)
|
|
|
22033d |
{
|
|
|
22033d |
if (sr->saved)
|
|
|
22033d |
{
|
|
|
22033d |
- struct machine_function *m = cfun->machine;
|
|
|
22033d |
- rtx x, insn = emit_insn (gen_pop (sr->reg));
|
|
|
22033d |
+ if (release_via_pop)
|
|
|
22033d |
+ {
|
|
|
22033d |
+ struct machine_function *m = cfun->machine;
|
|
|
22033d |
+ rtx x, insn = emit_insn (gen_pop (sr->reg));
|
|
|
22033d |
|
|
|
22033d |
- /* The RTX_FRAME_RELATED_P mechanism doesn't know about pop. */
|
|
|
22033d |
- RTX_FRAME_RELATED_P (insn) = 1;
|
|
|
22033d |
- x = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (UNITS_PER_WORD));
|
|
|
22033d |
- x = gen_rtx_SET (VOIDmode, stack_pointer_rtx, x);
|
|
|
22033d |
- add_reg_note (insn, REG_FRAME_RELATED_EXPR, x);
|
|
|
22033d |
- m->fs.sp_offset -= UNITS_PER_WORD;
|
|
|
22033d |
+ /* The RTX FRAME_RELATED_P mechanism doesn't know about pop. */
|
|
|
22033d |
+ RTX_FRAME_RELATED_P (insn) = 1;
|
|
|
22033d |
+ x = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (UNITS_PER_WORD));
|
|
|
22033d |
+ x = gen_rtx_SET (VOIDmode, stack_pointer_rtx, x);
|
|
|
22033d |
+ add_reg_note (insn, REG_FRAME_RELATED_EXPR, x);
|
|
|
22033d |
+ m->fs.sp_offset -= UNITS_PER_WORD;
|
|
|
22033d |
+ }
|
|
|
22033d |
+ else
|
|
|
22033d |
+ {
|
|
|
22033d |
+ rtx x = gen_rtx_PLUS (Pmode, stack_pointer_rtx, GEN_INT (offset));
|
|
|
22033d |
+ x = gen_rtx_SET (VOIDmode, sr->reg, gen_rtx_MEM (word_mode, x));
|
|
|
22033d |
+ emit_insn (x);
|
|
|
22033d |
+ }
|
|
|
22033d |
}
|
|
|
22033d |
}
|
|
|
22033d |
|
|
|
22033d |
@@ -10212,7 +10229,7 @@ release_scratch_register_on_entry (struct scratch_reg *sr)
|
|
|
22033d |
pushed on the stack. */
|
|
|
22033d |
|
|
|
22033d |
static void
|
|
|
22033d |
-ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size,
|
|
|
22033d |
+ix86_adjust_stack_and_probe_stack_clash (HOST_WIDE_INT size,
|
|
|
22033d |
const bool int_registers_saved)
|
|
|
22033d |
{
|
|
|
22033d |
struct machine_function *m = cfun->machine;
|
|
|
22033d |
@@ -10331,6 +10348,12 @@ ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size,
|
|
|
22033d |
struct scratch_reg sr;
|
|
|
22033d |
get_scratch_register_on_entry (&sr);
|
|
|
22033d |
|
|
|
22033d |
+ /* If we needed to save a register, then account for any space
|
|
|
22033d |
+ that was pushed (we are not going to pop the register when
|
|
|
22033d |
+ we do the restore). */
|
|
|
22033d |
+ if (sr.saved)
|
|
|
22033d |
+ size -= UNITS_PER_WORD;
|
|
|
22033d |
+
|
|
|
22033d |
/* Step 1: round SIZE down to a multiple of the interval. */
|
|
|
22033d |
HOST_WIDE_INT rounded_size = size & -probe_interval;
|
|
|
22033d |
|
|
|
22033d |
@@ -10379,7 +10402,9 @@ ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size,
|
|
|
22033d |
m->fs.cfa_reg == stack_pointer_rtx);
|
|
|
22033d |
dump_stack_clash_frame_info (PROBE_LOOP, size != rounded_size);
|
|
|
22033d |
|
|
|
22033d |
- release_scratch_register_on_entry (&sr);
|
|
|
22033d |
+ /* This does not deallocate the space reserved for the scratch
|
|
|
22033d |
+ register. That will be deallocated in the epilogue. */
|
|
|
22033d |
+ release_scratch_register_on_entry (&sr, size, false);
|
|
|
22033d |
}
|
|
|
22033d |
|
|
|
22033d |
/* Make sure nothing is scheduled before we are done. */
|
|
|
22033d |
@@ -10392,7 +10417,7 @@ ix86_adjust_stack_and_probe_stack_clash (const HOST_WIDE_INT size,
|
|
|
22033d |
pushed on the stack. */
|
|
|
22033d |
|
|
|
22033d |
static void
|
|
|
22033d |
-ix86_adjust_stack_and_probe (const HOST_WIDE_INT size,
|
|
|
22033d |
+ix86_adjust_stack_and_probe (HOST_WIDE_INT size,
|
|
|
22033d |
const bool int_registers_saved)
|
|
|
22033d |
{
|
|
|
22033d |
/* We skip the probe for the first interval + a small dope of 4 words and
|
|
|
22033d |
@@ -10465,6 +10490,11 @@ ix86_adjust_stack_and_probe (const HOST_WIDE_INT size,
|
|
|
22033d |
|
|
|
22033d |
get_scratch_register_on_entry (&sr);
|
|
|
22033d |
|
|
|
22033d |
+ /* If we needed to save a register, then account for any space
|
|
|
22033d |
+ that was pushed (we are not going to pop the register when
|
|
|
22033d |
+ we do the restore). */
|
|
|
22033d |
+ if (sr.saved)
|
|
|
22033d |
+ size -= UNITS_PER_WORD;
|
|
|
22033d |
|
|
|
22033d |
/* Step 1: round SIZE to the previous multiple of the interval. */
|
|
|
22033d |
|
|
|
22033d |
@@ -10516,7 +10546,9 @@ ix86_adjust_stack_and_probe (const HOST_WIDE_INT size,
|
|
|
22033d |
(get_probe_interval ()
|
|
|
22033d |
+ dope))));
|
|
|
22033d |
|
|
|
22033d |
- release_scratch_register_on_entry (&sr);
|
|
|
22033d |
+ /* This does not deallocate the space reserved for the scratch
|
|
|
22033d |
+ register. That will be deallocated in the epilogue. */
|
|
|
22033d |
+ release_scratch_register_on_entry (&sr, size, false);
|
|
|
22033d |
}
|
|
|
22033d |
|
|
|
22033d |
gcc_assert (cfun->machine->fs.cfa_reg != stack_pointer_rtx);
|
|
|
22033d |
@@ -10669,7 +10701,7 @@ ix86_emit_probe_stack_range (HOST_WIDE_INT first, HOST_WIDE_INT size,
|
|
|
22033d |
sr.reg),
|
|
|
22033d |
rounded_size - size));
|
|
|
22033d |
|
|
|
22033d |
- release_scratch_register_on_entry (&sr);
|
|
|
22033d |
+ release_scratch_register_on_entry (&sr, size, true);
|
|
|
22033d |
}
|
|
|
22033d |
|
|
|
22033d |
/* Make sure nothing is scheduled before we are done. */
|
|
|
22033d |
diff --git a/gcc/testsuite/gcc.target/i386/pr84128.c b/gcc/testsuite/gcc.target/i386/pr84128.c
|
|
|
22033d |
new file mode 100644
|
|
|
22033d |
index 0000000..a8323fd
|
|
|
22033d |
--- /dev/null
|
|
|
22033d |
+++ b/gcc/testsuite/gcc.target/i386/pr84128.c
|
|
|
22033d |
@@ -0,0 +1,30 @@
|
|
|
22033d |
+/* { dg-do run } */
|
|
|
22033d |
+/* { dg-options "-O2 -march=i686 -mtune=generic -fstack-clash-protection" } */
|
|
|
22033d |
+/* { dg-require-effective-target ia32 } */
|
|
|
22033d |
+
|
|
|
22033d |
+__attribute__ ((noinline, noclone, weak, regparm (3)))
|
|
|
22033d |
+int
|
|
|
22033d |
+f1 (long arg0, int (*pf) (long, void *))
|
|
|
22033d |
+{
|
|
|
22033d |
+ unsigned char buf[32768];
|
|
|
22033d |
+ return pf (arg0, buf);
|
|
|
22033d |
+}
|
|
|
22033d |
+
|
|
|
22033d |
+__attribute__ ((noinline, noclone, weak))
|
|
|
22033d |
+int
|
|
|
22033d |
+f2 (long arg0, void *ignored)
|
|
|
22033d |
+{
|
|
|
22033d |
+ if (arg0 != 17)
|
|
|
22033d |
+ __builtin_abort ();
|
|
|
22033d |
+ return 19;
|
|
|
22033d |
+}
|
|
|
22033d |
+
|
|
|
22033d |
+int
|
|
|
22033d |
+main (void)
|
|
|
22033d |
+{
|
|
|
22033d |
+ if (f1 (17, f2) != 19)
|
|
|
22033d |
+ __builtin_abort ();
|
|
|
22033d |
+ return 0;
|
|
|
22033d |
+}
|
|
|
22033d |
+
|
|
|
22033d |
+
|