You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cmd/compile: tweak inlining to favor PPARAM call sites
If a function f being considered for inlining calls
one of its parameters, reduce the normal cost of that
call (57) to 17 to increase the chance that f will
be inlined and (with luck) that parameter will be
revealed as a constant function (which unblocks
escape analysis) or perhaps even be inlined.
The least-change value for that was still effective for
iter_test benchmarks was 32; however tests showed no
particular harm even when reduced as low as 7, and there
have been reports of other performance problems with
rangefunc overheads and so I picked a middling number
in hopes of warding off such reports.
Updates #69015
Change-Id: I2a525c1beffb9f88daa14caa8a622864b023675c
Reviewed-on: https://go-review.googlesource.com/c/go/+/609095
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
Reviewed-by: Tim King <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
Copy file name to clipboardExpand all lines: src/cmd/compile/internal/inline/inl.go
+9-1Lines changed: 9 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -49,6 +49,7 @@ const (
49
49
inlineExtraAppendCost=0
50
50
// default is to inline if there's at most one call. -l=4 overrides this by using 1 instead.
51
51
inlineExtraCallCost=57// 57 was benchmarked to provided most benefit with no bad surprises; see https://github.com/golang/go/issues/19348#issuecomment-439370742
52
+
inlineParamCallCost=17// calling a parameter only costs this much extra (inlining might expose a constant function)
52
53
inlineExtraPanicCost=1// do not penalize inlining panics.
53
54
inlineExtraThrowCost=inlineMaxBudget// with current (2018-05/1.11) code, inlining runtime.throw does not help.
54
55
@@ -520,6 +521,10 @@ opSwitch:
520
521
}
521
522
}
522
523
524
+
// A call to a parameter is optimistically a cheap call, if it's a constant function
525
+
// perhaps it will inline, it also can simplify escape analysis.
526
+
extraCost:=v.extraCallCost
527
+
523
528
ifn.Fun.Op() ==ir.ONAME {
524
529
name:=n.Fun.(*ir.Name)
525
530
ifname.Class==ir.PFUNC {
@@ -539,6 +544,9 @@ opSwitch:
539
544
}
540
545
}
541
546
}
547
+
ifname.Class==ir.PPARAM {
548
+
extraCost=min(extraCost, inlineParamCallCost)
549
+
}
542
550
}
543
551
544
552
ifcheap {
@@ -572,7 +580,7 @@ opSwitch:
572
580
}
573
581
574
582
// Call cost for non-leaf inlining.
575
-
v.budget-=v.extraCallCost
583
+
v.budget-=extraCost
576
584
577
585
caseir.OCALLMETH:
578
586
base.FatalfAt(n.Pos(), "OCALLMETH missed by typecheck")
0 commit comments