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

--- Comment #3 from Tijl Coosemans <tijl at coosemans dot org> 2012-03-27 
11:33:41 UTC ---
(In reply to comment #2)
> Hm.  We delay evaluating __builtin_constant_p to make it possible for inlining
> to lead to simplifications that result in a constant.  We could of course
> evaluate early if there are any side-effects in its argument, but that would
> change outcome in existing code bases.
> 
> What do you think specifies the behavior you are expecting?  Nothing
> explicitely says that the argument is not evaluated or that its
> side-effects are discarded.

Either the compiler always emits code to evaluate the argument or it never
emits code, but not something in between. That's just arbitrary.

I think it should never emit code because __builtin_constant_p is just a query
to the compiler: "Can you reduce this expression to a constant at compile time
or not?" It's not a request to emit code for the given expression.

It's ok for the compiler to inline the function and see if that can be reduced
to a constant, but that should not result in any code being emitted. If it does
it causes the compiler to make bad decisions such as in the first test program
where it needs an extra register (%ebx) that needs to be saved on the stack.

Reply via email to