On Mon, Sep 14, 2020 at 12:56 PM Eric Botcazou <botca...@adacore.com> wrote: > > > No, so you're right - validity analysis is split. Still the cause you > > reference comes from RTL expansion which means RTL expansion should > > possibly do the disqualification here. The question is what makes the case > > you run into at -O0 impossible to trigger with -O1+? > > The key test in use_register_for_decl is: > > if (optimize) > return true; > > I think that all the preceding tests that return false cannot trigger in this > context - a parameter passed by invisible reference - so, by returning true > here, you're pretty much covered I think. > > > Maybe we can also avoid this spilling at -O0? > > The code wants to retrieve the parameter at all optimization levels. The > question is: register or stack slot? It uses use_register_for_decl to decide > as in other circumstances, but so you want to always force a register? > > Note that, since cgraph_node::expand_thunk has expanded the thunk in GIMPLE, > the function is no longer a thunk for the middle-end (cfun->is_thunk false). > > That being said, I can add another bit to cfun, e.g. is_gimple_thunk, and > force the use of a register above only in case the bit is true.
/* We don't set DECL_IGNORED_P for the function_result_decl. */ if (optimize) return true; /* We don't set DECL_REGISTER for the function_result_decl. */ return false; or maybe set (and check) DECL_REGISTER? But the above certainly looks like we can pick as we wish. > > Yeah, but the asm thunk tail-calls also at -O0. I guess tail-calling is > > forced here because gimple analysis sometimes would not mark the call. > > The low-level assembly thunks simply support the most simple thunks, see the > condition in expand_thunk. Moreover targets can opt out as they wish. > > -- > Eric Botcazou > >