Bug 84566 - error: qsort comparator not anti-commutative: -1, -1 on aarch64 in sched1
Summary: error: qsort comparator not anti-commutative: -1, -1 on aarch64 in sched1
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: qsort_chk selective-scheduling
  Show dependency treegraph
 
Reported: 2018-02-26 08:48 UTC by Martin Liška
Modified: 2018-04-11 14:47 UTC (History)
2 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target: aarch64-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-02-26 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liška 2018-02-26 08:48:36 UTC
Following ICEs:

$ aarch64-linux-gnu-g++ /home/marxin/Programming/gcc/gcc/testsuite/g++.old-deja/g++.other/crash15.C /dev/null -mcpu=cortex-a35 -O2 -fselective-scheduling
/home/marxin/Programming/gcc/gcc/testsuite/g++.old-deja/g++.other/crash15.C: In function ‘void test05()’:
/home/marxin/Programming/gcc/gcc/testsuite/g++.old-deja/g++.other/crash15.C:43:1: error: qsort comparator not anti-commutative: -1, -1
 }
 ^
during RTL pass: sched1
/home/marxin/Programming/gcc/gcc/testsuite/g++.old-deja/g++.other/crash15.C:43:1: internal compiler error: qsort checking failed
0x5e693a qsort_chk_error
	.././../gcc/vec.c:201
0x15781dd qsort_chk(void*, unsigned long, unsigned long, int (*)(void const*, void const*))
	.././../gcc/vec.c:255
0xd77de4 vec<_expr*, va_heap, vl_embed>::qsort(int (*)(void const*, void const*))
	.././../gcc/vec.h:1054
0xd77de4 vec<_expr*, va_heap, vl_ptr>::qsort(int (*)(void const*, void const*))
	.././../gcc/vec.h:1816
0xd77de4 fill_vec_av_set
	.././../gcc/sel-sched.c:3953
0xd78df3 fill_ready_list
	.././../gcc/sel-sched.c:4027
0xd78df3 find_best_expr
	.././../gcc/sel-sched.c:4387
0xd78df3 fill_insns
	.././../gcc/sel-sched.c:5544
0xd7af80 schedule_on_fences
	.././../gcc/sel-sched.c:7361
0xd7af80 sel_sched_region_2
	.././../gcc/sel-sched.c:7499
0xd7d4b1 sel_sched_region_1
	.././../gcc/sel-sched.c:7541
0xd7d4b1 sel_sched_region(int)
	.././../gcc/sel-sched.c:7642
0xd7da99 run_selective_scheduling()
	.././../gcc/sel-sched.c:7718
0xd5a45d rest_of_handle_sched
	.././../gcc/sched-rgn.c:3715
0xd5a45d execute
	.././../gcc/sched-rgn.c:3825
Comment 1 Alexander Monakov 2018-02-26 11:07:26 UTC
Sorry, I cannot reproduce this. I've built a cross-compiler from today's trunk via 'configure --target aarch64-linux-gnu && make all-gcc' (i.e. just to cc1plus, no binutils etc.) and it doesn't abort.

If possible please add 'g++ -v' output, svn revision, and any other info that can help me reproduce the issue.
Comment 2 Alexander Monakov 2018-02-26 11:10:25 UTC
Bah, built a wrong branch, not the trunk. I'll recheck later, sorry for the noise.
Comment 3 Alexander Monakov 2018-02-26 13:31:26 UTC
Confirmed. Our comparator breaks here:

  /* Prefer SCHED_GROUP_P insns to any others.  */
  if (SCHED_GROUP_P (tmp_insn) != SCHED_GROUP_P (tmp2_insn))
    {
      if (VINSN_UNIQUE_P (tmp_vinsn) && VINSN_UNIQUE_P (tmp2_vinsn))
        return SCHED_GROUP_P (tmp2_insn) ? 1 : -1;

      /* Now uniqueness means SCHED_GROUP_P is set, because schedule groups
         cannot be cloned.  */
      if (VINSN_UNIQUE_P (tmp2_vinsn))
        return 1;
      return -1;
    }

when we have two non-unique insns such that one is in a sched group. That is not supposed to happen actually, since SCHED_GROUP_P should imply VINSN_UNIQUE_P. This invariant is broken when sched_macro_fuse_insns sets SCHED_GROUP_P without looking at deps->readonly.

So while we could get rid of the issue by rewriting the problematic sel-sched code in terms of SCHED_GROUP_P only, lack of deps->readonly check for macro-fusion seems like a bigger issue and should be fixed too.
Comment 4 Alexander Monakov 2018-04-11 14:36:35 UTC
Author: amonakov
Date: Wed Apr 11 14:36:04 2018
New Revision: 259322

URL: https://gcc.gnu.org/viewcvs?rev=259322&root=gcc&view=rev
Log:
sched-deps: respect deps->readonly in macro-fusion (PR 84566)

	PR rtl-optimization/84566
	* sched-deps.c (sched_analyze_insn): Check deps->readonly when invoking
	sched_macro_fuse_insns.



Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/sched-deps.c
Comment 5 Alexander Monakov 2018-04-11 14:47:50 UTC
Fixed.