[Bug tree-optimization/94836] Failure to optimize condition based on known value of static variable

2021-08-29 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94836

Andrew Pinski  changed:

   What|Removed |Added

   Severity|normal  |enhancement
   Keywords||missed-optimization

[Bug tree-optimization/94836] Failure to optimize condition based on known value of static variable

2020-04-30 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94836

Richard Biener  changed:

   What|Removed |Added

   Assignee|rguenth at gcc dot gnu.org |unassigned at gcc dot 
gnu.org
 Status|ASSIGNED|NEW
 CC||rguenth at gcc dot gnu.org

[Bug tree-optimization/94836] Failure to optimize condition based on known value of static variable

2020-04-30 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94836

--- Comment #2 from Richard Biener  ---
OK, so it's not that easy to do.  Consider

int f(int x)
{
static int s;

if (!s)
s = x;

return s;
}

which we cannot optimize in this way.  VN would need to work in a way
assigning the value 0 to 's' optimistically and if it eventually
arrives at s = x it would need to invalidate that optimistic assumption
and iterate.  That is it would need to see the function as

int f(int x)
{
static int s;
 # s = PHI <0, s'>

if (!s)
s = x;

return s;
 s' = s;
 goto start;
}

with the goto of course not explicit.  I suppose rather than integrating
the feature into their value-numbering scheme compilers implement special
purpose optimization (IIRC this pattern appears in SPEC).

[Bug tree-optimization/94836] Failure to optimize condition based on known value of static variable

2020-04-29 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94836

Richard Biener  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |rguenth at gcc dot 
gnu.org
   Last reconfirmed||2020-04-29
 Ever confirmed|0   |1
 Status|UNCONFIRMED |ASSIGNED

--- Comment #1 from Richard Biener  ---
Confirmed.  We do have varpool->used_by_single_function which we could use
to optimize this during VN.

Let me have a looksee.