This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: New GCC options for loop vectorization
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Xinliang David Li <davidxl at google dot com>
- Cc: Richard Biener <richard dot guenther at gmail dot com>, "Joseph S. Myers" <joseph at codesourcery dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 17 Sep 2013 17:45:22 +0200
- Subject: Re: New GCC options for loop vectorization
- Authentication-results: sourceware.org; auth=none
- References: <CAAkRFZJzPkDJe=y2RqDwXsegN1So-u8mvUM2Cc2=4yZm29ip5g at mail dot gmail dot com> <CAFiYyc204YzVZVSOKnzomiMZs0Spe7=8AMUz+ho-xzr6beahXg at mail dot gmail dot com> <CAAkRFZJ7ZFBK86f8ZUpq_YgnCj0d3GK=3r1QUGqp5_QzgEzx3w at mail dot gmail dot com> <CAFiYyc0g3V_CrHkhquZS=Fie4cD4rZNFArpj+72+QkEkCw1Uyg at mail dot gmail dot com> <CAAkRFZK0ueehNqELXqbupG6VrYOT_g=HbjYtQGuzsDR=e04QnQ at mail dot gmail dot com> <CAFiYyc3MOHYHFUqVVCorZvDXO0wp00N=F4qP8rVG2nxF0Oji_g at mail dot gmail dot com> <CAAkRFZ+=rZ+7qX=1On1JNBe-hKK=rstp_L430wWKjPJxhtVuFg at mail dot gmail dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Sep 17, 2013 at 08:37:57AM -0700, Xinliang David Li wrote:
> >> char a[10000];
> >>
> >> void foo(int n)
> >> {
> >> int* b = (int*)(a+n);
> >> int i = 0;
> >> for (; i < 1000; ++i)
> >> b[i] = 1;
> >> }
> >>
> >> int main(int argn, char** argv)
> >> {
> >> foo(argn);
> >> }
> >
> > But that's just a bug that should be fixed (looking into it).
>
> This kind of code is not uncommon for certain applications (e.g, group
> varint decoding). Besides, the code like this may be built with
That is irrelevant to the fact that it is invalid.
> -fno-strict-aliasing.
It isn't invalid because of aliasing violations, but because of unaligned
access without saying that it is unaligned (say accessing through
aligned(1) type, or packed struct or similar, or doing memcpy).
On various architectures unaligned accesses don't cause faults, so it
may appear to work, and even on i?86/x86_64 often appears to work, as
long as you aren't trying to vectorize code (which doesn't change anything
on the fact that it is undefined behavior).
Jakub