[dev.ssa] cmd/compile/internal/ssa: reuse Aux values for PEXTERN

This improves cse and works correctly now that divide by zero is checked
explicitly.

Change-Id: If54fbe403ed5230b897afc5def644ba9f0056dfd
Reviewed-on: https://go-review.googlesource.com/16454
Run-TryBot: Todd Neal <todd@tneal.org>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Todd Neal 2015-10-27 21:35:48 -05:00
parent a347ab7cd1
commit 74180dd7da
2 changed files with 29 additions and 1 deletions

View file

@ -2265,7 +2265,7 @@ func (s *state) addr(n *Node, bounded bool) *ssa.Value {
switch n.Class {
case PEXTERN:
// global variable
aux := &ssa.ExternSymbol{n.Type, n.Sym}
aux := s.lookupSymbol(n, &ssa.ExternSymbol{n.Type, n.Sym})
v := s.entryNewValue1A(ssa.OpAddr, t, aux, s.sb)
// TODO: Make OpAddr use AuxInt as well as Aux.
if n.Xoffset != 0 {

View file

@ -77,11 +77,39 @@ func testExtStore() {
}
}
var b int
// testDeadStorePanic_ssa ensures that we don't optimize away stores
// that could be read by after recover(). Modeled after fixedbugs/issue1304.
func testDeadStorePanic_ssa(a int) (r int) {
switch {
}
defer func() {
recover()
r = a
}()
a = 2 // store
b := a - a // optimized to zero
c := 4
a = c / b // store, but panics
a = 3 // store
r = a
return
}
func testDeadStorePanic() {
if want, got := 2, testDeadStorePanic_ssa(1); want != got {
fmt.Println("testDeadStorePanic failed. want =", want, ", got =", got)
failed = true
}
}
func main() {
testLoadStoreOrder()
testStoreSize()
testExtStore()
testDeadStorePanic()
if failed {
panic("failed")