diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2021-03-13 13:56:40 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2021-03-13 13:56:40 +0100 |
commit | 9de5aac7a29564ac0e1574d17d2589eefe8de3e6 (patch) | |
tree | 3272d4e82cace88b97cacc4408d6eaeea42d9a16 /sys/src/cmd/vc/cgen.c | |
parent | 2f55920a22c24bcf489fa3fa621eae5969b5bf2c (diff) |
5c, 6c, 7c, 8c, kc, qc, vc: use explicit gmove(... , nn) in cgen() for result of OAS*, OPREINC, OPOSTINC
The expression value of the assignment operation was
returned implicitely by relying on regalloc() on the
right hand side "nod" borrowing the register from nn.
But this only works if nn is a register.
In case of 6c, it can also be a ONAME from a .safe
rathole returned by regsalloc().
This change adds explicit gmove() calls to assign the
expression value. Note that gmove() checks if source
and destination are the same register so it wont emit
redundant move operations in the common case.
The same is applied also to OPREINC and OPOSTINC operations.
Diffstat (limited to 'sys/src/cmd/vc/cgen.c')
-rw-r--r-- | sys/src/cmd/vc/cgen.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/sys/src/cmd/vc/cgen.c b/sys/src/cmd/vc/cgen.c index 7b9ec4808..4c0cf61c1 100644 --- a/sys/src/cmd/vc/cgen.c +++ b/sys/src/cmd/vc/cgen.c @@ -107,6 +107,8 @@ cgen(Node *n, Node *nn) reglcgen(&nod1, l, Z); } gmove(&nod, &nod1); + if(nn != Z) + gmove(&nod, nn); regfree(&nod); regfree(&nod1); break; @@ -425,6 +427,8 @@ cgen(Node *n, Node *nn) regalloc(&nod, l, nn); gopcode(OAS, &nod2, Z, &nod); + if(nn != Z) + gmove(&nod, nn); regalloc(&nod1, l, Z); if(typefd[l->type->etype]) { regalloc(&nod3, l, Z); @@ -477,9 +481,11 @@ cgen(Node *n, Node *nn) } else gopcode(OADD, nodconst(v), Z, &nod); gopcode(OAS, &nod, Z, &nod2); - if(nn && l->op == ONAME) /* in x=++i, emit USED(i) */ - gins(ANOP, l, Z); - + if(nn != Z) { + gmove(&nod, nn); + if(l->op == ONAME) /* in x=++i, emit USED(i) */ + gins(ANOP, l, Z); + } regfree(&nod); if(l->addable < INDEXED) regfree(&nod2); |