summaryrefslogtreecommitdiff
path: root/src/cmd/8g/peep.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/8g/peep.c')
-rw-r--r--src/cmd/8g/peep.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/cmd/8g/peep.c b/src/cmd/8g/peep.c
index 580b1a922..5ad29e1b2 100644
--- a/src/cmd/8g/peep.c
+++ b/src/cmd/8g/peep.c
@@ -120,6 +120,25 @@ peep(void)
p = p->link;
}
}
+
+ // movb elimination.
+ // movb is simulated by the linker
+ // when a register other than ax, bx, cx, dx
+ // is used, so rewrite to other instructions
+ // when possible. a movb into a register
+ // can smash the entire 32-bit register without
+ // causing any trouble.
+ for(r=firstr; r!=R; r=r->link) {
+ p = r->prog;
+ if(p->as == AMOVB && regtyp(&p->to)) {
+ // movb into register.
+ // from another register or constant can be movl.
+ if(regtyp(&p->from) || p->from.type == D_CONST)
+ p->as = AMOVL;
+ else
+ p->as = AMOVBLZX;
+ }
+ }
// constant propagation
// find MOV $con,R followed by
@@ -152,6 +171,8 @@ loop1:
for(r=firstr; r!=R; r=r->link) {
p = r->prog;
switch(p->as) {
+ case AMOVB:
+ case AMOVW:
case AMOVL:
if(regtyp(&p->to))
if(regtyp(&p->from)) {
@@ -182,6 +203,7 @@ loop1:
}
break;
+ case AADDB:
case AADDL:
case AADDW:
if(p->from.type != D_CONST || needc(p->link))
@@ -204,6 +226,7 @@ loop1:
}
break;
+ case ASUBB:
case ASUBL:
case ASUBW:
if(p->from.type != D_CONST || needc(p->link))
@@ -380,6 +403,8 @@ subprop(Reg *r0)
case AMOVSL:
return 0;
+ case AMOVB:
+ case AMOVW:
case AMOVL:
if(p->to.type == v1->type)
goto gotit;
@@ -560,6 +585,8 @@ copyu(Prog *p, Adr *v, Adr *s)
case ANOP: /* rhs store */
+ case AMOVB:
+ case AMOVW:
case AMOVL:
case AMOVBLSX:
case AMOVBLZX:
@@ -624,8 +651,6 @@ copyu(Prog *p, Adr *v, Adr *s)
case AXORB:
case AXORL:
case AXORW:
- case AMOVB:
- case AMOVW:
if(copyas(&p->to, v))
return 2;
goto caseread;