BSD 4_4 release
[unix-history] / usr / src / old / pcc / c2.tahoe / c21.c
index 776178d..36323be 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)c21.c      1.5 (Berkeley/CCI) %G%";
+static char sccsid[] = "@(#)c21.c      1.10 (Berkeley/CCI) 8/25/88";
 #endif
 
 /*
 #endif
 
 /*
@@ -292,9 +292,10 @@ bmove() {
                        case 1: pf->subop = WORD; break;
                        case 2: pf->subop = LONG; break;
                        }
                        case 1: pf->subop = WORD; break;
                        case 2: pf->subop = LONG; break;
                        }
+                       pf->pop = 0;
                        redunm++; nsaddr++;
                        redunm++; nsaddr++;
+                       goto std;
                }
                }
-               goto std;
 ashadd:
                /* at this point, RT2 and RT3 are guaranteed to be simple regs*/
                if (shcnt == 1) {
 ashadd:
                /* at this point, RT2 and RT3 are guaranteed to be simple regs*/
                if (shcnt == 1) {
@@ -303,6 +304,16 @@ ashadd:
                        **      shll    $1,A,A  >       addl2   A,A
                        **      shll    $1,A,B  >       addl3   A,A,B
                        */
                        **      shll    $1,A,A  >       addl2   A,A
                        **      shll    $1,A,B  >       addl3   A,A,B
                        */
+                       if ((pf = p->forw)->op == CBR ||
+                           (pf->op == MOV && (pf = pf->forw)->op == CBR))
+                               /*
+                               ** shll and addl handle the N bit differently
+                               ** on overflow; avoid N bit CBRs
+                               */
+                               switch (pf->subop) {
+                               case JLE: case JGE: case JLT: case JGT:
+                                       goto std;
+                               }
                        p->op = ADD;
                        strcpy(regs[RT1], regs[RT2]);
                        if(equstr(regs[RT2], regs[RT3])) {
                        p->op = ADD;
                        strcpy(regs[RT1], regs[RT2]);
                        if(equstr(regs[RT2], regs[RT3])) {
@@ -571,7 +582,8 @@ bflow(p)
        int flow= -1;
        struct node *olduse=0, *olduse1=0;
 
        int flow= -1;
        struct node *olduse=0, *olduse1=0;
 
-       if (p->subop==QUAD || p->subop==DOUBLE || (p->subop&0xF0)==DOUBLE<<4)
+       if (p->subop==QUAD || p->subop==DOUBLE || (p->subop&0xF0)==DOUBLE<<4 ||
+           p->op==EMUL)
                dblflg |= 1;    /* double dest */
        if ((p->subop&0xF)==DOUBLE || p->subop==QUAD)
                dblflg |= 2;    /* double src */
                dblflg |= 1;    /* double dest */
        if ((p->subop&0xF)==DOUBLE || p->subop==QUAD)
                dblflg |= 2;    /* double src */
@@ -650,7 +662,8 @@ bflow(p)
                                if (tempreg(src,r2))
                                        uses[r2]=uses[r], uses[r]=0;
                                redun3(p);
                                if (tempreg(src,r2))
                                        uses[r2]=uses[r], uses[r]=0;
                                redun3(p);
-                               newcode(p); redunm++; flow=r;
+                               newcode(p); redunm++;
+                               return(p);      /* avoid stale uses[] data */
                        } else
                                splitrand(p);
                }
                        } else
                                splitrand(p);
                }
@@ -672,7 +685,6 @@ bflow(p)
 #ifndef EMOD
                case EDIV:
 #endif EMOD
 #ifndef EMOD
                case EDIV:
 #endif EMOD
-               case EMUL:
                case AOBLEQ: case AOBLSS:
                        break;
                default:
                case AOBLEQ: case AOBLSS:
                        break;
                default:
@@ -789,6 +801,7 @@ bflow(p)
                                        uses[r]=p;
                                        regs[r][0] =
                                            (*--cp2=='[' ? OPX<<4 : OPB<<4);
                                        uses[r]=p;
                                        regs[r][0] =
                                            (*--cp2=='[' ? OPX<<4 : OPB<<4);
+                                       regs[r][1] = '\0';
                                }
                                *cp1=t;
                        }
                                }
                                *cp1=t;
                        }
@@ -841,7 +854,7 @@ register struct node *q;
                        case ATANF: case LOGF: case SQRTF: case EXPF:
                                return(q);
                        }
                        case ATANF: case LOGF: case SQRTF: case EXPF:
                                return(q);
                        }
-               
+       again:
                if(q->subop == p->subop)
                        switch(p->op) { /* do it in the accumulator */
                        case LDF:       /* redundant load */
                if(q->subop == p->subop)
                        switch(p->op) { /* do it in the accumulator */
                        case LDF:       /* redundant load */
@@ -917,19 +930,20 @@ register struct node *q;
                uses[r] = 0;
                if(q->subop == DOUBLE)
                        uses[r+1] = 0;
                uses[r] = 0;
                if(q->subop == DOUBLE)
                        uses[r+1] = 0;
-               { /* undo any effect on uses in the area between p and q,
-                  * as we are going over it again */
-                       register struct node *b;
-                       for(b=p; b!=q; b=b->back) {
-                               for(r=0; r<NUSE; r++) {
-                                       if(uses[r] == b)
-                                               uses[r] = 0;
-                                       if(useacc == b)
-                                               useacc = 0;
-                               }
-                       }
+               for(p = p->back; p != q && (!uses[r] || !uses[r+1]); p = p->back) {
+                       int xr;
+
+                       splitrand(p);
+                       if((xr=isreg(regs[RT1])) < 0)
+                               continue;
+                       if(!uses[r] && xr == r)
+                               uses[r] = p;
+                       else if(q->subop == DOUBLE && !uses[r+1] && xr == r+1)
+                               uses[r+1] = p;
                }
                }
-               return(p->forw); /* make p the next for bflow */
+               if(p = uses[r])
+                       goto again;
+               return(q->forw); /* DON'T re-scan code with dated uses[] */
        }
        /* it's a store to reg which isnt used elsewhere */
        if((p=q->forw)->op == CBR) {
        }
        /* it's a store to reg which isnt used elsewhere */
        if((p=q->forw)->op == CBR) {