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.
This commit is contained in:
parent
2f55920a22
commit
9de5aac7a2
7 changed files with 52 additions and 14 deletions
|
@ -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);
|
||||
|
|
|
@ -112,6 +112,8 @@ cgen(Node *n, Node *nn)
|
|||
if(l->complex >= r->complex) {
|
||||
if(l->op == OINDEX && immconst(r)) {
|
||||
gmove(r, l);
|
||||
if(nn != Z)
|
||||
gmove(r, nn);
|
||||
break;
|
||||
}
|
||||
reglcgen(&nod1, l, Z);
|
||||
|
@ -130,6 +132,8 @@ cgen(Node *n, Node *nn)
|
|||
reglcgen(&nod1, l, Z);
|
||||
}
|
||||
gmove(&nod, &nod1);
|
||||
if(nn != Z)
|
||||
gmove(&nod, nn);
|
||||
regfree(&nod);
|
||||
regfree(&nod1);
|
||||
break;
|
||||
|
|
|
@ -128,6 +128,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;
|
||||
|
@ -267,7 +269,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);
|
||||
|
@ -528,6 +531,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);
|
||||
|
@ -580,9 +585,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);
|
||||
|
|
|
@ -131,6 +131,8 @@ cgen(Node *n, Node *nn)
|
|||
if(l->complex >= r->complex) {
|
||||
if(l->op == OINDEX && r->op == OCONST) {
|
||||
gmove(r, l);
|
||||
if(nn != Z)
|
||||
gmove(r, nn);
|
||||
break;
|
||||
}
|
||||
reglcgen(&nod1, l, Z);
|
||||
|
@ -149,6 +151,8 @@ cgen(Node *n, Node *nn)
|
|||
reglcgen(&nod1, l, Z);
|
||||
}
|
||||
gmove(&nod, &nod1);
|
||||
if(nn != Z)
|
||||
gmove(&nod, nn);
|
||||
regfree(&nod);
|
||||
regfree(&nod1);
|
||||
break;
|
||||
|
|
|
@ -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;
|
||||
|
@ -423,6 +425,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);
|
||||
|
@ -475,9 +479,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);
|
||||
|
|
|
@ -109,6 +109,8 @@ cgen(Node *n, Node *nn)
|
|||
regalloc(&nod, r, nn);
|
||||
cgen(r, &nod);
|
||||
gmove(&nod, l);
|
||||
if(nn != Z)
|
||||
gmove(&nod, nn);
|
||||
regfree(&nod);
|
||||
} else
|
||||
gmove(r, l);
|
||||
|
@ -131,6 +133,8 @@ cgen(Node *n, Node *nn)
|
|||
reglcgen(&nod1, l, Z);
|
||||
}
|
||||
gmove(&nod, &nod1);
|
||||
if(nn != Z)
|
||||
gmove(&nod, nn);
|
||||
regfree(&nod);
|
||||
regfree(&nod1);
|
||||
break;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue