From 943a0d02d18bba5243f235fbbebd7f29d49d991e Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 23 Apr 2020 15:30:19 -0700 Subject: [PATCH] cmd/compile: add Value.Uses comparison during scheduling MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Falling back to comparing Value.ID during scheduling is undesirable: Not only are we simply hoping for a good outcome, but the decision we make will be easily perturbed by other compiler changes, leading to random fluctuations. This change adds another decision point to the scheduler by scheduling Values with many uses earlier. Values with fewer uses are less likely to be spilled for other reasons, so we should issue them as late as possible in the hope of avoiding a spill. This reduces the number of Value ID comparisons in schedule while running make.bash from 1,000,844 to 542,442. As you would expect, this changes a lot of functions, but the overall trend is positive: file before after Δ % api 5237184 5233088 -4096 -0.078% compile 19926480 19918288 -8192 -0.041% cover 5281816 5277720 -4096 -0.078% dist 3711608 3707512 -4096 -0.110% total 113588440 113567960 -20480 -0.018% Change-Id: Ic99ebc4c614d4ae3807ce44473ec6b04684388ec Reviewed-on: https://go-review.googlesource.com/c/go/+/229798 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/schedule.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cmd/compile/internal/ssa/schedule.go b/src/cmd/compile/internal/ssa/schedule.go index 5a77910bde..89407f27df 100644 --- a/src/cmd/compile/internal/ssa/schedule.go +++ b/src/cmd/compile/internal/ssa/schedule.go @@ -59,6 +59,9 @@ func (h ValHeap) Less(i, j int) bool { return c < 0 // smaller args comes later } } + if c := x.Uses - y.Uses; c != 0 { + return c < 0 // smaller uses come later + } return x.ID > y.ID } -- 2.48.1