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

--- Comment #4 from alalaw01 at gcc dot gnu.org ---
Here's another example, extracted from another benchmark - it vectorizes if
INDEX is defined to 'long' but not if INDEX is 'short':

#include <stdlib.h>

unsigned char *t_run_test(unsigned char *in, int N)
{
  unsigned char *out = malloc (N);

  for (unsigned INDEX i = 1; i < (N - 1); i++)
    out[i] = ((3 * in[i]) - in[i - 1] - in[i + 1]);

  return out;
}

However, the -Wunsafe-loop-optimizations doesn't give us anything useful here:

(successful case, warning printed)
$ aarch64-none-elf-gcc -O3 bmark2.c -DINDEX=long -S -Wunsafe-loop-optimizations
-fdump-tree-vect-details=stdout | grep vectorized
bmark2.c:7:3: note: === vect_mark_stmts_to_be_vectorized ===
bmark2.c:7:3: note: loop vectorized
bmark2.c:3:16: note: vectorized 1 loops in function.
bmark2.c: In function 't_run_test':
bmark2.c:3:16: warning: cannot optimize loop, the loop counter may overflow
[-Wunsafe-loop-optimizations]
 unsigned char *t_run_test(unsigned char *in, int N)

(unsuccessful case, no warning)
$ aarch64-none-elf-gcc -O3 bmark2.c -DINDEX=short -S
-Wunsafe-loop-optimizations -fdump-tree-vect-details=stdout | grep vectorized
bmark2.c:7:3: note: not vectorized: number of iterations cannot be computed.
bmark2.c:3:16: note: vectorized 0 loops in function.

Reply via email to