Skip to content

Commit bc07922

Browse files
committed
[dev.ssa] cmd/compile: speed up cse
Examine both Aux and AuxInt to form more precise initial partitions. Restructure loop to avoid repeated type.Equal() call. Speeds up compilation of testdata/gen/arithConst_ssa by 25%. Change-Id: I3cfb1d254adf0601ee69239e1885b0cf2a23575b Reviewed-on: https://go-review.googlesource.com/19313 Run-TryBot: Todd Neal <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent faf1bdb commit bc07922

1 file changed

Lines changed: 40 additions & 18 deletions

File tree

  • src/cmd/compile/internal/ssa

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

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,22 @@ func cse(f *Func) {
9999
eqloop:
100100
for j := 1; j < len(e); {
101101
w := e[j]
102+
equivalent := true
102103
for i := 0; i < len(v.Args); i++ {
103-
if valueEqClass[v.Args[i].ID] != valueEqClass[w.Args[i].ID] || !v.Type.Equal(w.Type) {
104-
// w is not equivalent to v.
105-
// move it to the end and shrink e.
106-
e[j], e[len(e)-1] = e[len(e)-1], e[j]
107-
e = e[:len(e)-1]
108-
valueEqClass[w.ID] = ID(len(partition))
109-
changed = true
110-
continue eqloop
104+
if valueEqClass[v.Args[i].ID] != valueEqClass[w.Args[i].ID] {
105+
equivalent = false
106+
break
111107
}
112108
}
109+
if !equivalent || !v.Type.Equal(w.Type) {
110+
// w is not equivalent to v.
111+
// move it to the end and shrink e.
112+
e[j], e[len(e)-1] = e[len(e)-1], e[j]
113+
e = e[:len(e)-1]
114+
valueEqClass[w.ID] = ID(len(partition))
115+
changed = true
116+
continue eqloop
117+
}
113118
// v and w are equivalent. Keep w in e.
114119
j++
115120
}
@@ -212,8 +217,12 @@ func partitionValues(a []*Value) []eqclass {
212217
len(v.Args) != len(w.Args) ||
213218
v.Op == OpPhi && v.Block != w.Block ||
214219
v.Aux != w.Aux ||
215-
len(v.Args) >= 1 && v.Args[0].Op != w.Args[0].Op ||
216-
len(v.Args) >= 2 && v.Args[1].Op != w.Args[1].Op ||
220+
len(v.Args) >= 1 && (v.Args[0].Op != w.Args[0].Op ||
221+
v.Args[0].Aux != w.Args[0].Aux ||
222+
v.Args[0].AuxInt != w.Args[0].AuxInt) ||
223+
len(v.Args) >= 2 && (v.Args[1].Op != w.Args[1].Op ||
224+
v.Args[1].Aux != w.Args[1].Aux ||
225+
v.Args[1].AuxInt != w.Args[1].AuxInt) ||
217226
typNames[v.Type] != typNames[w.Type] {
218227
break
219228
}
@@ -258,16 +267,29 @@ func (sv sortvalues) Less(i, j int) bool {
258267
return v.Block.ID < w.Block.ID
259268
}
260269
if len(v.Args) >= 1 {
261-
x := v.Args[0].Op
262-
y := w.Args[0].Op
263-
if x != y {
264-
return x < y
270+
vOp := v.Args[0].Op
271+
wOp := w.Args[0].Op
272+
if vOp != wOp {
273+
return vOp < wOp
274+
}
275+
276+
vAuxInt := v.Args[0].AuxInt
277+
wAuxInt := w.Args[0].AuxInt
278+
if vAuxInt != wAuxInt {
279+
return vAuxInt < wAuxInt
265280
}
281+
266282
if len(v.Args) >= 2 {
267-
x = v.Args[1].Op
268-
y = w.Args[1].Op
269-
if x != y {
270-
return x < y
283+
vOp = v.Args[1].Op
284+
wOp = w.Args[1].Op
285+
if vOp != wOp {
286+
return vOp < wOp
287+
}
288+
289+
vAuxInt = v.Args[1].AuxInt
290+
wAuxInt = w.Args[1].AuxInt
291+
if vAuxInt != wAuxInt {
292+
return vAuxInt < wAuxInt
271293
}
272294
}
273295
}

0 commit comments

Comments
 (0)