Bug 92945 - -O2 -floop-nest-optimize crashes gccin isl_basic_map_underlying_set ()
Summary: -O2 -floop-nest-optimize crashes gccin isl_basic_map_underlying_set ()
Status: RESOLVED DUPLICATE of bug 93134
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 9.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-15 11:04 UTC by Sergei Trofimovich
Modified: 2020-01-08 13:16 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
scipy-graphite-ice.f (323 bytes, text/plain)
2019-12-15 11:04 UTC, Sergei Trofimovich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2019-12-15 11:04:31 UTC
Created attachment 47498 [details]
scipy-graphite-ice.f

Initially reported as https://bugs.gentoo.org/702968 by wolfwood.
There fortran code (from scipy-1.1.0) and C++ code (from dav1d-0.5.2) crash with -floop-nest-optimize.

I crash both gcc-9.2.0 and current gcc trunk.

Here is the reduced fortran example:

$ cat scipy-graphite-ice.f

        SUBROUTINE CERZO(NT,ZO)
        IMPLICIT DOUBLE PRECISION (E,P,W)
        IMPLICIT COMPLEX *16 (C,Z)
        DIMENSION ZO(NT)
        DO 35 NR=1,NT
           PX=0.5*PU-0.5*DLOG(PV)/PU
           PY=0.5*PU+0.5*DLOG(PV)/PU
15         IT=IT+1
           CALL CERF(Z,ZF,ZD)
           DO 30 I=1,NR-1
              ZW=(1.0D0,0.0D0)
              DO 25 J=1,NR-1
                 IF (J.EQ.I) GO TO 25
                 ZW=ZW*(Z-ZO(J))
25            CONTINUE
30            ZQ=ZQ+ZW
           ZGD=(ZD-ZQ*ZFD)/ZP
           Z=Z-ZFD/ZGD
           IF (IT.LE.50.AND.DABS((W-W0)/W).GT.1.0D-11) GO TO 15
35         ZO(NR)=Z
        IF (B.NE.INT(B)) THEN
        ENDIF
        END

$ LANG=C ./gfortran -B . -O2 -floop-nest-optimize -c scipy-graphite-ice.f
scipy-graphite-ice.f:16:72:

   16 | 30            ZQ=ZQ+ZW
      |                                                                        1
Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 30 at (1)
scipy-graphite-ice.f:20:72:

   20 | 35         ZO(NR)=Z
      |                                                                        1
Warning: Fortran 2018 deleted feature: DO termination statement which is not END DO or CONTINUE with label 35 at (1)
during GIMPLE pass: graphite
scipy-graphite-ice.f:1:0:

    1 |         SUBROUTINE CERZO(NT,ZO)
      |
internal compiler error: Segmentation fault
0x7fda773f51cf ???
	/usr/src/debug/sys-libs/glibc-2.30-r3/glibc-2.30/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
0x7fda773def1a __libc_start_main
	../csu/libc-start.c:308
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.

$ LANG=C ./gfortran -B . -v
Reading specs from ./specs
COLLECT_GCC=./gfortran
COLLECT_LTO_WRAPPER=./lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --enable-languages=c,c++ --disable-bootstrap --with-multilib-list=m64 --prefix=/home/slyfox/dev/git/gcc-fortran-and-isl/../gcc-native-quick-installed --disable-nls --without-isl --disable-libsanitizer --disable-libvtv --disable-libgomp --disable-libstdcxx-pch --disable-libunwind-exceptions CFLAGS='-O1 ' CXXFLAGS='-O1 ' --with-sysroot=/usr/x86_64-HEAD-linux-gnu --enable-languages=c,c++,fortran --with-isl
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.0.0 20191215 (experimental) (GCC)
Comment 1 Sergei Trofimovich 2019-12-15 11:05:46 UTC
The crash happens somewhere in internals of isl-0.22:

Thread 2.1 "f951" received signal SIGSEGV, Segmentation fault.
[Switching to process 1919154]
0x00007ffff7e50a74 in isl_basic_map_underlying_set () from /usr/lib64/libisl.so.22
(gdb) bt
#0  0x00007ffff7e50a74 in isl_basic_map_underlying_set () from /usr/lib64/libisl.so.22
#1  0x00007ffff7e56431 in isl_basic_map_is_empty () from /usr/lib64/libisl.so.22
#2  0x00007ffff7e578da in ?? () from /usr/lib64/libisl.so.22
#3  0x00007ffff7e2ede3 in ?? () from /usr/lib64/libisl.so.22
#4  0x00007ffff7e3115c in ?? () from /usr/lib64/libisl.so.22
#5  0x00007ffff7e326ac in isl_union_access_info_compute_flow () from /usr/lib64/libisl.so.22
#6  0x00000000017b5b9e in scop_get_dependences(scop*) ()
#7  0x00000000017b603b in apply_poly_transforms(scop*) ()
#8  0x00000000017b02d2 in graphite_transform_loops() ()
#9  0x00000000017b0809 in (anonymous namespace)::pass_graphite_transforms::execute(function*) ()
#10 0x0000000000c0caed in execute_one_pass(opt_pass*) ()
#11 0x0000000000c0d50f in execute_pass_list_1(opt_pass*) ()
#12 0x0000000000c0d521 in execute_pass_list_1(opt_pass*) ()
#13 0x0000000000c0d521 in execute_pass_list_1(opt_pass*) ()
#14 0x0000000000c0d521 in execute_pass_list_1(opt_pass*) ()
#15 0x0000000000c0d53a in execute_pass_list(function*, opt_pass*) ()
#16 0x000000000080d779 in cgraph_node::expand() ()
#17 0x000000000080f2c2 in symbol_table::compile() ()
#18 0x00000000008117ba in symbol_table::finalize_compilation_unit() ()
#19 0x0000000000cfab26 in compile_file() ()
#20 0x0000000000cfd784 in toplev::main(int, char**) ()
#21 0x00000000018f083c in main ()
Comment 2 Sergei Trofimovich 2019-12-15 11:15:56 UTC
Rebuilt isl with debugging symbols. gdb says 'bmap' is NULL:

Thread 2.1 "f951" received signal SIGSEGV, Segmentation fault.
[Switching to process 1944963]
isl_basic_map_underlying_set (bmap=0x0) at ../isl-0.22/isl_map.c:5515
5515		space = isl_space_underlying(space, bmap->n_div);
(gdb) bt
#0  isl_basic_map_underlying_set (bmap=0x0) at ../isl-0.22/isl_map.c:5515
#1  0x00007ffff7e56431 in isl_basic_map_is_empty (bmap=0x28185f0) at ../isl-0.22/isl_map.c:8988
#2  isl_basic_map_is_empty (bmap=0x28185f0) at ../isl-0.22/isl_map.c:8958
#3  0x00007ffff7e578da in map_product (map1=0x27eb7b0, map2=0x27f4a90, space_product=<optimized out>,
    basic_map_product=0x7ffff7e4dfa0 <isl_basic_map_range_product>, remove_duplicates=1) at ../isl-0.22/isl_map.c:10468
#4  0x00007ffff7e2ede3 in coscheduled_source (acc=acc@entry=0x27f8c20, old_map=0x27f4a90, pos=pos@entry=8, depth=<optimized out>) at ../isl-0.22/isl_flow.c:941
#5  0x00007ffff7e3115c in handle_coscheduled (flow=0x28455d0, may_rel=0x2845370, must_rel=0x2845330, acc=0x27f8c20) at ../isl-0.22/isl_flow.c:1034
#6  compute_val_based_dependences (acc=<optimized out>) at ../isl-0.22/isl_flow.c:1238
#7  access_info_compute_flow_core (acc=<optimized out>, acc@entry=0x27f8c20) at ../isl-0.22/isl_flow.c:1338
#8  0x00007ffff7e326ac in compute_single_flow (data=0x7fffffffcfc0, sink=<optimized out>, uf=0x27d6410) at ../isl-0.22/isl_flow.c:3082
#9  compute_flow_schedule (access=0x28ab6e0) at ../isl-0.22/isl_flow.c:3166
#10 isl_union_access_info_compute_flow (access=0x28ab6e0) at ../isl-0.22/isl_flow.c:3217
#11 0x00000000017b5b9e in scop_get_dependences(scop*) ()
#12 0x00000000017b603b in apply_poly_transforms(scop*) ()
#13 0x00000000017b02d2 in graphite_transform_loops() ()
#14 0x00000000017b0809 in (anonymous namespace)::pass_graphite_transforms::execute(function*) ()
#15 0x0000000000c0caed in execute_one_pass(opt_pass*) ()
#16 0x0000000000c0d50f in execute_pass_list_1(opt_pass*) ()
#17 0x0000000000c0d521 in execute_pass_list_1(opt_pass*) ()
#18 0x0000000000c0d521 in execute_pass_list_1(opt_pass*) ()
#19 0x0000000000c0d521 in execute_pass_list_1(opt_pass*) ()
#20 0x0000000000c0d53a in execute_pass_list(function*, opt_pass*) ()
#21 0x000000000080d779 in cgraph_node::expand() ()
#22 0x000000000080f2c2 in symbol_table::compile() ()
#23 0x00000000008117ba in symbol_table::finalize_compilation_unit() ()
#24 0x0000000000cfab26 in compile_file() ()
#25 0x0000000000cfd784 in toplev::main(int, char**) ()
#26 0x00000000018f083c in main ()
(gdb) list
5510		    !isl_space_is_named_or_nested(bmap->dim, isl_dim_in) &&
5511		    !isl_space_is_named_or_nested(bmap->dim, isl_dim_out))
5512			return bset_from_bmap(bmap);
5513		bmap = isl_basic_map_cow(bmap);
5514		space = isl_basic_map_take_space(bmap);
5515		space = isl_space_underlying(space, bmap->n_div);
5516		bmap = isl_basic_map_restore_space(bmap, space);
5517		if (!bmap)
5518			return NULL;
5519		bmap->extra -= bmap->n_div;
(gdb) print bmap
$1 = (isl_basic_map *) 0x0
Comment 3 Arseny Solokha 2019-12-15 13:41:30 UTC
It looks like a duplicate of PR90004, or at least PR90004 comment 2.
Comment 4 Richard Biener 2020-01-08 13:16:44 UTC
Bug in ISL.

*** This bug has been marked as a duplicate of bug 93134 ***