Commit 8a961aee authored by Keith Randall's avatar Keith Randall

[dev.ssa] cmd/compile: fix -N build

The OpSB hack didn't quite work.  We need to really
CSE these ops to make regalloc happy.

Change-Id: I9f4d7bfb0929407c84ee60c9e25ff0c0fbea84af
Reviewed-on: https://go-review.googlesource.com/19083
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDavid Chase <drchase@google.com>
parent 056c09bb
......@@ -92,7 +92,7 @@ var passes = [...]pass{
{"decompose", decompose, true},
{"opt", opt, true}, // TODO: split required rules and optimizing rules
{"opt deadcode", deadcode, false}, // remove any blocks orphaned during opt
{"generic cse", cse, false},
{"generic cse", cse, true},
{"nilcheckelim", nilcheckelim, false},
{"generic deadcode", deadcode, false},
{"fuse", fuse, false},
......
......@@ -10,6 +10,34 @@ import "sort"
// Values are just relinked, nothing is deleted. A subsequent deadcode
// pass is required to actually remove duplicate expressions.
func cse(f *Func) {
if !f.Config.optimize {
// Don't do CSE in this case. But we need to do
// just a little bit, to combine multiple OpSB ops.
// Regalloc gets very confused otherwise.
var sb *Value
outer:
for _, b := range f.Blocks {
for _, v := range b.Values {
if v.Op == OpSB {
sb = v
break outer
}
}
}
if sb == nil {
return
}
for _, b := range f.Blocks {
for _, v := range b.Values {
for i, a := range v.Args {
if a.Op == OpSB {
v.Args[i] = sb
}
}
}
}
return
}
// Two values are equivalent if they satisfy the following definition:
// equivalent(v, w):
// v.op == w.op
......
......@@ -316,12 +316,6 @@ func (s *regAllocState) assignReg(r register, v *Value, c *Value) {
fmt.Printf("assignReg %s %s/%s\n", registers[r].Name(), v, c)
}
if s.regs[r].v != nil {
if v.Op == OpSB && !v.Block.Func.Config.optimize {
// Rewrite rules may introduce multiple OpSB, and with
// -N they don't get CSEd. Ignore the extra assignments.
s.f.setHome(c, &registers[r])
return
}
s.f.Fatalf("tried to assign register %d to %s/%s but it is already used by %s", r, v, c, s.regs[r].v)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment