Bug 88879 - [9 Regression] ICE in sel_target_adjust_priority, at sel-sched.c:3332
Summary: [9 Regression] ICE in sel_target_adjust_priority, at sel-sched.c:3332
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 9.0
: P4 normal
Target Milestone: 9.3
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2019-01-16 14:38 UTC by Richard Biener
Modified: 2020-02-14 14:08 UTC (History)
3 users (show)

See Also:
Host:
Target: ia64
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-01-16 00:00:00


Attachments
preprocessed source (8.56 KB, text/plain)
2019-01-16 14:42 UTC, Richard Biener
Details
Reduced test case (276 bytes, text/plain)
2019-01-16 15:52 UTC, David Malcolm
Details
ia64 -O3 test case from python2.7 (888 bytes, text/plain)
2019-06-09 20:37 UTC, Jason Duerstock
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2019-01-16 14:38:57 UTC
Building SPEC 2000 on Itanium ICEs left and right in sel_target_adjust_priority.
Comment 1 Richard Biener 2019-01-16 14:42:30 UTC
Created attachment 45441 [details]
preprocessed source

/gcc/spec/sb-terbium-head-64/ia64/install-201901161204/bin/gcc -c -o unlzw.o              -O3  unlzw.c -save-temps -v
Using built-in specs.
COLLECT_GCC=/gcc/spec/sb-terbium-head-64/ia64/install-201901161204/bin/gcc
Target: ia64-unknown-linux-gnu
Configured with: /gcc/spec/sb-terbium-head-64/gcc/configure --prefix=/gcc/spec/sb-terbium-head-64/ia64/install-201901161204 --enable-languages=c,c++,fortran --enable-threads=posix --disable-nls --enable-__cxa_atexit --enable-clocale=gnu --enable-checking=release --disable-libstdcxx-pch --disable-libsanitizer --disable-libcilkrts --without-isl --disable-werror
Thread model: posix
gcc version 9.0.0 20190116 (experimental) [trunk revision 267969] (GCC) 
COLLECT_GCC_OPTIONS='-c' '-o' 'unlzw.o' '-O3' '-save-temps' '-v'
 /gcc/spec/sb-terbium-head-64/ia64/install-201901161204/libexec/gcc/ia64-unknown-linux-gnu/9.0.0/cc1 -E -quiet -v unlzw.c -O3 -fpch-preprocess -o unlzw.i
ignoring nonexistent directory "/gcc/spec/sb-terbium-head-64/ia64/install-201901161204/lib/gcc/ia64-unknown-linux-gnu/9.0.0/../../../../ia64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /gcc/spec/sb-terbium-head-64/ia64/install-201901161204/lib/gcc/ia64-unknown-linux-gnu/9.0.0/include
 /usr/local/include
 /gcc/spec/sb-terbium-head-64/ia64/install-201901161204/include
 /gcc/spec/sb-terbium-head-64/ia64/install-201901161204/lib/gcc/ia64-unknown-linux-gnu/9.0.0/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-c' '-o' 'unlzw.o' '-O3' '-save-temps' '-v'
 /gcc/spec/sb-terbium-head-64/ia64/install-201901161204/libexec/gcc/ia64-unknown-linux-gnu/9.0.0/cc1 -fpreprocessed unlzw.i -quiet -dumpbase unlzw.c -auxbase-strip unlzw.o -O3 -version -o unlzw.s
GNU C17 (GCC) version 9.0.0 20190116 (experimental) [trunk revision 267969] (ia64-unknown-linux-gnu)
        compiled by GNU C version 9.0.0 20190116 (experimental) [trunk revision 267969], GMP version 5.0.5, MPFR version 3.1.0-p1, MPC version 0.8.2, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C17 (GCC) version 9.0.0 20190116 (experimental) [trunk revision 267969] (ia64-unknown-linux-gnu)
        compiled by GNU C version 9.0.0 20190116 (experimental) [trunk revision 267969], GMP version 5.0.5, MPFR version 3.1.0-p1, MPC version 0.8.2, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: b841429784bb4c1bcbfd81a8b6b2b964
unlzw.c: In function 'unlzw':
unlzw.c:261:19: warning: implicit declaration of function 'spec_read' [-Wimplicit-function-declaration]
  261 |      if ((rsize = read(in, (char*)inbuf+insize, INBUFSIZ)) == EOF) {
      |                   ^~~~~~~~~
during RTL pass: mach
unlzw.c:377:1: internal compiler error: in sel_target_adjust_priority, at sel-sched.c:3332
  377 | }
      | ^
0x4000000000db257f sel_target_adjust_priority
        /gcc/spec/sb-terbium-head-64/gcc/gcc/sel-sched.c:3332
0x4000000000db257f fill_vec_av_set
        /gcc/spec/sb-terbium-head-64/gcc/gcc/sel-sched.c:3726
0x4000000000db34ff fill_ready_list
        /gcc/spec/sb-terbium-head-64/gcc/gcc/sel-sched.c:4027
0x4000000000db34ff find_best_expr
        /gcc/spec/sb-terbium-head-64/gcc/gcc/sel-sched.c:4387
0x4000000000db34ff fill_insns
        /gcc/spec/sb-terbium-head-64/gcc/gcc/sel-sched.c:5548
0x4000000000dba63f schedule_on_fences
        /gcc/spec/sb-terbium-head-64/gcc/gcc/sel-sched.c:7364
0x4000000000dba63f sel_sched_region_2
        /gcc/spec/sb-terbium-head-64/gcc/gcc/sel-sched.c:7502
0x4000000000dbedff sel_sched_region_1
        /gcc/spec/sb-terbium-head-64/gcc/gcc/sel-sched.c:7544
0x4000000000dc20ef sel_sched_region(int)
        /gcc/spec/sb-terbium-head-64/gcc/gcc/sel-sched.c:7645
0x4000000000dc20ef sel_sched_region(int)
        /gcc/spec/sb-terbium-head-64/gcc/gcc/sel-sched.c:7630
0x4000000000dc350f run_selective_scheduling()
        /gcc/spec/sb-terbium-head-64/gcc/gcc/sel-sched.c:7731
0x4000000001583aaf ia64_reorg
        /gcc/spec/sb-terbium-head-64/gcc/gcc/config/ia64/ia64.c:9857
0x4000000000d3274f execute
        /gcc/spec/sb-terbium-head-64/gcc/gcc/reorg.c:3979
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Comment 2 Richard Biener 2019-01-16 14:47:28 UTC
A little detail is that host GCC is GCC 4.1.2 which happened to miscompile GCC
itself for quite a while (but now somehow we're back).
Comment 3 Richard Biener 2019-01-16 14:51:12 UTC
I can reproduce it with a cross from x86_64-linux.
Comment 4 Alexander Monakov 2019-01-16 15:48:50 UTC
Thanks. This broke when the patch for PR 85458 was applied, and Andreas raised it on the gcc-patches thread: https://gcc.gnu.org/ml/gcc-patches/2018-09/msg00128.html

Soon after that, the HP-PA adjust_priority target hook was removed, making the sel-sched change unnecessary. Therefore, my recommendation is to revert the sel-sched patch, or remove the new assert as Andreas has suggested. Andrey, which approach would you prefer?

It's also possible to implement Jeff's suggestion and clamp negative priorities to zero in create_speculation_check, but that may turn out to be insufficient if there is other code producing negative priority values.
Comment 5 David Malcolm 2019-01-16 15:52:05 UTC
Created attachment 45443 [details]
Reduced test case

This ICEs with -O3 at the same place.

3332	  gcc_assert (new_priority >= 0);

where:

3321	static int
3322	sel_target_adjust_priority (expr_t expr)
3323	{
3324	  int priority = EXPR_PRIORITY (expr);
3325	  int new_priority;
3326	
3327	  if (targetm.sched.adjust_priority)
3328	    new_priority = targetm.sched.adjust_priority (EXPR_INSN_RTX (expr), priority);
3329	  else
3330	    new_priority = priority;
3331	
3332	  gcc_assert (new_priority >= 0);

(gdb) p expr->priority
$7 = -1
(gdb) p new_priority
$8 = -1
(gdb) (gdb) p targetm.sched.adjust_priority
Undefined command: "".  Try "help".
(gdb) p targetm.sched.adjust_priority
$9 = (int (*)(rtx_insn *, int)) 0x0
Comment 6 Andrey Belevantsev 2019-01-25 08:52:21 UTC
(In reply to Alexander Monakov from comment #4)
> Thanks. This broke when the patch for PR 85458 was applied, and Andreas
> raised it on the gcc-patches thread:
> https://gcc.gnu.org/ml/gcc-patches/2018-09/msg00128.html
> 
> Soon after that, the HP-PA adjust_priority target hook was removed, making
> the sel-sched change unnecessary. Therefore, my recommendation is to revert
> the sel-sched patch, or remove the new assert as Andreas has suggested.
> Andrey, which approach would you prefer?
> 
> It's also possible to implement Jeff's suggestion and clamp negative
> priorities to zero in create_speculation_check, but that may turn out to be
> insufficient if there is other code producing negative priority values.

I would try to avoid negative priorities if possible. It looks they could only come from the adjust_priority hook or from create_speculation_check.  If the former is now impossible then maybe just fix the latter?
Comment 7 Richard Biener 2019-04-26 07:21:40 UTC
Almost all SPEC 2000 tests still fail to build.

Time to retire the IA64 port.
Comment 8 Jakub Jelinek 2019-05-03 09:16:11 UTC
GCC 9.1 has been released.
Comment 9 Richard Biener 2019-05-07 12:51:23 UTC
ping?
Comment 10 Alexander Monakov 2019-05-09 18:14:02 UTC
Author: amonakov
Date: Thu May  9 18:13:28 2019
New Revision: 271039

URL: https://gcc.gnu.org/viewcvs?rev=271039&root=gcc&view=rev
Log:
sel-sched: allow negative insn priority (PR 88879)

	PR rtl-optimization/88879
	* sel-sched.c (sel_target_adjust_priority): Remove assert.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/sel-sched.c
Comment 11 Alexander Monakov 2019-05-09 18:19:54 UTC
Fixed on the trunk.
Comment 12 Jason Duerstock 2019-06-09 20:37:05 UTC
Created attachment 46469 [details]
ia64 -O3 test case from python2.7

There is still a problem with sel-sched.c on ia64.  Removing this assertion just results in python2.7 dumping core when attempting to build it.  I trimmed down the failure and put it in this attachment.
Comment 13 Jakub Jelinek 2019-08-12 08:55:11 UTC
GCC 9.2 has been released.
Comment 14 Arnd Bergmann 2020-02-11 17:00:22 UTC
I got the same output while building the linux kernel defconfig today, reduced to this minimal test case:

$ cat test.c
long a, b;
int fn1() {
  char *c = (void *)b;
  while (1) {
    const long d = *c = d;
    do
      a++;
    while (a == 5);
  }
}
$ ia64-linux-gcc -O3 -c test.c
during RTL pass: mach
lz4_decompress.c:10:1: internal compiler error: in sel_target_adjust_priority, at sel-sched.c:3334
   10 | }

Reproduced both with 9.2 and current HEAD 
$ ia64-linux-gcc --version
ia64-linux-gcc (GCC) 9.2.1 20200211
Comment 15 Alexander Monakov 2020-02-11 17:30:55 UTC
This should not be reproducible with current HEAD because the assert was simply eliminated. If GCC master definitely fails, can you please provide the exact diagnostic?

As for 9.2 this is sadly expected because the patch was not backported, I will backport it soon for the next release from the gcc-9 branch (but if you're building GCC yourself you can easily do it on your end as the patch simply removes the offending assert). Sorry about the trouble.
Comment 16 Arnd Bergmann 2020-02-11 18:04:31 UTC
Right, I was on the releases/gcc-9 branch, not HEAD. Sorry about the confusion. I applied your fix and have a working 9.2 build that can build the kernel now. Thanks!
Comment 17 GCC Commits 2020-02-14 14:06:13 UTC
The releases/gcc-9 branch has been updated by Alexander Monakov <amonakov@gcc.gnu.org>:

https://gcc.gnu.org/g:0f7b7aeb71d06fc85f49c323fbd4879d5a02f336

commit r9-8237-g0f7b7aeb71d06fc85f49c323fbd4879d5a02f336
Author: Alexander Monakov <amonakov@ispras.ru>
Date:   Fri Feb 14 16:51:21 2020 +0300

    sel-sched: allow negative insn priority (PR 88879)
    
    	PR rtl-optimization/88879
    	* sel-sched.c (sel_target_adjust_priority): Remove assert.
Comment 18 Alexander Monakov 2020-02-14 14:08:06 UTC
Fixed.