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

            Bug ID: 129292
           Summary: [16/17 Regression] wrong code at -O2: SLP reduction
                    group, out-of-loop use of the second lane's
                    intermediate add is never replaced
                    (vectorizable_live_operation skips non-zero lanes)
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 0599jiangyc at gmail dot com
  Target Milestone: ---

The following code:

```c
unsigned a[8][3], b[8];

__attribute__((noipa)) int
f (void)
{
  int s0 = 0, s1 = 0;
  unsigned c = 0;
  for (int t = 0; t < 8; t++)
    {
      c += b[t];
      s0 += a[t][0];
      s1 += a[t][1];
    }
  return (s0 < 8 || s0 > 100) + s1 + c;
}

int
main ()
{
  for (int i = 0; i < 8; i++)
    a[i][0] = 1;
  if (f () != 0)        /* s0 == 8, s1 == 0, c == 0 */
    __builtin_abort ();
  return 0;
}
```

Resulted in this output:
```
$ gcc -O2 repro.c && ./a.out
Aborted (core dumped)
(also -O3 and -O3 -march=x86-64-v3; -O0/-O1/-Os and -O2
-fno-tree-loop-vectorize exit 0)
```

Trunk: https://godbolt.org/z/nfehnez6e
- GCC 16.1, 16.2 and trunk abort; GCC 15.3 and older are OK.
- Reproduced with unpatched upstream trunk d1dbc89caa5 of 2026-11-26.

Reply via email to