summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2014-05-12 17:10:36 -0400
committerJosh Bleecher Snyder <josharian@gmail.com>2014-05-12 17:10:36 -0400
commitd8543db621c41762e475c2e45f6b48918c2ce898 (patch)
treea37f1e7879c5ad494f8ab8ebc612e48283a30ee9 /test
parentd3849a7fc8ca58e1b4c6606f4bf589c65bfe656f (diff)
downloadgo-d8543db621c41762e475c2e45f6b48918c2ce898.tar.gz
cmd/gc: alias more variables during register allocation
This is joint work with Daniel Morsing. In order for the register allocator to alias two variables, they must have the same width, stack offset, and etype. Code generation was altering a variable's etype in a few places. This prevented the variable from being moved to a register, which in turn prevented peephole optimization. This failure to alias was very common, with almost 23,000 instances just running make.bash. This phenomenon was not visible in the register allocation debug output because the variables that failed to alias had the same name. The debugging-only change to bits.c fixes this by printing the variable number with its name. This CL fixes the source of all etype mismatches for 6g, all but one case for 8g, and depressingly few cases for 5g. (I believe that extending CL 6819083 to 5g is a prerequisite.) Fixing the remaining cases in 8g and 5g is work for the future. The etype mismatch fixes are: * [gc] Slicing changed the type of the base pointer into a uintptr in order to perform arithmetic on it. Instead, support addition directly on pointers. * [*g] OSPTR was giving type uintptr to slice base pointers; undo that. This arose, for example, while compiling copy(dst, src). * [8g] 64 bit float conversion was assigning int64 type during codegen, overwriting the existing uint64 type. Note that some etype mismatches are appropriate, such as a struct with a single field or an array with a single element. With these fixes, the number of registerizations that occur while running make.bash for 6g increases ~10%. Hello world binary size shrinks ~1.5%. Running all benchmarks in the standard library show performance improvements ranging from nominal to substantive (>10%); a full comparison using 6g on my laptop is available at https://gist.github.com/josharian/8f9b5beb46667c272064. The microbenchmarks must be taken with a grain of salt; see issue 7920. The few benchmarks that show real regressions are likely due to issue 7920. I manually examined the generated code for the top few regressions and none had any assembly output changes. The few benchmarks that show extraordinary improvements are likely also due to issue 7920. Performance results from 8g appear similar to 6g. 5g shows no performance improvements. This is not surprising, given the discussion above. Update issue 7316 LGTM=rsc R=rsc, daniel.morsing, bradfitz CC=dave, golang-codereviews https://codereview.appspot.com/91850043 Committer: Russ Cox <rsc@golang.org>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue7316.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/fixedbugs/issue7316.go b/test/fixedbugs/issue7316.go
new file mode 100644
index 000000000..4b32261d4
--- /dev/null
+++ b/test/fixedbugs/issue7316.go
@@ -0,0 +1,37 @@
+// runoutput
+
+// Copyright 2014 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 7316
+// This test exercises all types of numeric conversions, which was one
+// of the sources of etype mismatch during register allocation in 8g.
+
+package main
+
+import "fmt"
+
+const tpl = `
+func init() {
+ var i %s
+ j := %s(i)
+ _ = %s(j)
+}
+`
+
+func main() {
+ fmt.Println("package main")
+ ntypes := []string{
+ "byte", "rune", "uintptr",
+ "float32", "float64",
+ "int", "int8", "int16", "int32", "int64",
+ "uint", "uint8", "uint16", "uint32", "uint64",
+ }
+ for i, from := range ntypes {
+ for _, to := range ntypes[i:] {
+ fmt.Printf(tpl, from, to, from)
+ }
+ }
+ fmt.Println("func main() {}")
+}