cmd/6g: fix out of registers when chaining integer divisions.

Fixes #4201.

R=golang-dev, rsc
CC=golang-dev, remy
https://golang.org/cl/6622055
This commit is contained in:
Rémy Oudompheng 2012-10-07 00:30:29 +02:00
parent 94acfde22e
commit 46fcfdaa7d
2 changed files with 39 additions and 1 deletions

View 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:

View 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
}