Skip to content

Commit 06fd2f1

Browse files
dr2chasecagedmantis
authored andcommitted
[release-branch.go1.24] cmd/compile: remove no-longer-necessary recursive inlining checks
this does result in a little bit more inlining, cmd/compile text is 0.5% larger, bent-benchmark text geomeans grow by only 0.02%. some of our tests make assumptions about inlining. Fixes: #73440. Change-Id: I999d1798aca5dc64a1928bd434258a61e702951a Reviewed-on: https://go-review.googlesource.com/c/go/+/655157 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/go/+/666555 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Carlos Amedee <[email protected]>
1 parent f66ab65 commit 06fd2f1

File tree

9 files changed

+21
-85
lines changed

9 files changed

+21
-85
lines changed

src/cmd/cgo/internal/test/issue42018_windows.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func test42018(t *testing.T) {
2727
recurseHWND(400, hwnd, uintptr(unsafe.Pointer(&i)))
2828
}
2929

30+
//go:noinline
3031
func recurseHANDLE(n int, p C.HANDLE, v uintptr) {
3132
if n > 0 {
3233
recurseHANDLE(n-1, p, v)
@@ -36,6 +37,7 @@ func recurseHANDLE(n int, p C.HANDLE, v uintptr) {
3637
}
3738
}
3839

40+
//go:noinline
3941
func recurseHWND(n int, p C.HWND, v uintptr) {
4042
if n > 0 {
4143
recurseHWND(n-1, p, v)

src/cmd/compile/internal/inline/inl.go

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,8 @@ func CanInlineFuncs(funcs []*ir.Func, profile *pgoir.Profile) {
170170
}
171171

172172
ir.VisitFuncsBottomUp(funcs, func(funcs []*ir.Func, recursive bool) {
173-
numfns := numNonClosures(funcs)
174-
175173
for _, fn := range funcs {
176-
if !recursive || numfns > 1 {
177-
// We allow inlining if there is no
178-
// recursion, or the recursion cycle is
179-
// across more than one function.
180-
CanInline(fn, profile)
181-
} else {
182-
if base.Flag.LowerM > 1 && fn.OClosure == nil {
183-
fmt.Printf("%v: cannot inline %v: recursive\n", ir.Line(fn), fn.Nname)
184-
}
185-
}
174+
CanInline(fn, profile)
186175
if inlheur.Enabled() {
187176
analyzeFuncProps(fn, profile)
188177
}
@@ -1023,68 +1012,6 @@ func canInlineCallExpr(callerfn *ir.Func, n *ir.CallExpr, callee *ir.Func, bigCa
10231012
}
10241013
}
10251014

1026-
if callee == callerfn {
1027-
// Can't recursively inline a function into itself.
1028-
if log && logopt.Enabled() {
1029-
logopt.LogOpt(n.Pos(), "cannotInlineCall", "inline", fmt.Sprintf("recursive call to %s", ir.FuncName(callerfn)))
1030-
}
1031-
return false, 0, false
1032-
}
1033-
1034-
isClosureParent := func(closure, parent *ir.Func) bool {
1035-
for p := closure.ClosureParent; p != nil; p = p.ClosureParent {
1036-
if p == parent {
1037-
return true
1038-
}
1039-
}
1040-
return false
1041-
}
1042-
if isClosureParent(callerfn, callee) {
1043-
// Can't recursively inline a parent of the closure into itself.
1044-
if log && logopt.Enabled() {
1045-
logopt.LogOpt(n.Pos(), "cannotInlineCall", "inline", fmt.Sprintf("recursive call to closure parent: %s, %s", ir.FuncName(callerfn), ir.FuncName(callee)))
1046-
}
1047-
return false, 0, false
1048-
}
1049-
if isClosureParent(callee, callerfn) {
1050-
// Can't recursively inline a closure if there's a call to the parent in closure body.
1051-
if ir.Any(callee, func(node ir.Node) bool {
1052-
if call, ok := node.(*ir.CallExpr); ok {
1053-
if name, ok := call.Fun.(*ir.Name); ok && isClosureParent(callerfn, name.Func) {
1054-
return true
1055-
}
1056-
}
1057-
return false
1058-
}) {
1059-
if log && logopt.Enabled() {
1060-
logopt.LogOpt(n.Pos(), "cannotInlineCall", "inline", fmt.Sprintf("recursive call to closure parent: %s, %s", ir.FuncName(callerfn), ir.FuncName(callee)))
1061-
}
1062-
return false, 0, false
1063-
}
1064-
}
1065-
do := func(fn *ir.Func) bool {
1066-
// Can't recursively inline a function if the function body contains
1067-
// a call to a function f, which the function f is one of the call arguments.
1068-
return ir.Any(fn, func(node ir.Node) bool {
1069-
if call, ok := node.(*ir.CallExpr); ok {
1070-
for _, arg := range call.Args {
1071-
if call.Fun == arg {
1072-
return true
1073-
}
1074-
}
1075-
}
1076-
return false
1077-
})
1078-
}
1079-
for _, fn := range []*ir.Func{callerfn, callee} {
1080-
if do(fn) {
1081-
if log && logopt.Enabled() {
1082-
logopt.LogOpt(n.Pos(), "cannotInlineCall", "inline", fmt.Sprintf("recursive call to function: %s", ir.FuncName(fn)))
1083-
}
1084-
return false, 0, false
1085-
}
1086-
}
1087-
10881015
if base.Flag.Cfg.Instrumenting && types.IsNoInstrumentPkg(callee.Sym().Pkg) {
10891016
// Runtime package must not be instrumented.
10901017
// Instrument skips runtime package. However, some runtime code can be

src/runtime/pprof/proto_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ func TestConvertCPUProfileNoSamples(t *testing.T) {
7373
checkProfile(t, p, 2000*1000, periodType, sampleType, nil, "")
7474
}
7575

76+
//go:noinline
7677
func f1() { f1() }
78+
79+
//go:noinline
7780
func f2() { f2() }
7881

7982
// testPCs returns two PCs and two corresponding memory mappings

test/fixedbugs/issue40954.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func main() {
3030
// should not be adjusted when the stack is copied.
3131
recurse(100, p, v)
3232
}
33+
34+
//go:noinline
3335
func recurse(n int, p *S, v uintptr) {
3436
if n > 0 {
3537
recurse(n-1, p, v)

test/fixedbugs/issue52193.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ package p
1111

1212
func f() { // ERROR "can inline f"
1313
var i interface{ m() } = T(0) // ERROR "T\(0\) does not escape"
14-
i.m() // ERROR "devirtualizing i.m" "inlining call to T.m"
14+
i.m() // ERROR "devirtualizing i.m" "inlining call to T.m" "inlining call to f" "T\(0\) does not escape"
1515
}
1616

1717
type T int
1818

1919
func (T) m() { // ERROR "can inline T.m"
2020
if never {
21-
f() // ERROR "inlining call to f" "devirtualizing i.m" "T\(0\) does not escape"
21+
f() // ERROR "inlining call to f" "devirtualizing i.m" "T\(0\) does not escape" "inlining call to T.m"
2222
}
2323
}
2424

test/fixedbugs/issue54159.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
package main
88

9-
func run() { // ERROR "cannot inline run: recursive"
9+
//go:noinline
10+
func run() { // ERROR "cannot inline run: marked go:noinline"
1011
f := func() { // ERROR "can inline run.func1 with cost .* as:.*" "func literal does not escape"
1112
g() // ERROR "inlining call to g"
1213
}

test/inline.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,13 @@ func ff(x int) { // ERROR "can inline ff"
280280
if x < 0 {
281281
return
282282
}
283-
gg(x - 1) // ERROR "inlining call to gg" "inlining call to hh"
283+
gg(x - 1) // ERROR "inlining call to gg" "inlining call to hh" "inlining call to ff"
284284
}
285285
func gg(x int) { // ERROR "can inline gg"
286-
hh(x - 1) // ERROR "inlining call to hh" "inlining call to ff"
286+
hh(x - 1) // ERROR "inlining call to hh" "inlining call to ff" "inlining call to gg"
287287
}
288288
func hh(x int) { // ERROR "can inline hh"
289-
ff(x - 1) // ERROR "inlining call to ff" "inlining call to gg"
289+
ff(x - 1) // ERROR "inlining call to ff" "inlining call to gg" "inlining call to hh"
290290
}
291291

292292
// Issue #14768 - make sure we can inline for loops.
@@ -332,9 +332,9 @@ func ii() { // ERROR "can inline ii"
332332
// Issue #42194 - make sure that functions evaluated in
333333
// go and defer statements can be inlined.
334334
func gd1(int) {
335-
defer gd1(gd2()) // ERROR "inlining call to gd2"
335+
defer gd1(gd2()) // ERROR "inlining call to gd2" "can inline gd1.deferwrap1"
336336
defer gd3()() // ERROR "inlining call to gd3"
337-
go gd1(gd2()) // ERROR "inlining call to gd2"
337+
go gd1(gd2()) // ERROR "inlining call to gd2" "can inline gd1.gowrap2"
338338
go gd3()() // ERROR "inlining call to gd3"
339339
}
340340

test/loopbce.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func f5_int8(a [10]int) int {
8888
return x
8989
}
9090

91+
//go:noinline
9192
func f6(a []int) {
9293
for i := range a { // ERROR "Induction variable: limits \[0,\?\), increment 1$"
9394
b := a[0:i] // ERROR "(\([0-9]+\) )?Proved IsSliceInBounds$"

test/newinline.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,13 @@ func ff(x int) { // ERROR "can inline ff"
280280
if x < 0 {
281281
return
282282
}
283-
gg(x - 1) // ERROR "inlining call to gg" "inlining call to hh"
283+
gg(x - 1) // ERROR "inlining call to gg" "inlining call to hh" "inlining call to ff"
284284
}
285285
func gg(x int) { // ERROR "can inline gg"
286-
hh(x - 1) // ERROR "inlining call to hh" "inlining call to ff"
286+
hh(x - 1) // ERROR "inlining call to hh" "inlining call to ff" "inlining call to gg"
287287
}
288288
func hh(x int) { // ERROR "can inline hh"
289-
ff(x - 1) // ERROR "inlining call to ff" "inlining call to gg"
289+
ff(x - 1) // ERROR "inlining call to ff" "inlining call to gg" "inlining call to hh"
290290
}
291291

292292
// Issue #14768 - make sure we can inline for loops.

0 commit comments

Comments
 (0)