Skip to content

Commit 217c284

Browse files
committed
cmd/compile: combine stores into larger widths
Combine stores into larger widths when it is safe to do so. Add clobber() function so stray dead uses do not impede the above rewrites. Fix bug in loads where all intermediate values depending on a small load (not just the load itself) must have no other uses. We really need the small load to be dead after the rewrite.. Fixes #14267 Change-Id: Ib25666cb19777f65082c76238fba51a76beb5d74 Reviewed-on: https://go-review.googlesource.com/22326 Run-TryBot: Keith Randall <[email protected]> Reviewed-by: Todd Neal <[email protected]>
1 parent a370361 commit 217c284

File tree

4 files changed

+1582
-217
lines changed

4 files changed

+1582
-217
lines changed

src/cmd/compile/internal/gc/testdata/dupLoad.go

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ package main
1212
import "fmt"
1313

1414
//go:noinline
15-
func read(b []byte) (uint16, uint16) {
15+
func read1(b []byte) (uint16, uint16) {
1616
// There is only a single read of b[0]. The two
1717
// returned values must have the same low byte.
1818
v := b[0]
@@ -21,7 +21,7 @@ func read(b []byte) (uint16, uint16) {
2121

2222
const N = 100000
2323

24-
func main() {
24+
func main1() {
2525
done := make(chan struct{})
2626
b := make([]byte, 2)
2727
go func() {
@@ -33,7 +33,7 @@ func main() {
3333
}()
3434
go func() {
3535
for i := 0; i < N; i++ {
36-
x, y := read(b)
36+
x, y := read1(b)
3737
if byte(x) != byte(y) {
3838
fmt.Printf("x=%x y=%x\n", x, y)
3939
panic("bad")
@@ -44,3 +44,40 @@ func main() {
4444
<-done
4545
<-done
4646
}
47+
48+
//go:noinline
49+
func read2(b []byte) (uint16, uint16) {
50+
// There is only a single read of b[1]. The two
51+
// returned values must have the same high byte.
52+
v := uint16(b[1]) << 8
53+
return v, uint16(b[0]) | v
54+
}
55+
56+
func main2() {
57+
done := make(chan struct{})
58+
b := make([]byte, 2)
59+
go func() {
60+
for i := 0; i < N; i++ {
61+
b[0] = byte(i)
62+
b[1] = byte(i)
63+
}
64+
done <- struct{}{}
65+
}()
66+
go func() {
67+
for i := 0; i < N; i++ {
68+
x, y := read2(b)
69+
if x&0xff00 != y&0xff00 {
70+
fmt.Printf("x=%x y=%x\n", x, y)
71+
panic("bad")
72+
}
73+
}
74+
done <- struct{}{}
75+
}()
76+
<-done
77+
<-done
78+
}
79+
80+
func main() {
81+
main1()
82+
main2()
83+
}

0 commit comments

Comments
 (0)