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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-05-27
           Keywords|                            |missed-optimization
                 CC|                            |rguenth at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
It works fine with the C frontend so I suspect PRE (which does the transform
there) is confused by the fact that g_value isn't marked as to not throwing.

const int g_value() __attribute__((pure,nothrow));
int bar(int n) {
    int s = 0;
    for (int i=0; i<n; ++i) {
        s += g_value() * i;
    }
    return s;
}

makes the case work.  Basically the number of times g_value is called
depends on whether one of it might throw.  That might be overly conservative
for pure (or const) functions.

Reply via email to