From 9de5aac7a29564ac0e1574d17d2589eefe8de3e6 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 13 Mar 2021 13:56:40 +0100 Subject: 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. --- sys/src/cmd/5c/cgen.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'sys/src/cmd/5c') diff --git a/sys/src/cmd/5c/cgen.c b/sys/src/cmd/5c/cgen.c index dae6e1872..fdddfa8e9 100644 --- a/sys/src/cmd/5c/cgen.c +++ b/sys/src/cmd/5c/cgen.c @@ -113,6 +113,8 @@ cgenrel(Node *n, Node *nn, int inrel) reglcgen(&nod1, l, Z); } gmove(&nod, &nod1); + if(nn != Z) + gmove(&nod, nn); regfree(&nod); regfree(&nod1); break; @@ -251,7 +253,8 @@ cgenrel(Node *n, Node *nn, int inrel) gopcode(OAS, &nod2, Z, &nod); gopcode(o, r, Z, &nod); gopcode(OAS, &nod, Z, &nod2); - + if(nn != Z) + gmove(&nod, nn); regfree(&nod); if(l->addable < INDEXED) regfree(&nod2); @@ -472,6 +475,8 @@ cgenrel(Node *n, Node *nn, int inrel) 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); @@ -524,9 +529,11 @@ cgenrel(Node *n, Node *nn, int inrel) } 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); -- cgit v1.2.3