aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/gc/testdata
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2016-04-11 21:23:11 -0700
committerKeith Randall <khr@golang.org>2016-04-12 15:10:16 +0000
commitcd85f711c0b6847cbfe4e05f4402df075ea936de (patch)
treed9fa34021c95884eec601e218c9ff2ab03cb8d88 /src/cmd/compile/internal/gc/testdata
parent204b6f48c5107d3132033324fd492ca0253568dc (diff)
downloadgo-cd85f711c0b6847cbfe4e05f4402df075ea936de.tar.xz
cmd/compile: add x.Uses==1 test to load combiners
We need to make sure that when we combine loads, we only do so if there are no other uses of the load. We can't split one load into two because that can then lead to inconsistent loaded values in the presence of races. Add some aggressive copy removal code so that phantom "dead copy" uses of values are cleaned up promptly. This lets us use x.Uses==1 conditions reliably. Change-Id: I9037311db85665f3868dbeb3adb3de5c20728b38 Reviewed-on: https://go-review.googlesource.com/21853 Reviewed-by: Todd Neal <todd@tneal.org>
Diffstat (limited to 'src/cmd/compile/internal/gc/testdata')
-rw-r--r--src/cmd/compile/internal/gc/testdata/dupLoad.go46
-rw-r--r--src/cmd/compile/internal/gc/testdata/namedReturn.go4
2 files changed, 50 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/gc/testdata/dupLoad.go b/src/cmd/compile/internal/gc/testdata/dupLoad.go
new file mode 100644
index 0000000000..d12c26355a
--- /dev/null
+++ b/src/cmd/compile/internal/gc/testdata/dupLoad.go
@@ -0,0 +1,46 @@
+// run
+
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This test makes sure that we don't split a single
+// load up into two separate loads.
+
+package main
+
+import "fmt"
+
+//go:noinline
+func read(b []byte) (uint16, uint16) {
+ // There is only a single read of b[0]. The two
+ // returned values must have the same low byte.
+ v := b[0]
+ return uint16(v), uint16(v) | uint16(b[1])<<8
+}
+
+const N = 100000
+
+func main() {
+ done := make(chan struct{})
+ b := make([]byte, 2)
+ go func() {
+ for i := 0; i < N; i++ {
+ b[0] = byte(i)
+ b[1] = byte(i)
+ }
+ done <- struct{}{}
+ }()
+ go func() {
+ for i := 0; i < N; i++ {
+ x, y := read(b)
+ if byte(x) != byte(y) {
+ fmt.Printf("x=%x y=%x\n", x, y)
+ panic("bad")
+ }
+ }
+ done <- struct{}{}
+ }()
+ <-done
+ <-done
+}
diff --git a/src/cmd/compile/internal/gc/testdata/namedReturn.go b/src/cmd/compile/internal/gc/testdata/namedReturn.go
index dafb5d719f..19ef8a7e43 100644
--- a/src/cmd/compile/internal/gc/testdata/namedReturn.go
+++ b/src/cmd/compile/internal/gc/testdata/namedReturn.go
@@ -1,5 +1,9 @@
// run
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
// This test makes sure that naming named
// return variables in a return statement works.
// See issue #14904.