[Bug middle-end/123986] [gcc16 regression] ICE in SLP
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123986
--- Comment #3 from Hongtao Liu ---
GPT suggestion for reference:
SLP simd-clone lowering could dereference an unset bestn->simdclone when
analysis failed to record clone info, leading to a null pointer segfault in
vectorizable_simd_clone_call.
I now re-run the clone-selection logic during transform when the recorded clone
is missing and guard against null metadata, so we bail out cleanly instead of
crashing (tree-vect-stmts.cc:4370-4423).
Uninitialized SIMD-clone pointers in the per-node data are now defaulted to
null to prevent use of garbage values (tree-vectorizer.h:262-269).
patch:
diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index e7d6b4c123a..4afd54b3dde 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -4253,10 +4253,7 @@ vectorizable_simd_clone_call (vec_info *vinfo,
stmt_vec_info stmt_info,
unsigned int badness_inbranch = 0;
struct cgraph_node *bestn = NULL;
struct cgraph_node *bestn_inbranch = NULL;
- if (!cost_vec)
-bestn = ((loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
-? data.clone_inbranch : data.clone);
- else
+ auto pick_best_clone = [&] () {
for (struct cgraph_node *n = node->simd_clones; n != NULL;
n = n->simdclone->next_clone)
{
@@ -4400,8 +4397,24 @@ vectorizable_simd_clone_call (vec_info *vinfo,
stmt_vec_info stmt_info,
badness_inbranch = this_badness;
}
}
+ };
+
+ if (cost_vec)
+pick_best_clone ();
+ else
+{
+ bestn = ((loop_vinfo && LOOP_VINFO_FULLY_MASKED_P (loop_vinfo))
+ ? data.clone_inbranch : data.clone);
+ bestn_inbranch = data.clone_inbranch;
+
+ /* If analysis didn't record a usable clone, recompute here. */
+ if (bestn == NULL || bestn->simdclone == NULL)
+ pick_best_clone ();
+}
- if (bestn == NULL)
+ /* If the chosen cgraph node has no SIMD clone metadata, bail out to avoid
+ dereferencing a null simdclone pointer during SLP transformation. */
+ if (bestn == NULL || bestn->simdclone == NULL)
return false;
fndecl = bestn->decl;
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 4849830204d..3fc938554f1 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -262,7 +262,8 @@ struct vect_data {
call_simd_clone_vec_info_type. */
struct vect_simd_clone_data : vect_data {
virtual ~vect_simd_clone_data () = default;
- vect_simd_clone_data () = default;
+ vect_simd_clone_data ()
+ : clone (NULL), clone_inbranch (NULL) {}
vect_simd_clone_data (vect_simd_clone_data &&other) = default;
/* Selected SIMD clone and clone for in-branch. */
[Bug middle-end/123986] [gcc16 regression] ICE in SLP
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123986 --- Comment #2 from Hongtao Liu --- during GIMPLE pass: slp test.f90:240:17: 240 | SUBROUTINE riming_graupel_cloud_ij( i, j ) | ^~ internal compiler error: Segmentation fault 0x2da3dfb internal_error(char const*, ...) /home/liuhongt/gcc/pr123986/gcc/diagnostic-global-context.cc:787 0x17103e3 crash_signal /home/liuhongt/gcc/pr123986/gcc/toplev.cc:325 0x7f453ec4251f ??? ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0 0x19e461c vectorizable_simd_clone_call /home/liuhongt/gcc/pr123986/gcc/tree-vect-stmts.cc:4407 0x1a02c80 vect_transform_stmt(vec_info*, _stmt_vec_info*, gimple_stmt_iterator*, _slp_tree*, _slp_instance*) /home/liuhongt/gcc/pr123986/gcc/tree-vect-stmts.cc:13414 0x1a436ef vect_schedule_slp_node /home/liuhongt/gcc/pr123986/gcc/tree-vect-slp.cc:12098 0x1a6770f vect_schedule_slp_node /home/liuhongt/gcc/pr123986/gcc/tree-vect-slp.cc:11880 0x1a6770f vect_schedule_scc /home/liuhongt/gcc/pr123986/gcc/tree-vect-slp.cc:12345 0x1a676a8 vect_schedule_scc /home/liuhongt/gcc/pr123986/gcc/tree-vect-slp.cc:12326 0x1a676a8 vect_schedule_scc /home/liuhongt/gcc/pr123986/gcc/tree-vect-slp.cc:12326 0x1a676a8 vect_schedule_scc /home/liuhongt/gcc/pr123986/gcc/tree-vect-slp.cc:12326 0x1a67d89 vect_schedule_slp(vec_info*, vec<_slp_instance*, va_heap, vl_ptr> const&) /home/liuhongt/gcc/pr123986/gcc/tree-vect-slp.cc:12490 0x1a69a5f vect_slp_region /home/liuhongt/gcc/pr123986/gcc/tree-vect-slp.cc:10423 0x1a6af0b vect_slp_bbs /home/liuhongt/gcc/pr123986/gcc/tree-vect-slp.cc:10535 0x1a6b4b4 vect_slp_function(function*) /home/liuhongt/gcc/pr123986/gcc/tree-vect-slp.cc:10657 0x1a76ed2 execute /home/liuhongt/gcc/pr123986/gcc/tree-vectorizer.cc:1571 gcc version 16.0.1 20260205 (experimental) (GCC) I can reproduce with r16-7303-g3cc03c04c72be8
[Bug middle-end/123986] [gcc16 regression] ICE in SLP
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123986 Richard Biener changed: What|Removed |Added CC||rguenth at gcc dot gnu.org --- Comment #1 from Richard Biener --- I can't reproduce? > ./f951 -quiet t.f90 -Ofast -march=x86-64-v4 r16-7225 ICEs though, with t.f90:240:3: 240 | SUBROUTINE riming_graupel_cloud_ij( i, j ) | ^~ internal compiler error: in exact_div, at poly-int.h:2179 0x25c576d internal_error(char const*, ...) /space/rguenther/src/gcc-clean/gcc/diagnostic-global-context.cc:787 0x80a663 fancy_abort(char const*, int, char const*) /space/rguenther/src/gcc-clean/gcc/diagnostics/context.cc:1812 0x140a4a6 poly_int<1u, poly_result::is_poly>::type, poly_coeff_pair_traits::is_poly>::type>::result_kind>::type> exact_div<1u, unsigned long, unsigned long>(poly_int<1u, unsigned long> const&, unsigned long) /space/rguenther/src/gcc-clean/gcc/poly-int.h:2179 0x13eb75f poly_int<1u, poly_result::result_kind>::type> exact_div<1u, unsigned long, unsigned long>(poly_int<1u, unsigned long> const&, poly_int<1u, unsigned long> const&) /space/rguenther/src/gcc-clean/gcc/poly-int.h:2192 0x13eb75f vectorizable_simd_clone_call /space/rguenther/src/gcc-clean/gcc/tree-vect-stmts.cc:4409 No vectorizer changes since then though. Odd.
