https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127978
Bug ID: 127978
Summary: vectorizer: segfault in vectorizable_store on
conditional call to an omp declare simd simdlen(32)
clone
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: ice-on-valid-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: dohanam2 at illinois dot edu
Target Milestone: ---
GCC crashes with a segmentation fault in the vectorizer (vectorizable_store)
when an `omp simd` loop makes a conditional call to a `#pragma omp declare simd
simdlen(32)` function returning `signed char`.
```c
#pragma omp declare simd simdlen(32)
signed char f(signed char) __attribute__((const));
void g(signed char *d, signed char *a, int *m, int n) {
#pragma omp simd
for (int i = 0; i < n; i++)
if (m[i])
d[i] = f(a[i]);
}
```
```
gcc -O2 -fopenmp-simd -mavx512vl -mavx512bw -mprefer-vector-width=512 -c
reduced.c
```
```
reduced.c: In function 'g':
reduced.c:3:6: internal compiler error: Segmentation fault
0x1532f9b vec<tree_node*, va_heap, vl_embed>::operator[](unsigned int)
../../gcc/vec.h:911
0x1532f9b vectorizable_store
../../gcc/tree-vect-stmts.cc:9370
0x15397d0 vect_transform_stmt(vec_info*, _stmt_vec_info*,
gimple_stmt_iterator*, _slp_tree*, _slp_instance*)
../../gcc/tree-vect-stmts.cc:13252
0x1585fbb vect_schedule_slp_node
../../gcc/tree-vect-slp.cc:12520
```
This is valid input using only documented options, so the compiler should
either vectorize the loop or decline to; it should not crash.
It reproduces at af927b3bb7b08f5f164ed700f86c597d5867b2fb (latest upstream when
checked). The checking build crashes with "Segmentation fault (during GIMPLE
pass: vect)" in `vec::operator[]` (vec.h:911, called from vectorizable_store),
and the release build crashes the same way in `vectorizable_store`
(tree-vect-stmts.cc:9370).
Looks like, going by the vect dump (of the unreduced input), the vectorizer
turns the clone call into two `D.N[0]`/`D.N[1]` array-element extractions but
never builds a `vect__N` CONSTRUCTOR for the stored value, so
vectorizable_store indexes an empty def vector at tree-vect-stmts.cc:9370. Only
simdlen(32) crashes (simdlen 8, 16 and 64 do not), which matches a 16-lane SSE
clone being picked for a V64QI loop vector type.
Found with an LLM-based testing tool; I used Claude to reduce it and look for
the cause.