https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128225

            Bug ID: 128225
           Summary: vectorizer: ICE in build_truth_vector_type_for_mode on
                    omp declare simd inbranch call with -m32 -mavx2
           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 `-m32 -mavx2`, vectorizing an `omp simd` loop that calls an `omp declare
simd simdlen(2) inbranch` function ICEs in `build_truth_vector_type_for_mode`
called from `vectorizable_simd_clone_call`.

```c
#pragma omp declare simd simdlen(2) inbranch
extern float clone(double) __attribute__((const));
void use(float *restrict d, const double *restrict a, int n)
{
#pragma omp simd
  for (int i = 0; i < n; i++)
    d[i] = clone(a[i]);
}
```

```
gcc -O3 -fopenmp-simd -m32 -mavx2 -c reduced.c
```

```
during GIMPLE pass: vect
reduced.c:3:6: internal compiler error: in build_truth_vector_type_for_mode, at
tree.cc:10548
0x90df62 build_truth_vector_type_for_mode(poly_int<1u, unsigned long>,
machine_mode)
        ../../gcc/tree.cc:10548
0x151d2ed vectorizable_simd_clone_call
        ../../gcc/tree-vect-stmts.cc:4502
0x15392da vect_analyze_stmt(vec_info*, _slp_tree*, _slp_instance*,
vec<stmt_info_for_cost, va_heap, vl_ptr>*)
        ../../gcc/tree-vect-stmts.cc:13146
```

The file compiles without an ICE with plain `-m32`, `-msse4.2` or `-m64`; the
vectorizer should reject the clone or leave the loop scalar.

Found at commit f16aa1c29ef9fe49ef11f9735e8d01954dfb8b01, and it still
reproduces at 4dee18cade51d955d9cd6dc86f4399be133a2821 (same assertion, now at
tree.cc:10552). The checking build fails with the assertion above (exit 4). The
release build fails too: exit 4, same ICE message.

Looks like the non-integer-mask-mode branch in
`tree-vect-stmts.cc:vectorizable_simd_clone_call` (around line 4497) passes the
inbranch clone's mask argument vector type to
`build_truth_vector_type_for_mode`, and with `-m32` that type's mode is
probably `BLKmode`, which trips `gcc_assert (mask_mode != BLKmode)`. Not
verified.

Found with an LLM-based testing tool; I used Claude to reduce it and look for
the cause.

Reply via email to