1
0
mirror of https://github.com/golang/go synced 2024-11-22 02:44:39 -07:00

peep: bug fix

R=r
CC=golang-dev
https://golang.org/cl/4173041
This commit is contained in:
Ken Thompson 2011-02-09 13:13:17 -08:00
parent 6c03b0d468
commit acc82ad721
3 changed files with 145 additions and 102 deletions

View File

@ -87,6 +87,10 @@ Dconv(Fmt *fp)
int32 v; int32 v;
a = va_arg(fp->args, Addr*); a = va_arg(fp->args, Addr*);
if(a == A) {
sprint(str, "<nil>");
goto conv;
}
i = a->type; i = a->type;
switch(i) { switch(i) {
@ -183,7 +187,7 @@ Dconv(Fmt *fp)
// a->type = D_ADDR; // a->type = D_ADDR;
// goto conv; // goto conv;
} }
//conv: conv:
return fmtstrcpy(fp, str); return fmtstrcpy(fp, str);
} }

View File

@ -48,7 +48,6 @@ peep(void)
/* /*
* complete R structure * complete R structure
*/ */
t = 0;
for(r=firstr; r!=R; r=r1) { for(r=firstr; r!=R; r=r1) {
r1 = r->link; r1 = r->link;
if(r1 == R) if(r1 == R)
@ -68,7 +67,6 @@ peep(void)
r1->p1 = r2; r1->p1 = r2;
r = r2; r = r2;
t++;
case ADATA: case ADATA:
case AGLOBL: case AGLOBL:
@ -77,8 +75,10 @@ peep(void)
p = p->link; p = p->link;
} }
} }
//dumpit("begin", firstr);
loop1: loop1:
t = 0; t = 0;
for(r=firstr; r!=R; r=r->link) { for(r=firstr; r!=R; r=r->link) {
p = r->prog; p = r->prog;
@ -99,18 +99,9 @@ loop1:
case AMOVW: case AMOVW:
case AMOVF: case AMOVF:
case AMOVD: case AMOVD:
if(p->scond != C_SCOND_NONE) if(regtyp(&p->from))
break; if(p->from.type == p->to.type)
if(!regtyp(&p->to)) if(p->scond == C_SCOND_NONE) {
break;
// if(isdconst(&p->from)) {
// constprop(&p->from, &p->to, r->s1);
// break;
// }
if(!regtyp(&p->from))
break;
if(p->from.type != p->to.type)
break;
if(copyprop(r)) { if(copyprop(r)) {
excise(r); excise(r);
t++; t++;
@ -122,17 +113,24 @@ loop1:
break; break;
} }
} }
break;
if(p->scond == C_SCOND_NONE)
if(regtyp(&p->to))
if(isdconst(&p->from)) {
constprop(&p->from, &p->to, r->s1);
}
break;
}
} }
if(t) if(t)
goto loop1; goto loop1;
/*
* look for MOVB x,R; MOVB R,R return;
*/
for(r=firstr; r!=R; r=r->link) { for(r=firstr; r!=R; r=r->link) {
p = r->prog; p = r->prog;
switch(p->as) { switch(p->as) {
default:
continue;
// case AEOR: // case AEOR:
// /* // /*
// * EOR -1,x,y => MVN x,y // * EOR -1,x,y => MVN x,y
@ -146,26 +144,30 @@ loop1:
// p->from.reg = p->to.reg; // p->from.reg = p->to.reg;
// p->reg = NREG; // p->reg = NREG;
// } // }
// continue; // break;
case AMOVH: case AMOVH:
case AMOVHU: case AMOVHU:
case AMOVB: case AMOVB:
case AMOVBU: case AMOVBU:
/*
* look for MOVB x,R; MOVB R,R
*/
if(p->to.type != D_REG) if(p->to.type != D_REG)
continue; break;
if(r1 == R)
break;
p1 = r1->prog;
if(p1->as != p->as)
break;
if(p1->from.type != D_REG || p1->from.reg != p->to.reg)
break;
if(p1->to.type != D_REG || p1->to.reg != p->to.reg)
break;
excise(r1);
break; break;
} }
r1 = r->link; r1 = r->link;
if(r1 == R)
continue;
p1 = r1->prog;
if(p1->as != p->as)
continue;
if(p1->from.type != D_REG || p1->from.reg != p->to.reg)
continue;
if(p1->to.type != D_REG || p1->to.reg != p->to.reg)
continue;
excise(r1);
} }
// for(r=firstr; r!=R; r=r->link) { // for(r=firstr; r!=R; r=r->link) {
@ -975,7 +977,7 @@ copyu(Prog *p, Adr *v, Adr *s)
} }
return 0; return 0;
case ANOP: /* read, write */ case ANOP: /* read,, write */
case AMOVW: case AMOVW:
case AMOVF: case AMOVF:
case AMOVD: case AMOVD:
@ -1047,12 +1049,12 @@ copyu(Prog *p, Adr *v, Adr *s)
case ADIVF: case ADIVF:
case ADIVD: case ADIVD:
case ACMPF: case ACMPF: /* read, read, */
case ACMPD: case ACMPD:
case ATST:
case ACMP: case ACMP:
case ACMN: case ACMN:
case ACASE: case ACASE:
case ATST: /* read,, */
if(s != A) { if(s != A) {
if(copysub(&p->from, v, s, 1)) if(copysub(&p->from, v, s, 1))
return 1; return 1;
@ -1154,53 +1156,6 @@ copyu(Prog *p, Adr *v, Adr *s)
return 0; return 0;
} }
int
a2type(Prog *p)
{
switch(p->as) {
case ATST:
case ACMP:
case ACMN:
case AMULLU:
case AMULA:
case AADD:
case ASUB:
case ARSB:
case ASLL:
case ASRL:
case ASRA:
case AORR:
case AAND:
case AEOR:
// case AMVN:
case AMUL:
case AMULU:
case ADIV:
case ADIVU:
case AMOD:
case AMODU:
return D_REG;
case ACMPF:
case ACMPD:
case AADDF:
case AADDD:
case ASUBF:
case ASUBD:
case AMULF:
case AMULD:
case ADIVF:
case ADIVD:
return D_FREG;
}
return D_NONE;
}
/* /*
* direct reference, * direct reference,
* could be set/use depending on * could be set/use depending on
@ -1260,17 +1215,33 @@ copyau(Adr *a, Adr *v)
return 0; return 0;
} }
/*
* compare v to the center
* register in p (p->reg)
* the trick is that this
* register might be D_REG
* D_FREG. there are basically
* two cases,
* ADD r,r,r
* CMP r,r,
*/
int int
copyau1(Prog *p, Adr *v) copyau1(Prog *p, Adr *v)
{ {
if(regtyp(v)) { if(regtyp(v))
if(a2type(p) == v->type)
if(p->reg == v->reg) { if(p->reg == v->reg) {
if(a2type(p) != v->type) if(p->to.type != D_NONE) {
print("botch a2type %P\n", p); if(v->type == p->to.type)
return 1; return 1;
return 0;
} }
if(p->from.type != D_NONE) {
if(v->type == p->from.type)
return 1;
return 0;
}
print("copyau1: cant tell %P\n", p);
} }
return 0; return 0;
} }

View File

@ -1375,3 +1375,71 @@ noreturn(Prog *p)
return 1; return 1;
return 0; return 0;
} }
void
dumpone(Reg *r)
{
int z;
Bits bit;
print("%d:%P", r->loop, r->prog);
for(z=0; z<BITS; z++)
bit.b[z] =
r->set.b[z] |
r->use1.b[z] |
r->use2.b[z] |
r->refbehind.b[z] |
r->refahead.b[z] |
r->calbehind.b[z] |
r->calahead.b[z] |
r->regdiff.b[z] |
r->act.b[z] |
0;
// if(bany(&bit)) {
// print("\t");
// if(bany(&r->set))
// print(" s:%Q", r->set);
// if(bany(&r->use1))
// print(" u1:%Q", r->use1);
// if(bany(&r->use2))
// print(" u2:%Q", r->use2);
// if(bany(&r->refbehind))
// print(" rb:%Q ", r->refbehind);
// if(bany(&r->refahead))
// print(" ra:%Q ", r->refahead);
// if(bany(&r->calbehind))
// print("cb:%Q ", r->calbehind);
// if(bany(&r->calahead))
// print(" ca:%Q ", r->calahead);
// if(bany(&r->regdiff))
// print(" d:%Q ", r->regdiff);
// if(bany(&r->act))
// print(" a:%Q ", r->act);
// }
print("\n");
}
void
dumpit(char *str, Reg *r0)
{
Reg *r, *r1;
print("\n%s\n", str);
for(r = r0; r != R; r = r->link) {
dumpone(r);
r1 = r->p2;
if(r1 != R) {
print(" pred:");
for(; r1 != R; r1 = r1->p2link)
print(" %.4ud", r1->prog->loc);
print("\n");
}
// r1 = r->s1;
// if(r1 != R) {
// print(" succ:");
// for(; r1 != R; r1 = r1->s1)
// print(" %.4ud", r1->prog->loc);
// print("\n");
// }
}
}