diff mbox

[05/05] Fix PR 69102

Message ID 0ad96ef3-4296-d9db-7576-4366c83d0912@ispras.ru
State New
Headers show

Commit Message

Andrey Belevantsev March 14, 2016, 9:52 a.m. UTC
Hello,

The problem here is readonly dependence contexts in selective scheduler. 
We're trying to cache the effect of initializing a dependence context with 
remembering that context and setting a readonly bit on it.  When first 
moving the insn 43 with REG_ARGS_SIZE note through the insn 3 (a simple eax 
set) we also set the last_args_size field of the context.  Later, when we 
make a copy of insn 43 and try to move it again through insn 3, we take the 
cached dependency context and notice the (fake) dep with last_args_size 
insn, which is the old insn 43.  Then the assert saying that we should be 
able to lift the bookkeeping copy up the same way as we did with the 
original insn breaks.

Fixed by the attached patch that makes us notice only deps with the current 
producer insn.

Ok for trunk?

gcc/

2016-03-14  Andrey Belevantsev  <abel@ispras.ru>

	PR rtl-optimization/69102
	* sel-sched.c (has_dependence_note_dep): Only take into
	account dependencies produced by the current producer insn.
	(has_dependence_note_mem_dep): Likewise.

testsuite/

2016-03-14  Andrey Belevantsev  <abel@ispras.ru>

	PR rtl-optimization/69102
	* gcc.c-torture/compile/pr69102.c: New test.

Best,
Andrey
diff mbox

Patch

diff --git a/gcc/sel-sched-ir.c b/gcc/sel-sched-ir.c
index c1a9e55..b4aa933 100644
--- a/gcc/sel-sched-ir.c
+++ b/gcc/sel-sched-ir.c
@@ -3277,9 +3277,14 @@  has_dependence_note_reg_use (int regno)
 static void
 has_dependence_note_mem_dep (rtx mem ATTRIBUTE_UNUSED,
 			     rtx pending_mem ATTRIBUTE_UNUSED,
-			     insn_t pending_insn ATTRIBUTE_UNUSED,
+			     insn_t pending_insn,
 			     ds_t ds ATTRIBUTE_UNUSED)
 {
+  /* We're only interested in dependencies with the current producer.
+     We might get other insns that were saved in dependence context
+     as last_* or pending_* fields.  */
+  if (INSN_UID (pending_insn) != INSN_UID (has_dependence_data.pro))
+    return;
   if (!sched_insns_conditions_mutex_p (has_dependence_data.pro,
 				       VINSN_INSN_RTX (has_dependence_data.con)))
     {
@@ -3291,9 +3296,14 @@  has_dependence_note_mem_dep (rtx mem ATTRIBUTE_UNUSED,
 
 /* Note a dependence.  */
 static void
-has_dependence_note_dep (insn_t pro ATTRIBUTE_UNUSED,
+has_dependence_note_dep (insn_t pro,
 			 ds_t ds ATTRIBUTE_UNUSED)
 {
+  /* We're only interested in dependencies with the current producer.
+     We might get other insns that were saved in dependence context
+     as last_* or pending_* fields.  */
+  if (INSN_UID (pro) != INSN_UID (has_dependence_data.pro))
+    return;
   if (!sched_insns_conditions_mutex_p (has_dependence_data.pro,
 				       VINSN_INSN_RTX (has_dependence_data.con)))
     {
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr69102.c b/gcc/testsuite/gcc.c-torture/compile/pr69102.c
new file mode 100644
index 0000000..b1328ca
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr69102.c
@@ -0,0 +1,21 @@ 
+/* { dg-options "-Og -fPIC -fschedule-insns2 -fselective-scheduling2 -fno-tree-fre --param=max-sched-extend-regions-iters=10" } */
+void bar (unsigned int);
+
+void
+foo (void)
+{
+  char buf[1] = { 3 };
+  const char *p = buf;
+  const char **q = &p;
+  unsigned int ch;
+  switch (**q)
+    {
+    case 1:  ch = 5; break;
+    case 2:  ch = 4; break;
+    case 3:  ch = 3; break;
+    case 4:  ch = 2; break;
+    case 5:  ch = 1; break;
+    default: ch = 0; break;
+    }
+  bar (ch);
+}