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

--- Comment #7 from eric-gcc at omnifarious dot org 2011-09-13 22:15:16 UTC ---
(In reply to comment #6)
> (In reply to comment #5)
> > I still think it's a missed optimization opportunity.
> 
> Yes, it definitely is.  I'm just not sure whether it should be fixed by doing
> constexpr expansion in non-constant expression contexts in some cases, or
> improving normal optimization to handle this case.

That's an interesting question. I think improving normal optimization to handle
this case might prove to be rather tricky. It would basically require detecting
that a function could be constexpr even if it wasn't declared that way.
Otherwise, a deep recursion case like this is really a pain to deal with at
optimization time.

I can think of cases where I have created templates for finding GCDs (using
Euclid's algorithm), integer logarithms and integer exponents at compile time
that are not toy problems. GCDs in particular are at least is tricky as the
silly bad recursive Fibonacci number generator.

Of course, I'm only guessing. Compilers and optimizers are not my thing. It
just seems like using the constexpr logic in some cases would be a lot easier.

Reply via email to