From: Matthew Dempsky Date: Fri, 18 Jan 2013 21:33:25 +0000 (-0500) Subject: cmd/6c: Improve peep hole optimization of rotate and shift instructions. X-Git-Tag: go1.1rc2~1357 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=41ec481a53b2592111e1278670b3361ef98c352d;p=gostls13.git cmd/6c: Improve peep hole optimization of rotate and shift instructions. 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 --- diff --git a/src/cmd/6c/peep.c b/src/cmd/6c/peep.c index d3a9ee9e0e..c648d8c005 100644 --- a/src/cmd/6c/peep.c +++ b/src/cmd/6c/peep.c @@ -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: diff --git a/src/cmd/6g/peep.c b/src/cmd/6g/peep.c index 9b6278792a..ee58d67fbc 100644 --- a/src/cmd/6g/peep.c +++ b/src/cmd/6g/peep.c @@ -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;