]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add Value.Uses comparison during scheduling
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 23 Apr 2020 22:30:19 +0000 (15:30 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 24 Apr 2020 21:12:21 +0000 (21:12 +0000)
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 <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/ssa/schedule.go

index 5a77910bde042e9a10fa80780c80fb9b45b6d5a4..89407f27dfc06bc200b6d114fead14c7ba0251d4 100644 (file)
@@ -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
 }