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

--- Comment #14 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Alexander Monakov from comment #9)
> I don't understand how LIM may deduce that store sinking is safe without
> considering may-alias relations. If it is UB to write the same object from
> different declared-independent iterations, then I think the correct
> deduction would be "iteration count is at most 1", not "store sinking is
> safe"?
> 
> 
> A C++ variation of the test, doesn't need -fno-tree-sra or asm() shenanigans:
> 
> void g(int p, int *out)
> {
>   int x = 0, y;
> #pragma GCC ivdep
>   for (int i = 0; i < 100; i++)
>     {
>       int &r = p ? x : y;
>       r = 42;
>       out[i] = x;
>     }
> }

Given OMP simdlen docs pretty clearly say we need to preserve forward
dependences
the transform we do is invalid.  simdlen tells us the only thing we can do
(without doing dependence analysis ourselves) is to interleave iterations like

  stmt1_iteration1
  stmt1_iteration2
  ...
  stmt1_iterationN
  stmt2_iteration1
  stmt2_iteration2
  ...

thus for the example

    r = 42;
    r = 42;
...
    out[0] = x;
    out[1] = x;
....

but that's not really useful information for the transform LIM is performing
(neither for invariant motion nor store motion).  So I think the only
option is to remove the safelen usage from LIM.

I will prepare a patch to do that.

Reply via email to