On 1/30/06, Joern RENNECKE <[EMAIL PROTECTED]> wrote: > gimplify.c:gimplify_modify_expr_rhs tries to optimize calls to functions > which return their value in memory, if the result is assigned to a > variable, by using the address of that variable as the location where > the result is top be stored. It uses lang_hooks.mark_addressable to > mark the variable > as addressable. > There is a preceding check that is supposed to verify that the variable > is not a register variable, but the function called - > is_gimple_reg_type - is really more a heuristic for optimizations. > The necessary information to decide if we can safely call > lang_hooks.mark_addressable is not available in a frontend-independet > manner. I think we need a new frontend hook that can tell an optimizer > if a call to lang_hooks.mark_addressable would succeed.
Is this optimization really legit? I've never come across an ABI which actually requires functions that return structures by value to leave the return value buffer untouched until just before they return. Consider code like this: struct f { int a, b }; struct f x; struct f foo (void) { struct f y; y.a = 42; y.b = x.a; return y; } struct f bar () { x = foo (); return x; } The ABI's I've seen permit foo to actually store the 42 directly into the 'a' slot of their return buffer, before fetching x.a. If bar then passes x itself to foo as its return value buffer, then you wipe out x.a before you have a chance to reference it.