From 80ced393965eb74382c4df63e74461f0bf144c55 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 23 Apr 2020 16:22:37 -0700 Subject: [PATCH] cmd/compile: add more non-ID comparisons to schedule 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 TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/schedule.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cmd/compile/internal/ssa/schedule.go b/src/cmd/compile/internal/ssa/schedule.go index 89407f27df..8facb91100 100644 --- a/src/cmd/compile/internal/ssa/schedule.go +++ b/src/cmd/compile/internal/ssa/schedule.go @@ -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 } -- 2.50.0