Bug 113018 - ICE in gimple_convert, gimple-fold.cc during the SLP pass
Summary: ICE in gimple_convert, gimple-fold.cc during the SLP pass
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 14.0
: P3 normal
Target Milestone: ---
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code, needs-bisection
Depends on:
Blocks:
 
Reported: 2023-12-14 10:20 UTC by Filip Kastl
Modified: 2023-12-14 15:57 UTC (History)
0 users

See Also:
Host: x86_64-linux
Target: aarch64-gnu-linux
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-12-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Filip Kastl 2023-12-14 10:20:52 UTC
While compiling the GCC testsuite testcase gcc.target/aarch64/vect-fmax-fmin.c with aarch64 crosscompiler:

aarch64-linux-gnu-gcc /home/worker/buildworker/tiber-option-juggler/build/gcc/testsuite/gcc.target/aarch64/vect-fmax-fmin.c -fno-tree-loop-vectorize -Ofast

An ICE occurs:

during GIMPLE pass: slp
In file included from /home/worker/buildworker/tiber-option-juggler/build/gcc/testsuite/gcc.target/aarch64/vect-fmax-fmin.c:8:
/home/worker/buildworker/tiber-option-juggler/build/gcc/testsuite/gcc.target/aarch64/vect-fmaxv-fminv.x: In function ‘maxv_f32’:
/home/worker/buildworker/tiber-option-juggler/build/gcc/testsuite/gcc.target/aarch64/vect-fmaxv-fminv.x:5:7: internal compiler error: Segmentation fault
    5 | float maxv_f32 (pRF32 a)
      |       ^~~~~~~~
0xd938df crash_signal
	/home/worker/buildworker/tiber-gcc-trunk-aarch64/build/gcc/toplev.cc:316
0xa7e033 gimple_convert(gimple_stmt_iterator*, bool, gsi_iterator_update, unsigned int, tree_node*, tree_node*)
	/home/worker/buildworker/tiber-gcc-trunk-aarch64/build/gcc/gimple-fold.cc:9168
0x10274cf gimple_convert(gimple**, tree_node*, tree_node*)
	/home/worker/buildworker/tiber-gcc-trunk-aarch64/build/gcc/gimple-fold.h:183
0x10274cf vectorize_slp_instance_root_stmt(_slp_tree*, _slp_instance*)
	/home/worker/buildworker/tiber-gcc-trunk-aarch64/build/gcc/tree-vect-slp.cc:9401
0x10287aa vect_schedule_slp(vec_info*, vec<_slp_instance*, va_heap, vl_ptr> const&)
	/home/worker/buildworker/tiber-gcc-trunk-aarch64/build/gcc/tree-vect-slp.cc:9639
0x102ac51 vect_slp_region
	/home/worker/buildworker/tiber-gcc-trunk-aarch64/build/gcc/tree-vect-slp.cc:7770
0x102c19c vect_slp_bbs
	/home/worker/buildworker/tiber-gcc-trunk-aarch64/build/gcc/tree-vect-slp.cc:7870
0x102c688 vect_slp_function(function*)
	/home/worker/buildworker/tiber-gcc-trunk-aarch64/build/gcc/tree-vect-slp.cc:7992
0x1033f59 execute
	/home/worker/buildworker/tiber-gcc-trunk-aarch64/build/gcc/tree-vectorizer.cc:1531
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

My guess is that the segmentation fault is caused by SLP passing a null tree to gimple_convert.
Comment 1 Richard Biener 2023-12-14 14:04:07 UTC
I will have a look.
Comment 2 Richard Biener 2023-12-14 14:27:18 UTC
OK, so we're running into

  /* When a BB reduction doesn't have an even number of lanes
     strip it down, treating the remaining lane as scalar.
     ???  Selecting the optimal set of lanes to vectorize would be nice
     but SLP build for all lanes will fail quickly because we think
     we're going to need unrolling.  */
  if (kind == slp_inst_kind_bb_reduc
      && (scalar_stmts.length () & 1))
    remain.safe_insert (0, gimple_get_lhs (scalar_stmts.pop ()->stmt));

pushing the "LHS" of an asm.

__asm__("" : "=w" s_10 : "0" _1);
Comment 3 GCC Commits 2023-12-14 15:57:20 UTC
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:4e9b2c94e45f5991a472fb639fb2baa6aa42b76b

commit r14-6552-g4e9b2c94e45f5991a472fb639fb2baa6aa42b76b
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Dec 14 16:00:50 2023 +0100

    tree-optimization/113018 - ICE with BB reduction vectorization
    
    When BB reduction vectorization picks up a chain with an ASM def
    in it and that's inside the vectorized region we fail to get its
    LHS.  Instead of trying to get the correct def the following
    avoids vectorizing such def and instead keeps it as def to add
    in the epilog.
    
            PR tree-optimization/113018
            * tree-vect-slp.cc (vect_slp_check_for_roots): Only start
            SLP discovery from stmts with a LHS.
Comment 4 Richard Biener 2023-12-14 15:57:41 UTC
Fixed.