]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/6c: Improve peep hole optimization of rotate and shift instructions.
authorMatthew Dempsky <mdempsky@google.com>
Fri, 18 Jan 2013 21:33:25 +0000 (16:33 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 18 Jan 2013 21:33:25 +0000 (16:33 -0500)
Update #4629.

$ cat shift2.c
unsigned int
shift(unsigned int x, unsigned int y)
{
        x = (x << 3);
        y = (y << 5);
        x = (x << 7);
        y = (y << 9);
        return x ^ y;
}

## BEFORE
$ go tool 6c -S shift2.c
(shift2.c:2) TEXT shift+0(SB),$0-8
(shift2.c:4) MOVL x+0(FP),!!AX
(shift2.c:4) SALL $3,!!AX
(shift2.c:4) MOVL AX,!!DX
(shift2.c:5) MOVL y+4(FP),!!AX
(shift2.c:5) SALL $5,!!AX
(shift2.c:5) MOVL AX,!!CX
(shift2.c:6) MOVL DX,!!AX
(shift2.c:6) SALL $7,!!AX
(shift2.c:6) MOVL AX,!!DX
(shift2.c:7) MOVL CX,!!AX
(shift2.c:7) SALL $9,!!AX
(shift2.c:7) MOVL AX,!!CX
(shift2.c:8) MOVL DX,!!AX
(shift2.c:8) XORL CX,!!AX
(shift2.c:8) RET ,!!
(shift2.c:8) RET ,!!
(shift2.c:8) END ,!!

## AFTER
$ go tool 6c -S shift2.c
(shift2.c:2) TEXT shift+0(SB),$0-8
(shift2.c:4) MOVL x+0(FP),!!AX
(shift2.c:4) SALL $3,!!AX
(shift2.c:5) MOVL y+4(FP),!!CX
(shift2.c:5) SALL $5,!!CX
(shift2.c:6) SALL $7,!!AX
(shift2.c:7) SALL $9,!!CX
(shift2.c:8) XORL CX,!!AX
(shift2.c:8) RET ,!!
(shift2.c:8) RET ,!!
(shift2.c:8) END ,!!

R=rsc, minux.ma, dave, nigeltao
CC=golang-dev
https://golang.org/cl/7066055

src/cmd/6c/peep.c
src/cmd/6g/peep.c

index d3a9ee9e0eb1a32f64f253243a3c667ee6cf2feb..c648d8c0056114fbf1773470c1431c944e5b8fbb 100644 (file)
@@ -330,20 +330,7 @@ subprop(Reg *r0)
                case AIMULW:
                        if(p->to.type != D_NONE)
                                break;
-
-               case ADIVB:
-               case ADIVL:
-               case ADIVQ:
-               case ADIVW:
-               case AIDIVB:
-               case AIDIVL:
-               case AIDIVQ:
-               case AIDIVW:
-               case AIMULB:
-               case AMULB:
-               case AMULL:
-               case AMULQ:
-               case AMULW:
+                       goto giveup;
 
                case AROLB:
                case AROLL:
@@ -369,6 +356,23 @@ subprop(Reg *r0)
                case ASHRL:
                case ASHRQ:
                case ASHRW:
+                       if(p->from.type == D_CONST)
+                               break;
+                       goto giveup;
+
+               case ADIVB:
+               case ADIVL:
+               case ADIVQ:
+               case ADIVW:
+               case AIDIVB:
+               case AIDIVL:
+               case AIDIVQ:
+               case AIDIVW:
+               case AIMULB:
+               case AMULB:
+               case AMULL:
+               case AMULQ:
+               case AMULW:
 
                case AREP:
                case AREPN:
@@ -384,6 +388,7 @@ subprop(Reg *r0)
                case AMOVSL:
                case AMOVSQ:
                case AMOVQL:
+               giveup:
                        return 0;
 
                case AMOVL:
index 9b6278792a826e6bf333a454634067c49aa54488..ee58d67fbc3c170c1bfcd36220dd28d4fa5fe606 100644 (file)
@@ -664,6 +664,7 @@ subprop(Reg *r0)
                case AIMULW:
                        if(p->to.type != D_NONE)
                                break;
+                       goto giveup;
 
                case ARCLB:
                case ARCLL:
@@ -699,6 +700,7 @@ subprop(Reg *r0)
                case ASHRW:
                        if(p->from.type == D_CONST)
                                break;
+                       goto giveup;
 
                case ADIVB:
                case ADIVL:
@@ -727,6 +729,7 @@ subprop(Reg *r0)
                case AMOVSB:
                case AMOVSL:
                case AMOVSQ:
+               giveup:
                        if(debug['P'] && debug['v'])
                                print("\tfound %P; return 0\n", p);
                        return 0;