]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add more non-ID comparisons to schedule
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 23 Apr 2020 23:22:37 +0000 (16:22 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Fri, 24 Apr 2020 21:13:36 +0000 (21:13 +0000)
These comparisons are fairly arbitrary,
but they should be more stable in the face
of other compiler changes than value ID.

This reduces the number of value ID
comparisons in schedule while running
make.bash from 542,442 to 99,703.

There are lots of changes to generated code
from this change, but they appear to
be overall neutral.

It is possible to further reduce the
number of comparisons in schedule;
I have changes locally that reduce the
number to about 25,000 during make.bash.
However, the changes are increasingly
complex and arcane, and reduce in much less
code churn. Given that the goal is stability,
that suggests that this is a reasonable
place to stop, at least for now.

Change-Id: Ie3a75f84fd3f3fdb102fcd0b29299950ea66b827
Reviewed-on: https://go-review.googlesource.com/c/go/+/229799
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 89407f27dfc06bc200b6d114fead14c7ba0251d4..8facb91100c5e79de0337d8de96a9608464a996c 100644 (file)
@@ -5,6 +5,7 @@
 package ssa
 
 import (
+       "cmd/compile/internal/types"
        "container/heap"
        "sort"
 )
@@ -62,6 +63,15 @@ func (h ValHeap) Less(i, j int) bool {
        if c := x.Uses - y.Uses; c != 0 {
                return c < 0 // smaller uses come later
        }
+       // These comparisons are fairly arbitrary.
+       // The goal here is stability in the face
+       // of unrelated changes elsewhere in the compiler.
+       if c := x.AuxInt - y.AuxInt; c != 0 {
+               return c > 0
+       }
+       if cmp := x.Type.Compare(y.Type); cmp != types.CMPeq {
+               return cmp == types.CMPgt
+       }
        return x.ID > y.ID
 }