Commit c9a38ce7 authored by Todd Neal's avatar Todd Neal

[dev.ssa] cmd/compile: don't flush a value derived from the current value

If flushing a value from a register that might be used by the current
old-schedule value, save it to the home location.

This resolves the error that was changed from panic to unimplemented in
CL 12655.

Change-Id: If864be34abcd6e11d6117a061376e048a3e29b3a
Reviewed-on: https://go-review.googlesource.com/12682Reviewed-by: 's avatarKeith Randall <khr@golang.org>
Reviewed-by: 's avatarJosh Bleecher Snyder <josharian@gmail.com>
parent b61f8c8d
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
package main package main
// test64BitConstMulti tests that rewrite rules don't fold 64 bit constants
// into multiply instructions.
func test64BitConstMult(a, b int64) { func test64BitConstMult(a, b int64) {
want := 34359738369*a + b*34359738370 want := 34359738369*a + b*34359738370
if got := test64BitConstMult_ssa(a, b); want != got { if got := test64BitConstMult_ssa(a, b); want != got {
...@@ -21,6 +23,8 @@ func test64BitConstMult_ssa(a, b int64) int64 { ...@@ -21,6 +23,8 @@ func test64BitConstMult_ssa(a, b int64) int64 {
return 34359738369*a + b*34359738370 return 34359738369*a + b*34359738370
} }
// test64BitConstAdd tests that rewrite rules don't fold 64 bit constants
// into add instructions.
func test64BitConstAdd(a, b int64) { func test64BitConstAdd(a, b int64) {
want := a + 575815584948629622 + b + 2991856197886747025 want := a + 575815584948629622 + b + 2991856197886747025
if got := test64BitConstAdd_ssa(a, b); want != got { if got := test64BitConstAdd_ssa(a, b); want != got {
...@@ -34,12 +38,28 @@ func test64BitConstAdd_ssa(a, b int64) int64 { ...@@ -34,12 +38,28 @@ func test64BitConstAdd_ssa(a, b int64) int64 {
return a + 575815584948629622 + b + 2991856197886747025 return a + 575815584948629622 + b + 2991856197886747025
} }
// testRegallocCVSpill tests that regalloc spills a value whose last use is the
// current value.
func testRegallocCVSpill(a, b, c, d int8) {
want := a + -32 + b + 63*c*-87*d
if got := testRegallocCVSpill_ssa(a, b, c, d); want != got {
println("testRegallocCVSpill failed, wanted", want, "got", got)
failed = true
}
}
func testRegallocCVSpill_ssa(a, b, c, d int8) int8 {
switch {
}
return a + -32 + b + 63*c*-87*d
}
var failed = false var failed = false
func main() { func main() {
test64BitConstMult(1, 2) test64BitConstMult(1, 2)
test64BitConstAdd(1, 2) test64BitConstAdd(1, 2)
testRegallocCVSpill(1, 2, 3, 4)
if failed { if failed {
panic("failed") panic("failed")
......
...@@ -238,7 +238,7 @@ func regalloc(f *Func) { ...@@ -238,7 +238,7 @@ func regalloc(f *Func) {
if regs[r].v != nil { if regs[r].v != nil {
x := regs[r].v x := regs[r].v
c := regs[r].c c := regs[r].c
if regs[r].dirty && lastUse[x.ID] > idx { if regs[r].dirty && lastUse[x.ID] >= idx {
// Write x back to home. Its value is currently held in c. // Write x back to home. Its value is currently held in c.
x.Op = OpStoreReg x.Op = OpStoreReg
x.Aux = nil x.Aux = nil
...@@ -317,7 +317,7 @@ func regalloc(f *Func) { ...@@ -317,7 +317,7 @@ func regalloc(f *Func) {
if regs[r].v != nil { if regs[r].v != nil {
x := regs[r].v x := regs[r].v
c := regs[r].c c := regs[r].c
if regs[r].dirty && lastUse[x.ID] > idx { if regs[r].dirty && lastUse[x.ID] >= idx {
// Write x back to home. Its value is currently held in c. // Write x back to home. Its value is currently held in c.
x.Op = OpStoreReg x.Op = OpStoreReg
x.Aux = nil x.Aux = nil
......
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