mirror of
https://github.com/golang/go
synced 2024-11-26 02:07:57 -07:00
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:
parent
94acfde22e
commit
46fcfdaa7d
@ -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:
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user