]> Cypherpunks repositories - gostls13.git/commitdiff
peep: fix bug in peep optimizer.
authorKen Thompson <ken@golang.org>
Mon, 7 Feb 2011 23:00:30 +0000 (15:00 -0800)
committerKen Thompson <ken@golang.org>
Mon, 7 Feb 2011 23:00:30 +0000 (15:00 -0800)
reg: enable peep optimizer.
cgen64: better int64 code.

R=r
CC=golang-dev
https://golang.org/cl/3989065

src/cmd/5g/cgen64.c
src/cmd/5g/peep.c
src/cmd/5g/reg.c

index 78f2f4aeb46de2ffb7f2f91a343dd0754cdf1ddf..e5604e2394a47d1c83d45ced416d873b6e218c0d 100644 (file)
@@ -204,14 +204,17 @@ cgen64(Node *n, Node *res)
                                // here and below (verify it optimizes to EOR)
                                gins(AEOR, &al, &al);
                                gins(AEOR, &ah, &ah);
-                       } else if(v > 32) {
+                       } else
+                       if(v > 32) {
                                gins(AEOR, &al, &al);
                                //      MOVW    bl<<(v-32), ah
                                gshift(AMOVW, &bl, SHIFT_LL, (v-32), &ah);
-                       } else if(v == 32) {
+                       } else
+                       if(v == 32) {
                                gins(AEOR, &al, &al);
                                gins(AMOVW, &bl, &ah);
-                       } else if(v > 0) {
+                       } else
+                       if(v > 0) {
                                //      MOVW    bl<<v, al
                                gshift(AMOVW, &bl, SHIFT_LL, v, &al);
 
@@ -341,7 +344,8 @@ olsh_break:
                                        gins(AEOR, &al, &al);
                                        gins(AEOR, &ah, &ah);
                                }
-                       } else if(v > 32) {
+                       } else
+                       if(v > 32) {
                                if(bh.type->etype == TINT32) {
                                        //      MOVW    bh->(v-32), al
                                        gshift(AMOVW, &bh, SHIFT_AR, v-32, &al);
@@ -353,7 +357,8 @@ olsh_break:
                                        gshift(AMOVW, &bh, SHIFT_LR, v-32, &al);
                                        gins(AEOR, &ah, &ah);
                                }
-                       } else if(v == 32) {
+                       } else
+                       if(v == 32) {
                                gins(AMOVW, &bh, &al);
                                if(bh.type->etype == TINT32) {
                                        //      MOVW    bh->31, ah
@@ -361,7 +366,8 @@ olsh_break:
                                } else {
                                        gins(AEOR, &ah, &ah);
                                }
-                       } else if( v > 0) {
+                       } else
+                       if( v > 0) {
                                //      MOVW    bl>>v, al
                                gshift(AMOVW, &bl, SHIFT_LR, v, &al);
        
@@ -384,11 +390,16 @@ olsh_break:
 
                regalloc(&s, types[TUINT32], N);
                regalloc(&creg, types[TUINT32], N);
-               if (is64(r->type)) {
+               if(is64(r->type)) {
                        // shift is >= 1<<32
                        split64(r, &cl, &ch);
                        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);
                        gmove(&cl, &s);
                        splitclean();
@@ -441,7 +452,6 @@ olsh_break:
                        p1 = gshift(AMOVW, &bh, SHIFT_AR, 31, &ah);
                else
                        p1 = gins(AEOR, &ah, &ah);
-               p1->scond = C_SCOND_EQ;
                p4 = gbranch(ABEQ, T);
 
                // check if shift is < 64
@@ -461,33 +471,23 @@ olsh_break:
                        //      MOVW    bh->(s-32), al
                        p1 = gregshift(AMOVW, &bh, SHIFT_AR, &s, &al);
                        p1->scond = C_SCOND_LO;
-
-                       //      MOVW    bh->31, ah
-                       p1 = gshift(AMOVW, &bh, SHIFT_AR, 31, &ah);
-                       p1->scond = C_SCOND_LO;
                } else {
                        //      MOVW    bh>>(v-32), al
                        p1 = gregshift(AMOVW, &bh, SHIFT_LR, &s, &al);
                        p1->scond = C_SCOND_LO;
-
-                       p1 = gins(AEOR, &ah, &ah);
-                       p1->scond = C_SCOND_LO;
                }
 
                //      BLO     end
                p5 = gbranch(ABLO, T);
 
                // s >= 64
-               if (p6 != P) patch(p6, pc);
+               if(p6 != P)
+                       patch(p6, pc);
                if(bh.type->etype == TINT32) {
                        //      MOVW    bh->31, al
                        gshift(AMOVW, &bh, SHIFT_AR, 31, &al);
-
-                       //      MOVW    bh->31, ah
-                       gshift(AMOVW, &bh, SHIFT_AR, 31, &ah);
                } else {
                        gins(AEOR, &al, &al);
-                       gins(AEOR, &ah, &ah);
                }
 
                patch(p2, pc);
index f619a6206f8e8694361257a11ee4205362f0e042..783934f9d42e1673dac73cd02bf237854cc9d2c3 100644 (file)
@@ -99,6 +99,8 @@ loop1:
                case AMOVW:
                case AMOVF:
                case AMOVD:
+                       if(p->scond)
+                               break;
                        if(!regtyp(&p->to))
                                break;
 //                     if(isdconst(&p->from)) {
@@ -335,6 +337,7 @@ subprop(Reg *r0)
 
                case AMULLU:
                case AMULA:
+               case AMVN:
 
                case ACMN:
                case AADD:
@@ -347,7 +350,6 @@ subprop(Reg *r0)
                case AORR:
                case AAND:
                case AEOR:
-               case AMVN:
                case AMUL:
                case AMULU:
                case ADIV:
@@ -1014,6 +1016,7 @@ copyu(Prog *p, Adr *v, Adr *s)
 
        case AMULLU:    /* read, read, write, write */
        case AMULA:
+       case AMVN:
                return 2;
 
        case AADD:      /* read, read, write */
@@ -1027,7 +1030,6 @@ copyu(Prog *p, Adr *v, Adr *s)
        case AORR:
        case AAND:
        case AEOR:
-       case AMVN:
        case AMUL:
        case AMULU:
        case ADIV:
index eaf02b237e1feed579078571a11bf44478257c0e..104c1b772885cc88230788cba6e7fd0060d856a6 100644 (file)
@@ -143,7 +143,7 @@ regopt(Prog *firstp)
        first++;
 
        if(debug['K']) {
-               if(first != 13)
+               if(first != 2)
                        return;
 //             debug['R'] = 2;
 //             debug['P'] = 2;
@@ -491,7 +491,7 @@ brk:
         * peep-hole on basic block
         */
        if(!debug['R'] || debug['P']) {
-//             peep();
+               peep();
        }
 
        /*