ref: c4ad409e2756b66cd9c8c8ffb4ecd7e11605b7db
parent: 66cc3768c1a4d898bd0fbf9f2e5cde7779d3ef9b
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Mar 13 08:56:40 EST 2021
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.
--- a/sys/src/cmd/5c/cgen.c
+++ b/sys/src/cmd/5c/cgen.c
@@ -113,6 +113,8 @@
reglcgen(&nod1, l, Z);
}
gmove(&nod, &nod1);
+ if(nn != Z)
+ gmove(&nod, nn);
regfree(&nod);
regfree(&nod1);
break;
@@ -251,7 +253,8 @@
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 @@
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 @@
} 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);
--- a/sys/src/cmd/6c/cgen.c
+++ b/sys/src/cmd/6c/cgen.c
@@ -112,6 +112,8 @@
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 @@
reglcgen(&nod1, l, Z);
}
gmove(&nod, &nod1);
+ if(nn != Z)
+ gmove(&nod, nn);
regfree(&nod);
regfree(&nod1);
break;
--- a/sys/src/cmd/7c/cgen.c
+++ b/sys/src/cmd/7c/cgen.c
@@ -128,6 +128,8 @@
reglcgen(&nod1, l, Z);
}
gmove(&nod, &nod1);
+ if(nn != Z)
+ gmove(&nod, nn);
regfree(&nod);
regfree(&nod1);
break;
@@ -267,7 +269,8 @@
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 @@
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 @@
} 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);
--- a/sys/src/cmd/8c/cgen.c
+++ b/sys/src/cmd/8c/cgen.c
@@ -131,6 +131,8 @@
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 @@
reglcgen(&nod1, l, Z);
}
gmove(&nod, &nod1);
+ if(nn != Z)
+ gmove(&nod, nn);
regfree(&nod);
regfree(&nod1);
break;
--- a/sys/src/cmd/kc/cgen.c
+++ b/sys/src/cmd/kc/cgen.c
@@ -107,6 +107,8 @@
reglcgen(&nod1, l, Z);
}
gmove(&nod, &nod1);
+ if(nn != Z)
+ gmove(&nod, nn);
regfree(&nod);
regfree(&nod1);
break;
@@ -423,6 +425,8 @@
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 @@
} 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);
--- a/sys/src/cmd/qc/cgen.c
+++ b/sys/src/cmd/qc/cgen.c
@@ -109,6 +109,8 @@
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 @@
reglcgen(&nod1, l, Z);
}
gmove(&nod, &nod1);
+ if(nn != Z)
+ gmove(&nod, nn);
regfree(&nod);
regfree(&nod1);
break;
--- a/sys/src/cmd/vc/cgen.c
+++ b/sys/src/cmd/vc/cgen.c
@@ -107,6 +107,8 @@
reglcgen(&nod1, l, Z);
}
gmove(&nod, &nod1);
+ if(nn != Z)
+ gmove(&nod, nn);
regfree(&nod);
regfree(&nod1);
break;
@@ -425,6 +427,8 @@
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 @@
} 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);
--
⑨