On Mon, May 3, 2021 at 11:02 AM Eric Botcazou <[email protected]> wrote: > > Hi, > > when a call to a function is inlined and takes a parameter whose type is not > gimple_reg, a variable is created in the caller to hold a copy of the argument > passed in the call with the following comment: > > /* We may produce non-gimple trees by adding NOPs or introduce > invalid sharing when operand is not really constant. > It is not big deal to prohibit constant propagation here as > we will constant propagate in DOM1 pass anyway. * > > Of course the second sentence of the comment does not apply to non-gimple_reg > values, unless they get SRAed later, because we do not do constant propagation > for them. This for example prevents two identical calls to a pure function > from being merged in the attached Ada testcase. > > Therefore the attached patch attempts to reuse a read-only or non-addressable > local DECL of the caller, the hitch being that expand_call_inline needs to be > prevented from creating a CLOBBER for the cases where it ends uo being reused. > > Tested on x86-64/Linux, OK for the mainline?
Hmm, instead of (ab-)using debug_map can we instead use sth like setting TREE_VISITED on the argument decl (not the value - it might be passed multiple tiimes)? IIRC TREE_VISITED state is undetermined thus we can clear it at the start of setup_one_parameter and set it when we want to avoid the clobber and then test for this later? In the end I'd even find using a new bitmap to record parameter decl UIDs cleaner ... (I'm not sure if we not end up doing tree walks that might clobber TREE_VISITED here). Otherwise looks OK. Thanks, Richard. > > 2021-05-03 Eric Botcazou <[email protected]> > > * tree-inline.c (setup_one_parameter): Do not create a variable if the > value is either a read-only DECL or a non-addressable local variable. > Register the variable thus reused instead of creating a new one. > (expand_call_inline): Do not generate a CLOBBER for these variables. > > > 2021-05-03 Eric Botcazou <[email protected]> > > * gnat.dg/opt94.adb: New test. > * gnat.dg/opt94_pkg.ads, opt94.adb: New helper. > > -- > Eric Botcazou
