From c9a38ce758e3de93e73842bf42a6e84f182d183a Mon Sep 17 00:00:00 2001 From: Todd Neal Date: Sun, 26 Jul 2015 09:48:20 -0500 Subject: [PATCH] [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/12682 Reviewed-by: Keith Randall Reviewed-by: Josh Bleecher Snyder --- .../compile/internal/gc/testdata/arith_ssa.go | 20 +++++++++++++++++++ src/cmd/compile/internal/ssa/regalloc.go | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/gc/testdata/arith_ssa.go b/src/cmd/compile/internal/gc/testdata/arith_ssa.go index a4fdf16f7d..22fc034a1c 100644 --- a/src/cmd/compile/internal/gc/testdata/arith_ssa.go +++ b/src/cmd/compile/internal/gc/testdata/arith_ssa.go @@ -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") diff --git a/src/cmd/compile/internal/ssa/regalloc.go b/src/cmd/compile/internal/ssa/regalloc.go index 101eedd93f..a13b8b2a06 100644 --- a/src/cmd/compile/internal/ssa/regalloc.go +++ b/src/cmd/compile/internal/ssa/regalloc.go @@ -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 -- 2.48.1