]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/7c/cgen.c
git/branch: somewhere in the syncing, the fix for junk files was lost
[plan9front.git] / sys / src / cmd / 7c / cgen.c
index 2e6010b817fb1f187c8aaa718940f7484c796194..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);
@@ -287,25 +290,28 @@ cgenrel(Node *n, Node *nn, int inrel)
                                reglcgen(&nod2, l, Z);
                        else
                                nod2 = *l;
-                       regalloc(&nod, n, nn);
-                       cgen(r, &nod);
+                       regalloc(&nod1, r, Z);
+                       cgen(r, &nod1);
                } else {
-                       regalloc(&nod, n, nn);
-                       cgen(r, &nod);
+                       regalloc(&nod1, r, Z);
+                       cgen(r, &nod1);
                        if(l->addable < INDEXED)
                                reglcgen(&nod2, l, Z);
                        else
                                nod2 = *l;
                }
-               regalloc(&nod1, n, Z);
-               gopcode(OAS, &nod2, Z, &nod1);
+               if(nod1.type->etype == nod2.type->etype || !typefd[nod1.type->etype])
+                       regalloc(&nod, &nod2, nn);
+               else
+                       regalloc(&nod, &nod1, Z);
+               gopcode(OAS, &nod2, Z, &nod);
                if(nod1.type->etype != nod.type->etype){
                        regalloc(&nod3, &nod, Z);
                        gmove(&nod1, &nod3);
                        regfree(&nod1);
                        nod1 = nod3;
                }
-               gopcode(o, &nod, &nod1, &nod);
+               gopcode(o, &nod1, &nod, &nod);
                gmove(&nod, &nod2);
                if(nn != Z)
                        gmove(&nod, nn);
@@ -525,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);
@@ -577,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);