From 6abce7391ae63fd2808aa471aa9dd2679eb00496 Mon Sep 17 00:00:00 2001 From: Andrey Belevantsev Date: Mon, 9 Apr 2018 13:19:50 +0300 Subject: [PATCH] re PR rtl-optimization/80463 (ICE with -fselective-scheduling2 and -fvar-tracking-assignments) PR rtl-optimization/80463 PR rtl-optimization/83972 PR rtl-optimization/83480 * sel-sched-ir.c (has_dependence_note_mem_dep): Take into account the correct producer for the insn. (tidy_control_flow): Fixup seqnos in case of debug insns. * gcc.dg/pr80463.c: New test. * g++.dg/pr80463.C: Likewise. * gcc.dg/pr83972.c: Likewise. From-SVN: r259231 --- gcc/ChangeLog | 10 +++++++ gcc/sel-sched-ir.c | 34 +++++++++++++++++---- gcc/testsuite/ChangeLog | 10 +++++++ gcc/testsuite/g++.dg/pr80463.C | 20 +++++++++++++ gcc/testsuite/gcc.dg/pr80463.c | 54 ++++++++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/pr83972.c | 26 ++++++++++++++++ 6 files changed, 149 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr80463.C create mode 100644 gcc/testsuite/gcc.dg/pr80463.c create mode 100644 gcc/testsuite/gcc.dg/pr83972.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a22c610bab7..eef1fe43d62 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2018-04-09 Andrey Belevantsev + + PR rtl-optimization/80463 + PR rtl-optimization/83972 + PR rtl-optimization/83480 + + * sel-sched-ir.c (has_dependence_note_mem_dep): Take into account the + correct producer for the insn. + (tidy_control_flow): Fixup seqnos in case of debug insns. + 2018-04-09 Andrey Belevantsev PR rtl-optimization/83913 diff --git a/gcc/sel-sched-ir.c b/gcc/sel-sched-ir.c index 6f1e5a1f90d..ee970522890 100644 --- a/gcc/sel-sched-ir.c +++ b/gcc/sel-sched-ir.c @@ -3297,11 +3297,22 @@ has_dependence_note_mem_dep (rtx mem ATTRIBUTE_UNUSED, /* Note a dependence. */ static void -has_dependence_note_dep (insn_t pro ATTRIBUTE_UNUSED, - ds_t ds ATTRIBUTE_UNUSED) -{ - if (!sched_insns_conditions_mutex_p (has_dependence_data.pro, - VINSN_INSN_RTX (has_dependence_data.con))) +has_dependence_note_dep (insn_t pro, ds_t ds ATTRIBUTE_UNUSED) +{ + insn_t real_pro = has_dependence_data.pro; + insn_t real_con = VINSN_INSN_RTX (has_dependence_data.con); + + /* We do not allow for debug insns to move through others unless they + are at the start of bb. This movement may create bookkeeping copies + that later would not be able to move up, violating the invariant + that a bookkeeping copy should be movable as the original insn. + Detect that here and allow that movement if we allowed it before + in the first place. */ + if (DEBUG_INSN_P (real_con) + && INSN_UID (NEXT_INSN (pro)) == INSN_UID (real_con)) + return; + + if (!sched_insns_conditions_mutex_p (real_pro, real_con)) { ds_t *dsp = &has_dependence_data.has_dep_p[has_dependence_data.where]; @@ -3898,6 +3909,19 @@ tidy_control_flow (basic_block xbb, bool full_tidying) gcc_assert (EDGE_SUCC (xbb->prev_bb, 0)->flags & EDGE_FALLTHRU); + /* We could have skipped some debug insns which did not get removed with the block, + and the seqnos could become incorrect. Fix them up here. */ + if (MAY_HAVE_DEBUG_INSNS && (sel_bb_head (xbb) != first || sel_bb_end (xbb) != last)) + { + if (!sel_bb_empty_p (xbb->prev_bb)) + { + int prev_seqno = INSN_SEQNO (sel_bb_end (xbb->prev_bb)); + if (prev_seqno > INSN_SEQNO (sel_bb_head (xbb))) + for (insn_t insn = sel_bb_head (xbb); insn != first; insn = NEXT_INSN (insn)) + INSN_SEQNO (insn) = prev_seqno + 1; + } + } + /* It can turn out that after removing unused jump, basic block that contained that jump, becomes empty too. In such case remove it too. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2de94af83e2..f89ddfe7e9a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2018-04-09 Andrey Belevantsev + + PR rtl-optimization/80463 + PR rtl-optimization/83972 + PR rtl-optimization/83480 + + * gcc.dg/pr80463.c: New test. + * g++.dg/pr80463.C: Likewise. + * gcc.dg/pr83972.c: Likewise. + 2018-04-09 Andrey Belevantsev PR rtl-optimization/83913 diff --git a/gcc/testsuite/g++.dg/pr80463.C b/gcc/testsuite/g++.dg/pr80463.C new file mode 100644 index 00000000000..f4ea65ac5c0 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr80463.C @@ -0,0 +1,20 @@ +/* { dg-do compile { target powerpc*-*-* ia64-*-* i?86-*-* x86_64-*-* } } */ +/* { dg-options "-g -fselective-scheduling2 -O2 -fvar-tracking-assignments" } */ + +int *a; +int b, c; +void +d () +{ + for (int e; c; e++) + switch (e) + { + case 0: + a[e] = 1; + case 1: + b = 2; + break; + default: + a[e] = 3; + } +} diff --git a/gcc/testsuite/gcc.dg/pr80463.c b/gcc/testsuite/gcc.dg/pr80463.c new file mode 100644 index 00000000000..cebf2fef1f3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr80463.c @@ -0,0 +1,54 @@ +/* { dg-do compile { target powerpc*-*-* ia64-*-* i?86-*-* x86_64-*-* } } */ +/* { dg-options "-g -O2 -fvar-tracking-assignments -fselective-scheduling2 -ftree-loop-vectorize -fnon-call-exceptions -fno-tree-vrp -fno-gcse-lm -fno-tree-loop-im -fno-reorder-blocks-and-partition -fno-reorder-blocks -fno-move-loop-invariants -w" } */ + +short int t2; +int cd, aa, ft; + +void +dh (void) +{ + int qs = 0; + + if (t2 < 1) + { + int bq = 0; + + while (bq < 1) + { + } + + while (t2 < 1) + { + if (t2 == 0) + { + bq = 0; + cd = !!cd; + } + else + { + bq = 1; + cd = bq > qs; + } + + t2 += cd; + bq = (t2 / qs) == bq; + + if (aa != ft) + { + qs %= 0; + while (bq != 0) + { + ro: + ; + } + } + + ++t2; + } + + ia: + goto ro; + } + + goto ia; +} diff --git a/gcc/testsuite/gcc.dg/pr83972.c b/gcc/testsuite/gcc.dg/pr83972.c new file mode 100644 index 00000000000..b8de42cef0a --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr83972.c @@ -0,0 +1,26 @@ +/* { dg-do compile { target powerpc*-*-* ia64-*-* i?86-*-* x86_64-*-* } } */ +/* { dg-options "-O1 -fschedule-insns -fselective-scheduling -fsel-sched-pipelining -fvar-tracking-assignments -funroll-loops -fno-tree-dominator-opts -w" } */ + +int s7, p0; + +void +i0 (int ke) +{ + while (ke < 1) + { + if (s7 == 0) + p0 = 0; + else + { + if (p0 == 0) + s7 = 0; + + if (!!s7 || !!p0) + s7 = 0; + else + p0 = 0; + } + + ++ke; + } +} -- 2.30.2