Question about vectorization
Richard Biener
richard.guenther@gmail.com
Thu Jan 15 14:01:00 GMT 2015
On Thu, Jan 15, 2015 at 2:22 PM, Konstantin Vladimirov
<konstantin.vladimirov@gmail.com> wrote:
> Hi,
>
> Consider simple test:
>
> #include <stdlib.h>
>
> #ifdef FAILV
>
> unsigned short* get_aa(void);
> double* get_bb(void);
>
> #else
>
> extern unsigned short a[1024];
> extern double b[1024];
>
> #endif
>
>
> unsigned short *foo()
> {
> size_t i;
>
> #ifdef FAILV
> unsigned short * restrict aa = get_aa();
> double * restrict bb = get_bb();
> #else
> unsigned short * restrict aa = a;
> double * restrict bb = b;
> #endif
>
> for (i = 0; i < 1024; ++i)
> {
> *bb = *aa;
> ++bb; ++aa;
> }
>
> return aa;
> }
>
> Compile it with latest gcc, 4.8 or 4.9:
>
> gcc -O3 -ftree-vectorizer-verbose=2 --std=c99 -S test.c
> gcc -O3 -ftree-vectorizer-verbose=2 --std=c99 -S test.c -DFAILV
>
> In second case it outputs:
>
> test.c:28: note: versioning for alias required: can't determine
> dependence between *aa_22 and *bb_23
>
> So loop is vectorized but there is unnecessary aliasing check inside.
>
> But AFAIC, due to strong aliasing rules, compiler should statically
> know, that aliasing is not possible in that case.
It can know but only because it is in a loop. I belive this is fixed
already for GCC 5.
Richard.
> Is it a bug?
>
> ---
> With best regards, Konstantin
More information about the Gcc
mailing list