Commit 2799e0ec authored by Ken Thompson's avatar Ken Thompson

peep: fix bug in peep optimizer.

reg: enable peep optimizer.
cgen64: better int64 code.

R=r
CC=golang-dev
https://golang.org/cl/3989065
parent 22345989
...@@ -204,14 +204,17 @@ cgen64(Node *n, Node *res) ...@@ -204,14 +204,17 @@ cgen64(Node *n, Node *res)
// here and below (verify it optimizes to EOR) // here and below (verify it optimizes to EOR)
gins(AEOR, &al, &al); gins(AEOR, &al, &al);
gins(AEOR, &ah, &ah); gins(AEOR, &ah, &ah);
} else if(v > 32) { } else
if(v > 32) {
gins(AEOR, &al, &al); gins(AEOR, &al, &al);
// MOVW bl<<(v-32), ah // MOVW bl<<(v-32), ah
gshift(AMOVW, &bl, SHIFT_LL, (v-32), &ah); gshift(AMOVW, &bl, SHIFT_LL, (v-32), &ah);
} else if(v == 32) { } else
if(v == 32) {
gins(AEOR, &al, &al); gins(AEOR, &al, &al);
gins(AMOVW, &bl, &ah); gins(AMOVW, &bl, &ah);
} else if(v > 0) { } else
if(v > 0) {
// MOVW bl<<v, al // MOVW bl<<v, al
gshift(AMOVW, &bl, SHIFT_LL, v, &al); gshift(AMOVW, &bl, SHIFT_LL, v, &al);
...@@ -341,7 +344,8 @@ olsh_break: ...@@ -341,7 +344,8 @@ olsh_break:
gins(AEOR, &al, &al); gins(AEOR, &al, &al);
gins(AEOR, &ah, &ah); gins(AEOR, &ah, &ah);
} }
} else if(v > 32) { } else
if(v > 32) {
if(bh.type->etype == TINT32) { if(bh.type->etype == TINT32) {
// MOVW bh->(v-32), al // MOVW bh->(v-32), al
gshift(AMOVW, &bh, SHIFT_AR, v-32, &al); gshift(AMOVW, &bh, SHIFT_AR, v-32, &al);
...@@ -353,7 +357,8 @@ olsh_break: ...@@ -353,7 +357,8 @@ olsh_break:
gshift(AMOVW, &bh, SHIFT_LR, v-32, &al); gshift(AMOVW, &bh, SHIFT_LR, v-32, &al);
gins(AEOR, &ah, &ah); gins(AEOR, &ah, &ah);
} }
} else if(v == 32) { } else
if(v == 32) {
gins(AMOVW, &bh, &al); gins(AMOVW, &bh, &al);
if(bh.type->etype == TINT32) { if(bh.type->etype == TINT32) {
// MOVW bh->31, ah // MOVW bh->31, ah
...@@ -361,7 +366,8 @@ olsh_break: ...@@ -361,7 +366,8 @@ olsh_break:
} else { } else {
gins(AEOR, &ah, &ah); gins(AEOR, &ah, &ah);
} }
} else if( v > 0) { } else
if( v > 0) {
// MOVW bl>>v, al // MOVW bl>>v, al
gshift(AMOVW, &bl, SHIFT_LR, v, &al); gshift(AMOVW, &bl, SHIFT_LR, v, &al);
...@@ -384,11 +390,16 @@ olsh_break: ...@@ -384,11 +390,16 @@ olsh_break:
regalloc(&s, types[TUINT32], N); regalloc(&s, types[TUINT32], N);
regalloc(&creg, types[TUINT32], N); regalloc(&creg, types[TUINT32], N);
if (is64(r->type)) { if(is64(r->type)) {
// shift is >= 1<<32 // shift is >= 1<<32
split64(r, &cl, &ch); split64(r, &cl, &ch);
gmove(&ch, &s); gmove(&ch, &s);
p1 = gins(ATST, &s, N); gins(ATST, &s, N);
if(bh.type->etype == TINT32)
p1 = gshift(AMOVW, &bh, SHIFT_AR, 31, &ah);
else
p1 = gins(AEOR, &ah, &ah);
p1->scond = C_SCOND_NE;
p6 = gbranch(ABNE, T); p6 = gbranch(ABNE, T);
gmove(&cl, &s); gmove(&cl, &s);
splitclean(); splitclean();
...@@ -441,7 +452,6 @@ olsh_break: ...@@ -441,7 +452,6 @@ olsh_break:
p1 = gshift(AMOVW, &bh, SHIFT_AR, 31, &ah); p1 = gshift(AMOVW, &bh, SHIFT_AR, 31, &ah);
else else
p1 = gins(AEOR, &ah, &ah); p1 = gins(AEOR, &ah, &ah);
p1->scond = C_SCOND_EQ;
p4 = gbranch(ABEQ, T); p4 = gbranch(ABEQ, T);
// check if shift is < 64 // check if shift is < 64
...@@ -461,33 +471,23 @@ olsh_break: ...@@ -461,33 +471,23 @@ olsh_break:
// MOVW bh->(s-32), al // MOVW bh->(s-32), al
p1 = gregshift(AMOVW, &bh, SHIFT_AR, &s, &al); p1 = gregshift(AMOVW, &bh, SHIFT_AR, &s, &al);
p1->scond = C_SCOND_LO; p1->scond = C_SCOND_LO;
// MOVW bh->31, ah
p1 = gshift(AMOVW, &bh, SHIFT_AR, 31, &ah);
p1->scond = C_SCOND_LO;
} else { } else {
// MOVW bh>>(v-32), al // MOVW bh>>(v-32), al
p1 = gregshift(AMOVW, &bh, SHIFT_LR, &s, &al); p1 = gregshift(AMOVW, &bh, SHIFT_LR, &s, &al);
p1->scond = C_SCOND_LO; p1->scond = C_SCOND_LO;
p1 = gins(AEOR, &ah, &ah);
p1->scond = C_SCOND_LO;
} }
// BLO end // BLO end
p5 = gbranch(ABLO, T); p5 = gbranch(ABLO, T);
// s >= 64 // s >= 64
if (p6 != P) patch(p6, pc); if(p6 != P)
patch(p6, pc);
if(bh.type->etype == TINT32) { if(bh.type->etype == TINT32) {
// MOVW bh->31, al // MOVW bh->31, al
gshift(AMOVW, &bh, SHIFT_AR, 31, &al); gshift(AMOVW, &bh, SHIFT_AR, 31, &al);
// MOVW bh->31, ah
gshift(AMOVW, &bh, SHIFT_AR, 31, &ah);
} else { } else {
gins(AEOR, &al, &al); gins(AEOR, &al, &al);
gins(AEOR, &ah, &ah);
} }
patch(p2, pc); patch(p2, pc);
......
...@@ -99,6 +99,8 @@ loop1: ...@@ -99,6 +99,8 @@ loop1:
case AMOVW: case AMOVW:
case AMOVF: case AMOVF:
case AMOVD: case AMOVD:
if(p->scond)
break;
if(!regtyp(&p->to)) if(!regtyp(&p->to))
break; break;
// if(isdconst(&p->from)) { // if(isdconst(&p->from)) {
...@@ -335,6 +337,7 @@ subprop(Reg *r0) ...@@ -335,6 +337,7 @@ subprop(Reg *r0)
case AMULLU: case AMULLU:
case AMULA: case AMULA:
case AMVN:
case ACMN: case ACMN:
case AADD: case AADD:
...@@ -347,7 +350,6 @@ subprop(Reg *r0) ...@@ -347,7 +350,6 @@ subprop(Reg *r0)
case AORR: case AORR:
case AAND: case AAND:
case AEOR: case AEOR:
case AMVN:
case AMUL: case AMUL:
case AMULU: case AMULU:
case ADIV: case ADIV:
...@@ -1014,6 +1016,7 @@ copyu(Prog *p, Adr *v, Adr *s) ...@@ -1014,6 +1016,7 @@ copyu(Prog *p, Adr *v, Adr *s)
case AMULLU: /* read, read, write, write */ case AMULLU: /* read, read, write, write */
case AMULA: case AMULA:
case AMVN:
return 2; return 2;
case AADD: /* read, read, write */ case AADD: /* read, read, write */
...@@ -1027,7 +1030,6 @@ copyu(Prog *p, Adr *v, Adr *s) ...@@ -1027,7 +1030,6 @@ copyu(Prog *p, Adr *v, Adr *s)
case AORR: case AORR:
case AAND: case AAND:
case AEOR: case AEOR:
case AMVN:
case AMUL: case AMUL:
case AMULU: case AMULU:
case ADIV: case ADIV:
......
...@@ -143,7 +143,7 @@ regopt(Prog *firstp) ...@@ -143,7 +143,7 @@ regopt(Prog *firstp)
first++; first++;
if(debug['K']) { if(debug['K']) {
if(first != 13) if(first != 2)
return; return;
// debug['R'] = 2; // debug['R'] = 2;
// debug['P'] = 2; // debug['P'] = 2;
...@@ -491,7 +491,7 @@ brk: ...@@ -491,7 +491,7 @@ brk:
* peep-hole on basic block * peep-hole on basic block
*/ */
if(!debug['R'] || debug['P']) { if(!debug['R'] || debug['P']) {
// peep(); peep();
} }
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment