go/src/cmd/compile/internal/gc
Dan Scales ed7a8332c4 cmd/compile: allow mid-stack inlining when there is a cycle of recursion
We still disallow inlining for an immediately-recursive function, but allow
inlining if a function is in a recursion chain.

If all functions in the recursion chain are simple, then we could inline
forever down the recursion chain (eventually running out of stack on the
compiler), so we add a map to keep track of the functions we have
already inlined at a call site. We stop inlining when we reach a
function that we have already inlined in the recursive chain. Of course,
normally the inlining will have stopped earlier, because of the cost
function.

We could also limit the depth of inlining by a simple count (say, limit
max inlining of 10 at any given site). Would that limit other
opportunities too much?

Added a test in test/inline.go. runtime.BenchmarkStackCopyNoCache() is
also already a good test that triggers the check to stop inlining
when we reach the start of the recursive chain again.

For the bent benchmark suite, the performance improvement was mostly not
statistically significant, but the geomean averaged out to: -0.68%. The text size
increase was less than .1% for all bent benchmarks. The cmd/go text size increase
was 0.02% and the cmd/compile text size increase was .1%.

Fixes #29737

Change-Id: I892fa84bb07a947b3125ec8f25ed0e508bf2bdf5
Reviewed-on: https://go-review.googlesource.com/c/go/+/226818
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-04-03 21:43:52 +00:00
..
builtin cmd/compile: make isSmallMakeSlice checks slice cap only 2020-03-31 21:51:51 +00:00
testdata all: fix incorrect channel and API usage in some unit tests 2020-02-27 19:04:17 +00:00
alg.go runtime: make typehash match compiler generated hashes exactly 2020-03-10 16:26:59 +00:00
align.go cmd/compile: rename sizeof_Array and array_* to slice_* 2019-11-11 12:40:04 +00:00
bexport.go all: fix a bunch of misspellings 2019-11-15 21:04:43 +00:00
bimport.go
bitset.go
bootstrap.go
builtin.go cmd/compile: make isSmallMakeSlice checks slice cap only 2020-03-31 21:51:51 +00:00
builtin_test.go
bv.go
class_string.go
closure.go
const.go cmd/compile: remove guard for OCOMPLEX in evconst 2020-03-11 20:17:30 +00:00
constFold_test.go
dcl.go
dep_test.go
dump.go
dwinl.go
esc.go cmd/compile: restore more missing -m=2 escape analysis details 2019-11-07 21:59:16 +00:00
escape.go cmd/compile: avoid range over copy of array 2020-03-06 23:24:28 +00:00
export.go
fixedbugs_test.go
float_test.go cmd/compile: don't allow NaNs in floating-point constant ops 2020-03-04 04:49:54 +00:00
fmt.go cmd/compile: use a bytes.Buffer to format symbols 2020-03-11 16:29:44 +00:00
gen.go
global_test.go
go.go cmd/compile, runtime: use more registers for amd64 write barrier calls 2020-03-31 21:26:33 +00:00
gsubr.go cmd/compile, cmd/link: add coverage instrumentation for libfuzzer 2019-11-05 00:00:36 +00:00
iexport.go [dev.link] cmd/asm, cmd/compile: add back newobj flag 2020-03-23 14:38:49 +00:00
iface_test.go
iimport.go [dev.link] cmd/asm, cmd/compile: add back newobj flag 2020-03-23 14:38:49 +00:00
init.go cmd/compile: skip empty init function in fninit 2019-10-18 12:04:04 +00:00
initorder.go
inl.go cmd/compile: allow mid-stack inlining when there is a cycle of recursion 2020-04-03 21:43:52 +00:00
inl_test.go cmd/compile: implement compiler for riscv64 2020-01-18 14:41:40 +00:00
lang_test.go
lex.go cmd/compile: disable checkptr for //go:nosplit functions 2019-10-22 01:03:29 +00:00
lex_test.go all: fix incorrect channel and API usage in some unit tests 2020-02-27 19:04:17 +00:00
logic_test.go
main.go cmd/compile: allow mid-stack inlining when there is a cycle of recursion 2020-04-03 21:43:52 +00:00
mapfile_mmap.go
mapfile_read.go
mkbuiltin.go
mpfloat.go cmd/compile: resolve TODO of Mpflt.SetString 2019-10-30 04:55:05 +00:00
mpint.go
noder.go cmd/compile: avoid range over copy of array 2020-03-06 23:24:28 +00:00
obj.go [dev.link] all: merge branch 'master' into dev.link 2019-10-25 13:41:36 -04:00
op_string.go
order.go cmd/compile: mark Lsyms as readonly earlier 2020-02-26 19:30:21 +00:00
pgen.go cmd/compile: skip generating args_stackmap for "pulled" funcs 2020-03-23 03:56:18 +00:00
pgen_test.go
phi.go
plive.go cmd/compile: remove special handling for OpRISCV64SUBW in markUnsafePoints 2020-03-10 16:25:09 +00:00
pprof.go
racewalk.go
range.go all: fix a bunch of misspellings 2019-11-15 21:04:43 +00:00
reflect.go cmd/compile, cmd/link, runtime: make defers low-cost through inline code and extra funcdata 2019-10-24 13:54:11 +00:00
reproduciblebuilds_test.go
scc.go
scope.go
scope_test.go cmd/compile: assign correct declaration line to DIE of captured vars 2020-02-24 20:00:38 +00:00
select.go
shift_test.go
sinit.go cmd/compile: mark Lsyms as readonly earlier 2020-02-26 19:30:21 +00:00
sizeof_test.go cmd/compile, cmd/link, runtime: make defers low-cost through inline code and extra funcdata 2019-10-24 13:54:11 +00:00
ssa.go cmd/compile, runtime: use more registers for amd64 write barrier calls 2020-03-31 21:26:33 +00:00
ssa_test.go
subr.go cmd/compile: fix constant conversion involving complex types 2020-03-31 20:59:14 +00:00
swt.go cmd/compile/internal/gc: reword "declared and not used" error message 2019-10-28 23:34:13 +00:00
syntax.go cmd/compile: mark Lsyms as readonly earlier 2020-02-26 19:30:21 +00:00
timings.go
trace.go
truncconst_test.go
typecheck.go cmd/compile: fix constant conversion involving complex types 2020-03-31 20:59:14 +00:00
types.go
types_acc.go
universe.go cmd/compile: avoid range over copy of array 2020-03-06 23:24:28 +00:00
unsafe.go
util.go
walk.go cmd/compile: optimize len check when make slice 2020-03-31 23:39:12 +00:00
zerorange_test.go