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

            Bug ID: 128224
           Summary: vectorizer: ICE in vect_transform_loop on unused
                    inbranch simd clone call with -fno-tree-dce
                    -fno-tree-dse
           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 -fno-tree-dce and -fno-tree-dse, the vectorizer hits a gcc_assert in
vect_transform_loop on a conditional call to an `omp declare simd inbranch`
function whose result is unused.

```c
#pragma omp declare simd simdlen(4) inbranch
extern int f(int) __attribute__((const));
void g(int *restrict d, int n) {
#pragma omp simd
  for (int i = 0; i < n; i++)
    if (d[i] > 0)
      {
        int u = f(d[i]);
        d[i]++;
      }
}
```

```
gcc -O3 -fopenmp-simd -fno-tree-dce -fno-tree-dse -march=haswell -c c12b.c
```

```
c12b.c: In function 'g':
c12b.c:3:6: internal compiler error: in vect_transform_loop, at
tree-vect-loop.cc:11655
0x8f8f09 vect_transform_loop(_loop_vec_info*, gimple*)
        ../../gcc/tree-vect-loop.cc:11655
0x15b3bdb vect_transform_loops
        ../../gcc/tree-vectorizer.cc:1039
0x15b42c3 try_vectorize_loop_1
        ../../gcc/tree-vectorizer.cc:1188
```

I expected the dead call to be dropped and the loop compiled, as it is when the
call result is not assigned (`f(d[i]);`), or when DCE/DSE are left on.

Found at f16aa1c29ef9fe49ef11f9735e8d01954dfb8b01 (assertion at
tree-vect-loop.cc:11544), and it still reproduces at
4dee18cade51d955d9cd6dc86f4399be133a2821 (line 11655). The checking build and
the release build both fail the same way: internal compiler error in
vect_transform_loop. Either option alone does not trigger it, and neither does
the default x86-64 baseline without -march=haswell. The input is not from a
real program; a testing tool found it.

Looks like the IFN_MASK_CALL handling in tree-vect-loop.cc:vect_transform_loop
does `gcc_assert (!gimple_call_lhs (stmt_info->stmt))` for a call that is
neither relevant nor live, assuming DCE/DSE already removed dead calls with an
lhs. I have not tried a patch.

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

Reply via email to