http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49651

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |rguenth at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #8 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-07-14 
12:26:08 UTC ---
In the optimized dump I can see

<bb 4>:
...
  run.__v7 = &v7;
  run.__a = &a;
...

<bb 6>:
  # ivtmp.207_17 = PHI <ivtmp.207_68(10), ivtmp.207_69(5)>
  D.47092_58 = a;
  D.47093_59 = D.47092_58 + 1;
  a = D.47093_59;
  f (D.47092_58);

<bb 7>:
  D.47084_60 = MEM[(int * const &)&ve + 8];
  D.47090._M_current = D.47084_60;
  D.47083_61 = MEM[(int * const &)&ve];
  D.47089._M_current = D.47083_61;
  D.47091 = std::for_each<__gnu_cxx::__normal_iterator<int*, std::vector<int>
>, main(int, char**)::<lambda(int&)> > (D.47089, D.47090, run);

<bb 8>:
  D.47093_63 = D.47092_58 + 2;
  a = D.47093_63;
  f (D.47093_59);

<bb 9>:
  D.47082_64 = MEM[(int * const &)&ve + 8];
  D.47086._M_current = D.47082_64;
  D.47081_65 = MEM[(int * const &)&ve];
  D.47085._M_current = D.47081_65;
  D.47087 = std::for_each<__gnu_cxx::__normal_iterator<int*, std::vector<int>
>, main(int, char**)::<lambda(int&)> > (D.47085, D.47086, run);

<bb 10>:
  ivtmp.207_68 = ivtmp.207_17 + 4;
  __first$_M_current_66 = (int *) ivtmp.207_68;
  if (__last_27 != __first$_M_current_66)
    goto <bb 6>;
  else
...

so we do CSE a over the std::for_each invocation which gets run as argument.
That's wrong of course.  Alias-info tells us even that a is clobbered by
that call:

  # USE = nonlocal null { aD.40068 viD.40071 D.40875 veD.40876 D.40877
v7D.40878 }
  # CLB = nonlocal null { aD.40068 viD.40071 D.40875 veD.40876 D.40877
v7D.40878 }
  D.47091 = std::for_each<__gnu_cxx::__normal_iterator<int*, std::vector<int>
>, main(int, char**)::<lambda(int&)> > (D.47089, D.47090, runD.40880);

but it doesn't do so at the time when the first FRE is run:

  # USE = nonlocal null { viD.40071 D.40875 veD.40876 D.40877 v7D.40878 }
  # CLB = nonlocal null { viD.40071 D.40875 veD.40876 D.40877 v7D.40878 }
  D.47091 = std::for_each<__gnu_cxx::__normal_iterator<int*, std::vector<int>
>, main(int, char**)::<lambda(int&)> > (D.47089, D.47090,
*__f$__runD.47077_57);

the setup there is still not very optimized though.

Reply via email to