]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/7g: fix ACMP entry in progtable
authorDavid Crawshaw <crawshaw@golang.org>
Thu, 2 Apr 2015 15:35:56 +0000 (11:35 -0400)
committerDavid Crawshaw <crawshaw@golang.org>
Thu, 2 Apr 2015 20:18:28 +0000 (20:18 +0000)
On arm64, CMP $foo, R is encoded as from=$foo, reg=R, not as from=$foo,
to=R. The progtable entry for ACMP incorrectly described the latter
form. Because of this, the registerizer was not accounting the registers
used in CMP instructions and was incorrectly re-assigning those registers.

This was an old problem, but it only became apparent after b115c35
(cmd/internal/gc: move cgen, regalloc, et al to portable code). Previous
to this commit, the compiler used a slightly larger register set for the
temps than it used for register variables. Since it had plenty registers
dedicated to temps, the registers used in CMP instruction never clashed
with registers assigned to register variables.

Fixes #10253

Change-Id: Iedf4bd882bd59440dff310ac0f81e0f53d80d7ed
Reviewed-on: https://go-review.googlesource.com/8387
Reviewed-by: Aram Hăvărneanu <aram@mgk.ro>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
src/cmd/7g/prog.go
test/fixedbugs/issue10253.go [new file with mode: 0644]

index 4afb29b89ab3c00c604b2a92ac24e50559d80977..f503f78ef1281c56da766d895de4cd96d72f4fdf 100644 (file)
@@ -57,7 +57,7 @@ var progtable = [arm64.ALAST]obj.ProgInfo{
        arm64.ALSL:   {gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
        arm64.ALSR:   {gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
        arm64.AASR:   {gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
-       arm64.ACMP:   {gc.SizeQ | gc.LeftRead | gc.RightRead, 0, 0, 0},
+       arm64.ACMP:   {gc.SizeQ | gc.LeftRead | gc.RegRead, 0, 0, 0},
 
        // Floating point.
        arm64.AFADDD: {gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite, 0, 0, 0},
diff --git a/test/fixedbugs/issue10253.go b/test/fixedbugs/issue10253.go
new file mode 100644 (file)
index 0000000..fafca6c
--- /dev/null
@@ -0,0 +1,26 @@
+// run
+
+// Copyright 2015 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.
+
+// issue 10253: cmd/7g: bad codegen, probably regopt related
+
+package main
+
+func main() {
+       if !eq() {
+               panic("wrong value")
+       }
+}
+
+var text = "abc"
+var s = &str{text}
+
+func eq() bool {
+       return text[0] == s.text[0]
+}
+
+type str struct {
+       text string
+}