]> git.ipfire.org Git - thirdparty/gcc.git/commit
Reuse non-gimple_reg variable for inlining
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 4 May 2021 10:47:11 +0000 (12:47 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Tue, 4 May 2021 10:54:13 +0000 (12:54 +0200)
commit93f8cb4965cebee125f96376367f05e18ee5749b
tree7c2e52b252af7e8b29870529caa3cd0bc6236701
parentf418bc3cd173bc4e679469928d4d96ffcc05fc7e
Reuse non-gimple_reg variable for inlining

When a call to a function is inlined and takes a parameter whose type is not
gimple_reg, a local 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 don't 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 case where it ends uo being reused.

gcc/
* tree-inline.c (insert_debug_decl_map): Delete.
(copy_debug_stmt): Minor tweak.
(setup_one_parameter): Do not use a variable if the value is either
a read-only DECL or a non-addressable local variable in the caller.
In this case, insert the debug-only variable in the map manually.
(expand_call_inline): Do not generate a CLOBBER for these values.
* tree-inline.h (debug_map): Minor tweak.
gcc/testsuite/gnat.dg/opt94.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/opt94_pkg.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/opt94_pkg.ads [new file with mode: 0644]
gcc/tree-inline.c
gcc/tree-inline.h