aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/ssa/cse.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2015-07-15 14:38:19 -0600
committerJosh Bleecher Snyder <josharian@gmail.com>2015-07-23 18:06:04 +0000
commit8c954d57801d8ea855003425fbbbf78de8733e6a (patch)
treeb26f1457653032f71f993e5a29917b389e063c9a /src/cmd/compile/internal/ssa/cse.go
parent00437ebe73944854d58ddb6710a185677317ee6e (diff)
downloadgo-8c954d57801d8ea855003425fbbbf78de8733e6a.tar.gz
go-8c954d57801d8ea855003425fbbbf78de8733e6a.zip
[dev.ssa] cmd/compile: speed up cse
By walking only the current set of partitions at any given point, the cse pass ended up doing lots of extraneous, effectively O(n^2) work. Using a regular for loop allows each cse pass to make as much progress as possible by processing each new class as it is introduced. This can and should be optimized further, but it already reduces by 75% cse time on test/slice3.go. The overall time to compile test/slice3.go is still dominated by the O(n^2) work in the liveness pass. However, Keith is rewriting regalloc anyway. Change-Id: I8be020b2f69352234587eeadeba923481bf43fcc Reviewed-on: https://go-review.googlesource.com/12244 Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/ssa/cse.go')
-rw-r--r--src/cmd/compile/internal/ssa/cse.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/ssa/cse.go b/src/cmd/compile/internal/ssa/cse.go
index 9212aaf314..ebc25151b2 100644
--- a/src/cmd/compile/internal/ssa/cse.go
+++ b/src/cmd/compile/internal/ssa/cse.go
@@ -69,7 +69,10 @@ func cse(f *Func) {
for {
changed := false
- for i, e := range partition {
+ // partition can grow in the loop. By not using a range loop here,
+ // we process new additions as they arrive, avoiding O(n^2) behavior.
+ for i := 0; i < len(partition); i++ {
+ e := partition[i]
v := e[0]
// all values in this equiv class that are not equivalent to v get moved
// into another equiv class q.