News for hackers. Stuff that matters.
Re:Incrementing vectors by gpderetta on Tuesday August 27, 2019 @11:56AM (#20811036)
If I'm reading the generated asm correctly (which I might well be not), the following function is vectorized conditional to a runtime alias check (the non vectorized case is completely removed if the pragma is uncommented). So even scalars seem to be handled:

  void inc(float* x, float*  c, size_t n)
  {
    //#pragma GCC ivdep
    for (int i = 0; i < n; ++i)
      x[i]+= *c;
  }
the issue really seems to be that the compiler just gives up very early if the iteration count is not a loop invariant.
Re:Incrementing vectors by BeeOnRope on Tuesday August 27, 2019 @04:14PM (#20813988)
Yeah, I read it the same as you: so alias checks can definitely happen even for single values.

It seems like it's not just the loop counts that's the problem: in the blog post even when size is a local, it fails to check to see if the vector array pointer itself can alias.

I.e., analogous to incB here:

https://godbolt.org/z/ptQZcs

incA is like your example: the possibly aliasing is between the array and the value added, and an alias check occurs. incB is like the v[i] example: possible aliasing is between the array and the pointer to the same array, no check and conservative code is generated.

Interesting...