]> git.lizzy.rs Git - plan9front.git/commitdiff
5c, 6c, 7c, 8c, kc, qc, vc: use explicit gmove(... , nn) in cgen() for result of...
authorcinap_lenrek <cinap_lenrek@felloff.net>
Sat, 13 Mar 2021 12:56:40 +0000 (13:56 +0100)
committercinap_lenrek <cinap_lenrek@felloff.net>
Sat, 13 Mar 2021 12:56:40 +0000 (13:56 +0100)
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
sys/src/cmd/6c/cgen.c
sys/src/cmd/7c/cgen.c
sys/src/cmd/8c/cgen.c
sys/src/cmd/kc/cgen.c
sys/src/cmd/qc/cgen.c
sys/src/cmd/vc/cgen.c

index dae6e1872830f271fcb31bf047132c8c5bcd446e..fdddfa8e9f67f3085ecc3ec3b87267491d9121db 100644 (file)
@@ -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);
index d86eed22531f1118a3c087212eff4513dc86fcda..05b28594698051f4c234850fed21f29a0d1be94f 100644 (file)
@@ -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;
index bed0087f99e60bcd28f169c725f471e3c21079bc..3cb84a65ca8bea2593635cf7dddf838f0a761af7 100644 (file)
@@ -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);
index 0c26454e82b6f28857b2f7f1ac40ff49b4e55bbd..c1ec490d5bfd1fd76bb2717faeb147b75fcca2d4 100644 (file)
@@ -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;
index ad295177b49d7f6c85048366e4c53df8c0891009..401812e6065ec79e053cd71d134e68e5c5e62850 100644 (file)
@@ -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);
index b2391e3f818dad83a0473ef710b0bc5372dad56c..6f09197d630e0e6fc88939cd727fbb2ca862cad7 100644 (file)
@@ -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;
index 7b9ec4808bedceba6a934259f0a69bd81b62f2fb..4c0cf61c1ba316a9c9b563f366f7458a44edc883 100644 (file)
@@ -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);