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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-10-19
                 CC|                            |rguenth at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
It's not so easy (not an easy fit into existing optimization passes).  This
is because 'i' is considered a global variable and the optimization is only
valid because we know that 'i' is zero at program start.

Then for optimizing i = i % 10 to if (i == 10) i = 0; we have to know
that i actually reaches 10 (and not 11).

This means we have to compute sth like the scalar evolution of the memory
'i' which only evolves across multiple invocations of next_trivial().

If this happens in SPEC then other compilers probably pattern-match this
kind of thing ...

A "proper" analysis might transform a function body with local statics
into

  reg_static_var = static_var;
  while (1)
    {
  ... body ...
    }
  static_var = reg_static_var;

and analyze multiple invocations as if they were directly in a loop.  All
other global input would need to be treated volatile.

Eventually the SCEV infrastructure has enough to hack this up and the
prerequesite would be a single load from the static var at function
entry and a single store at function exit.

Reply via email to