]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/8g: roll back the small integer constant optimizations introduced
authorNigel Tao <nigeltao@golang.org>
Thu, 23 Aug 2012 06:17:22 +0000 (16:17 +1000)
committerNigel Tao <nigeltao@golang.org>
Thu, 23 Aug 2012 06:17:22 +0000 (16:17 +1000)
in 13416:67c0b8c8fb29 "faster code, mainly for rotate" [1]. The codegen
can run out of registers if there are too many small-int arithmetic ops.

An alternative approach is to copy 6g's sbop/abop codegen to 8g, but
this change is less risky.

Fixes #3835.

[1] http://code.google.com/p/go/source/diff?spec=svn67c0b8c8fb29b1b7b6221977af6b89cae787b941&name=67c0b8c8fb29&r=67c0b8c8fb29b1b7b6221977af6b89cae787b941&format=side&path=/src/cmd/8g/cgen.c

R=rsc, remyoudompheng, r
CC=golang-dev
https://golang.org/cl/6450163

src/cmd/8g/cgen.c
test/fixedbugs/bug451.go [new file with mode: 0644]

index aefa15a6707fb8367592d00217e0a9f4a29d4b70..1ae49acaa0fdf4dea139a4430f2c13b3e677b293 100644 (file)
@@ -392,13 +392,7 @@ sbop:      // symmetric binary
        }
 
 abop:  // asymmetric binary
-       if(smallintconst(nr)) {
-               regalloc(&n1, nr->type, res);
-               cgen(nl, &n1);
-               gins(a, nr, &n1);
-               gmove(&n1, res);
-               regfree(&n1);
-       } else if(nl->ullman >= nr->ullman) {
+       if(nl->ullman >= nr->ullman) {
                tempname(&nt, nl->type);
                cgen(nl, &nt);
                mgen(nr, &n2, N);
diff --git a/test/fixedbugs/bug451.go b/test/fixedbugs/bug451.go
new file mode 100644 (file)
index 0000000..d2e4a0b
--- /dev/null
@@ -0,0 +1,38 @@
+// run
+
+// Copyright 2012 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 3835: 8g tries to optimize arithmetic involving integer
+// constants, but can run out of registers in the process.
+
+package main
+
+var a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G int
+
+func foo() int {
+       return a + 1 + b + 2 + c + 3 + d + 4 + e + 5 + f + 6 + g + 7 + h + 8 + i + 9 + j + 10 +
+               k + 1 + l + 2 + m + 3 + n + 4 + o + 5 + p + 6 + q + 7 + r + 8 + s + 9 + t + 10 +
+               u + 1 + v + 2 + w + 3 + x + 4 + y + 5 + z + 6 + A + 7 + B + 8 + C + 9 + D + 10 +
+               E + 1 + F + 2 + G + 3
+}
+
+func bar() int8 {
+       var (
+               W int16
+               X int32
+               Y int32
+               Z int32
+       )
+       return int8(W+int16(X+3)+3) * int8(Y+3+Z*3)
+}
+
+func main() {
+       if foo() == 0 {
+               panic("foo")
+       }
+       if bar() == 0 {
+               panic("bar")
+       }
+}