[dev.simd] cmd/compile: inliner tweaks to favor simd-handling functions

this is partly to ensure that emulations get inlined

Change-Id: I14f1a591081a4c39b61e48957a1474217ed0a399
Reviewed-on: https://go-review.googlesource.com/c/go/+/705975
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
This commit is contained in:
David Chase 2025-09-22 15:06:42 -04:00
parent fb1749a3fe
commit 48756abd3a

View file

@ -179,6 +179,16 @@ func CanInlineFuncs(funcs []*ir.Func, profile *pgoir.Profile) {
})
}
func simdCreditMultiplier(fn *ir.Func) int32 {
for _, field := range fn.Type().RecvParamsResults() {
if field.Type.IsSIMD() {
return 3
break
}
}
return 1
}
// inlineBudget determines the max budget for function 'fn' prior to
// analyzing the hairiness of the body of 'fn'. We pass in the pgo
// profile if available (which can change the budget), also a
@ -186,9 +196,14 @@ func CanInlineFuncs(funcs []*ir.Func, profile *pgoir.Profile) {
// possibility that a call to the function might have its score
// adjusted downwards. If 'verbose' is set, then print a remark where
// we boost the budget due to PGO.
// Note that inlineCostOk has the final say on whether an inline will
// happen; changes here merely make inlines possible.
func inlineBudget(fn *ir.Func, profile *pgoir.Profile, relaxed bool, verbose bool) int32 {
// Update the budget for profile-guided inlining.
budget := int32(inlineMaxBudget)
budget *= simdCreditMultiplier(fn)
if IsPgoHotFunc(fn, profile) {
budget = inlineHotMaxBudget
if verbose {
@ -420,8 +435,8 @@ type hairyVisitor struct {
}
func isDebugFn(fn *ir.Func) bool {
// if n := fn.Nname; n != nil && n.Sym().Pkg.Path == "0" {
// if n.Sym().Name == "BroadcastInt64x4" {
// if n := fn.Nname; n != nil {
// if n.Sym().Name == "Int32x8.Transpose8" && n.Sym().Pkg.Path == "simd" {
// fmt.Printf("isDebugFn '%s' DOT '%s'\n", n.Sym().Pkg.Path, n.Sym().Name)
// return true
// }
@ -944,6 +959,8 @@ func inlineCostOK(n *ir.CallExpr, caller, callee *ir.Func, bigCaller, closureCal
maxCost = inlineBigFunctionMaxCost
}
simdMaxCost := simdCreditMultiplier(callee) * maxCost
if callee.ClosureParent != nil {
maxCost *= 2 // favor inlining closures
if closureCalledOnce { // really favor inlining the one call to this closure
@ -951,6 +968,8 @@ func inlineCostOK(n *ir.CallExpr, caller, callee *ir.Func, bigCaller, closureCal
}
}
maxCost = max(maxCost, simdMaxCost)
metric := callee.Inl.Cost
if inlheur.Enabled() {
score, ok := inlheur.GetCallSiteScore(caller, n)