https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127975
Bug ID: 127975
Summary: vect: ICE in vect_get_loop_mask on omp declare simd
simdlen(2) call with -mavx512vl and
vect-partial-vector-usage=2
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: ---
With `--param=vect-partial-vector-usage=2` and `-mavx512vl`, a loop that calls
an `omp declare simd simdlen(2)` function (`float f(double)`) hits a
`gcc_assert` in `vect_get_loop_mask`.
```c
#pragma omp declare simd simdlen(2)
float f(double);
void g(float *d, double *a, int n) {
#pragma omp simd
for (int i = 0; i < n; i++)
d[i] = f(a[i]);
}
```
```
gcc -O2 -fopenmp-simd -mavx512vl --param=vect-partial-vector-usage=2 -c
reduced.c -o /dev/null
```
```
during GIMPLE pass: vect
reduced.c: In function 'g':
reduced.c:3:6: internal compiler error: in vect_get_loop_mask, at
tree-vect-loop.cc:10709
0x8f8711 vect_get_loop_mask(_loop_vec_info*, gimple_stmt_iterator*,
vec_loop_masks*, unsigned int, tree_node*, unsigned int)
../../gcc/tree-vect-loop.cc:10709
0x151fd78 vectorizable_simd_clone_call
../../gcc/tree-vect-stmts.cc:4922
0x1539850 vect_transform_stmt(vec_info*, _stmt_vec_info*,
gimple_stmt_iterator*, _slp_tree*, _slp_instance*)
../../gcc/tree-vect-stmts.cc:13271
0x1585fbb vect_schedule_slp_node
../../gcc/tree-vect-slp.cc:12520
```
It reproduces at af927b3bb7b08f5f164ed700f86c597d5867b2fb. The checking build
and the release build both fail with the same ICE, exit status 4, same message
and backtrace. x86 defaults `vect-partial-vector-usage` to 0, so the `--param`
is needed.
This looks like `vectorizable_simd_clone_call` (tree-vect-stmts.cc, around line
4905) building a mask vectype of `vector(2) float` (8 bytes), for which
`ix86_get_mask_mode` returns a vector mask mode rather than an integer (kmask)
mode, so the mask-splitting path in `vect_get_loop_mask` asserts. The same
function asserts in closed PR 121059, 112450 and 97104; I did not check whether
those have the same cause. PR 122736 (loop masking with SIMD clones ICEs in
vect_verify_full_masking) is open and may be related; it has a different
assert.
Found with an LLM-based testing tool; I used Claude to reduce it and look for
the cause.