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

            Bug ID: 105968
           Summary: GCC vectorizes but reports that it did not vectorize
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: steveire at gmail dot com
  Target Milestone: ---

I'm looking for a way to know if GCC autovectorizes some code.

Starting with this testcase which I picked up somewhere:

```
#define N 10000
#define NTIMES 100000

double a[N] __attribute__ ((aligned (16)));
double b[N] __attribute__ ((aligned (16)));
double c[N] __attribute__ ((aligned (16)));
double r[N] __attribute__ ((aligned (16)));

int muladd (void) {
  int i, times;
  for (times = 0; times < NTIMES; times++) {
#if 1
    // count up
    for (i = 0; i < N; ++i)
        r[i] = (a[i] + b[i]) * c[i];
#else
    // count down (old gcc won't auto-vectorize)
    for (i = N-1; i >= 0; --i)
      r[i] = (a[i] + b[i]) * c[i];
#endif
  }
  return 0;
}
```

the command

```
g++ -O2 -ftree-vectorize -fno-verbose-asm -mavx2 -fopt-info-vec-all -c test.cpp
```

reports 

```
test.cpp:9:5: note: vectorized 1 loops in function.
```

However, with -O3, GCC reports that it did not vectorize:

```
g++ -O3 -ftree-vectorize -fno-verbose-asm -mavx2 -fopt-info-vec-all -c test.cpp
```

output:

```
test.cpp:9:5: note: vectorized 0 loops in function.
```

even though vector instructions are generated.

Demo https://godbolt.org/z/3o41r7jWc

Reply via email to