https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128056
Bug ID: 128056
Summary: vectorizer: verify_gimple failed (vector 'constructor'
elements) on omp declare simd const function returning
_Bool
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 checking enabled, the vectorizer ICEs with "verify_gimple failed:
incorrect type of vector 'constructor' elements" on a loop calling a `const`
`#pragma omp declare simd` function that returns `_Bool`.
```c
#pragma omp declare simd
_Bool g(int x) __attribute__((const));
int a[1024]; _Bool b[1024];
void f(void){for(int i=0;i<1024;i++)b[i]=g(a[i]);}
```
```
gcc -O3 -fopenmp-simd -mavx -c reduced.c
```
```
reduced.c: In function 'f':
reduced.c:4:6: error: incorrect type of vector 'constructor' elements
4 | void f(void){for(int i=0;i<1024;i++)b[i]=g(a[i]);}
| ^
{_24, _29}
vect__2.10_30 = {_24, _29};
during GIMPLE pass: vect
reduced.c:4:6: internal compiler error: verify_gimple failed
0x285bf1b internal_error(char const*, ...)
../../gcc/diagnostic-global-context.cc:787
0x1283cce verify_gimple_in_cfg(function*, bool, bool)
../../gcc/tree-cfg.cc:5642
0x10ea64a execute_function_todo
../../gcc/passes.cc:2100
0x10eaddb execute_todo
../../gcc/passes.cc:2152
```
Found at commit f16aa1c29ef9fe49ef11f9735e8d01954dfb8b01; it still fails the
same way at 2c19a667c2ae1e69453efe5737c5fb4c834a1f31, the latest upstream I
checked. The build with checking enabled ICEs (exit 4, as above); the release
build without checking compiles this valid code (exit 0), and I read its
assembly for a related larger input (-mxop) and it looks correct, so this is
assertion-only. GCC 11.4 with -fchecking gives the same verifier error. It also
fails with -mxop, but not with plain SSE2, -mavx2, -mavx512f, without
-fopenmp-simd, or without `const`. The same error message was PR 107306 (closed
as fixed). PR 127784 (verify_gimple failure with omp declare simd, marked a
14/15/16 regression) may be related; I have not compared them.
Looks like the branch of `vectorizable_simd_clone_call` in
gcc/tree-vect-stmts.cc that builds a CONSTRUCTOR from several clone-call
results when the clone returns a narrower vector than the vectype: the pieces
have the clone's `_Bool` element type while the vectype has `unsigned char`
elements, and the sibling branch at the end of the function handles such a
mismatch with VIEW_CONVERT_EXPR.
Found with an LLM-based testing tool; I used Claude to reduce it and look for
the cause.