From 33448d963caf0d66f042e738fe733c66796742b2 Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Thu, 2 Apr 2015 11:35:56 -0400 Subject: [PATCH] cmd/7g: fix ACMP entry in progtable MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Rob Pike Reviewed-by: Russ Cox Reviewed-by: Minux Ma --- src/cmd/7g/prog.go | 2 +- test/fixedbugs/issue10253.go | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue10253.go diff --git a/src/cmd/7g/prog.go b/src/cmd/7g/prog.go index 4afb29b89a..f503f78ef1 100644 --- a/src/cmd/7g/prog.go +++ b/src/cmd/7g/prog.go @@ -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 index 0000000000..fafca6c733 --- /dev/null +++ b/test/fixedbugs/issue10253.go @@ -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 +} -- 2.48.1