Skip to content

Commit 77d3749

Browse files
committed
cmd/compile: speed up dom checking in cse
Process a slice of equivalent values by setting replaced values to nil instead of removing them from the slice to eliminate copying. Also take advantage of the entry number sort to break early once we reach a value in a block that is not dominated. For the code in issue #15112: Before: real 0m52.603s user 0m56.957s sys 0m1.213s After: real 0m22.048s user 0m26.445s sys 0m0.939s Updates #15112 Change-Id: I06d9e1e1f1ad85d7fa196c5d51f0dc163907376d Reviewed-on: https://go-review.googlesource.com/22068 Reviewed-by: David Chase <[email protected]>
1 parent d0e8d3a commit 77d3749

File tree

1 file changed

+17
-9
lines changed
  • src/cmd/compile/internal/ssa

1 file changed

+17
-9
lines changed

src/cmd/compile/internal/ssa/cse.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,29 @@ func cse(f *Func) {
138138
rewrite := make([]*Value, f.NumValues())
139139
for _, e := range partition {
140140
sort.Sort(sortbyentry{e, f.sdom})
141-
for len(e) > 1 {
141+
for i := 0; i < len(e)-1; i++ {
142142
// e is sorted by entry value so maximal dominant element should be
143143
// found first in the slice
144-
v := e[0]
145-
e = e[1:]
144+
v := e[i]
145+
if v == nil {
146+
continue
147+
}
148+
149+
e[i] = nil
146150
// Replace all elements of e which v dominates
147-
for i := 0; i < len(e); {
148-
w := e[i]
151+
for j := i + 1; j < len(e); j++ {
152+
w := e[j]
153+
if w == nil {
154+
continue
155+
}
149156
if f.sdom.isAncestorEq(v.Block, w.Block) {
150157
rewrite[w.ID] = v
151-
// retain the sort order
152-
copy(e[i:], e[i+1:])
153-
e = e[:len(e)-1]
158+
e[j] = nil
154159
} else {
155-
i++
160+
// since the blocks are assorted in ascending order by entry number
161+
// once we know that we don't dominate a block we can't dominate any
162+
// 'later' block
163+
break
156164
}
157165
}
158166
}

0 commit comments

Comments
 (0)