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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-03-03
             Status|UNCONFIRMED                 |NEW
          Component|tree-optimization           |ipa
     Ever confirmed|0                           |1
                 CC|                            |hubicka at gcc dot gnu.org,
                   |                            |marxin at gcc dot gnu.org,
                   |                            |rguenth at gcc dot gnu.org
           Keywords|                            |missed-optimization

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
We have no "flow sensitive" analysis of global variable values.  When you
remove the 'a = 0' assignment we figure a is never written to and promote it
constant which then allows constant folding of the read.

Now we could eventually enhance that analysis to ignore writes that store
the same value as the initializer (and also make sure to remove those
later).

But consider

static int a = 0;
extern void bar(void);
int main() {
    if (a)
        bar();
    a = 1;
    return 0;
}

which would be still valid to be optimized to just

int main()
{
  return 0;
}

eliding the call and the variable 'a' completely (since it's unused).

Thus it's also a missed dead store elimination (for which we'd need to
know if there are any finalizers referencing 'a' for example).

Reply via email to