]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: don't flush a value derived from the current value
authorTodd Neal <todd@tneal.org>
Sun, 26 Jul 2015 14:48:20 +0000 (09:48 -0500)
committerTodd Neal <todd@tneal.org>
Mon, 27 Jul 2015 20:14:14 +0000 (20:14 +0000)
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/12682
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
src/cmd/compile/internal/gc/testdata/arith_ssa.go
src/cmd/compile/internal/ssa/regalloc.go

index a4fdf16f7de04cc683db3ce2ef24da4abafe757b..22fc034a1c6e2cf11db03969ed924dc140f74cdb 100644 (file)
@@ -8,6 +8,8 @@
 
 package main
 
+// test64BitConstMulti tests that rewrite rules don't fold 64 bit constants
+// into multiply instructions.
 func test64BitConstMult(a, b int64) {
        want := 34359738369*a + b*34359738370
        if got := test64BitConstMult_ssa(a, b); want != got {
@@ -21,6 +23,8 @@ func test64BitConstMult_ssa(a, b int64) int64 {
        return 34359738369*a + b*34359738370
 }
 
+// test64BitConstAdd tests that rewrite rules don't fold 64 bit constants
+// into add instructions.
 func test64BitConstAdd(a, b int64) {
        want := a + 575815584948629622 + b + 2991856197886747025
        if got := test64BitConstAdd_ssa(a, b); want != got {
@@ -34,12 +38,28 @@ func test64BitConstAdd_ssa(a, b int64) int64 {
        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
 
 func main() {
 
        test64BitConstMult(1, 2)
        test64BitConstAdd(1, 2)
+       testRegallocCVSpill(1, 2, 3, 4)
 
        if failed {
                panic("failed")
index 101eedd93f2562b4df0426d1859f72c89cb0e664..a13b8b2a067e7c57b555cdcad01c29b8ec94622f 100644 (file)
@@ -238,7 +238,7 @@ func regalloc(f *Func) {
                                        if regs[r].v != nil {
                                                x := regs[r].v
                                                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.
                                                        x.Op = OpStoreReg
                                                        x.Aux = nil
@@ -317,7 +317,7 @@ func regalloc(f *Func) {
                                if regs[r].v != nil {
                                        x := regs[r].v
                                        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.
                                                x.Op = OpStoreReg
                                                x.Aux = nil