Bug 102696

Summary: [12 Regression] ICE in vect_build_slp_tree, at tree-vect-slp.c:1551 for skylake-avx512 and icelake-server
Product: gcc Reporter: Vsevolod Livinskii <vsevolod.livinskiy>
Component: tree-optimizationAssignee: Richard Biener <rguenth>
Status: RESOLVED FIXED    
Severity: normal CC: babokin, regehr, vsevolod.livinskiy
Priority: P3 Keywords: ice-on-valid-code
Version: 12.0   
Target Milestone: 12.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2021-10-12 00:00:00
Bug Depends on:    
Bug Blocks: 103035    

Description Vsevolod Livinskii 2021-10-12 01:45:21 UTC
Link to the Compiler Explorer:
https://godbolt.org/z/WhYP35KKT

Reproducer:

int a;
extern bool b[][14];
char h;
void f(short g[][14]) {
    for (short d = h; d < 21; d += 1)
      for (unsigned char e = 0; e < 14; e += 1) {
        a = 0;
        b[d][e] = g[d][e];
      }
}

Error:
>$ g++ -c -O3 -march=skylake-avx512 func.cpp
during GIMPLE pass: slp
func.cpp: In function 'void f(short int (*)[14])':
func.cpp:4:6: internal compiler error: in vect_build_slp_tree, at tree-vect-slp.c:1551
    4 | void f(short g[][14]) {
      |      ^
0x153e92a vect_build_slp_tree
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:1551
0x153ee59 vect_build_slp_tree_2
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:2199
0x153e41c vect_build_slp_tree
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:1532
0x153ee59 vect_build_slp_tree_2
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:2199
0x153e41c vect_build_slp_tree
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:1532
0x153ee59 vect_build_slp_tree_2
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:2199
0x153e41c vect_build_slp_tree
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:1532
0x153ee59 vect_build_slp_tree_2
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:2199
0x153e41c vect_build_slp_tree
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:1532
0x1543ac2 vect_build_slp_instance
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:3012
0x1544d35 vect_analyze_slp_instance
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:3332
0x1543d96 vect_build_slp_instance
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:3230
0x1544d35 vect_analyze_slp_instance
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:3332
0x1543d96 vect_build_slp_instance
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:3230
0x1544d35 vect_analyze_slp_instance
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:3332
0x154979a vect_analyze_slp(vec_info*, unsigned int)
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:3365
0x154d316 vect_slp_analyze_bb_1
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:5746
0x154d316 vect_slp_region
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:5848
0x154f495 vect_slp_bbs
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:6040
0x154f799 vect_slp_function(function*)
        /testing/gcc/gcc_src_master/gcc/tree-vect-slp.c:6128
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.
root@86380205c3f4:/testing/result/S_3142105512/reduce# g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/testing/gcc/bin_master/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /testing/gcc/gcc_src_master/configure --enable-multilib --prefix=/testing/gcc/bin_master --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib

gcc version 12.0.0 20211011 (30cce6f65a77b8eaa22f3efff7f1ba54858106f9) (GCC)
Comment 1 Andrew Pinski 2021-10-12 04:58:56 UTC
Confirmed.

Alos this fails the same:
int a;
extern bool b[][14];
char h;
void f(short g[][14]) {
    for (short d = h; d < 21; d += 1) {
      a = 0;
      for (unsigned char e = 0; e < 14; e += 1) {
        b[d][e] = g[d][e];
      }
    }
}
Comment 2 Richard Biener 2021-10-12 06:25:04 UTC
I will have a look.  Note the issue is probably latent in GCC 11.
Comment 3 GCC Commits 2021-10-12 12:50:18 UTC
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:d1dcaa31453fa080a27938b064e53f02272d4aa1

commit r12-4351-gd1dcaa31453fa080a27938b064e53f02272d4aa1
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Oct 12 13:49:39 2021 +0200

    tree-optimization/102696 - fix SLP discovery for failed BIT_FIELD_REF
    
    This fixes a forgotten adjustment of matches[] when we fail SLP
    discovery.
    
    2021-10-12  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/102696
            * tree-vect-slp.c (vect_build_slp_tree_2): Properly mark
            the tree fatally failed when we reject a BIT_FIELD_REF.
    
            * g++.dg/vect/pr102696.cc: New testcase.
Comment 4 Richard Biener 2021-10-12 12:51:53 UTC
Fixed.  The branch doesn't cache negative entries so the issue is not latent.