]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/6g: fix out of registers when chaining integer divisions.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Sat, 6 Oct 2012 22:30:29 +0000 (00:30 +0200)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Sat, 6 Oct 2012 22:30:29 +0000 (00:30 +0200)
Fixes #4201.

R=golang-dev, rsc
CC=golang-dev, remy
https://golang.org/cl/6622055

src/cmd/6g/cgen.c
test/torture.go

index 8d6ffb087b8846ddba1b51a637f3ee79be8290d1..f2be7d1ae9336321f7ce836ffdb9668686c7798e 100644 (file)
@@ -402,7 +402,23 @@ cgen(Node *n, Node *res)
                        a = optoas(n->op, nl->type);
                        goto abop;
                }
-               cgen_div(n->op, nl, nr, res);
+
+               if(nl->ullman >= nr->ullman) {
+                       regalloc(&n1, nl->type, res);
+                       cgen(nl, &n1);
+                       cgen_div(n->op, &n1, nr, res);
+                       regfree(&n1);
+               } else {
+                       if(!smallintconst(nr)) {
+                               regalloc(&n2, nr->type, res);
+                               cgen(nr, &n2);
+                       } else {
+                               n2 = *nr;
+                       }
+                       cgen_div(n->op, nl, &n2, res);
+                       if(n2.op != OLITERAL)
+                               regfree(&n2);
+               }
                break;
 
        case OLSH:
index fdc5ddae0ff5674c5c2d0a537c9ceaf1a8debdfc..dd8ff59a03416db559d375a44ae137e60f569236 100644 (file)
@@ -169,3 +169,25 @@ func ChainUNoAssert(u *U) *U {
                Child(0).
                Child(0).(*U)
 }
+
+// Chains of divisions. See issue 4201.
+
+func ChainDiv(a, b int) int {
+       return a / b / a / b / a / b / a / b /
+               a / b / a / b / a / b / a / b /
+               a / b / a / b / a / b / a / b
+}
+
+func ChainDivRight(a, b int) int {
+       return a / (b / (a / (b /
+            (a / (b / (a / (b /
+            (a / (b / (a / (b /
+            (a / (b / (a / (b /
+            (a / (b / (a / b))))))))))))))))))
+}
+
+func ChainDivConst(a int) int {
+       return a / 17 / 17 / 17 /
+               17 / 17 / 17 / 17 /
+               17 / 17 / 17 / 17
+}