From decc7ec5183715bcd268dd6d6674ff0a94665c27 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Wed, 24 Sep 2014 20:45:16 +0200 Subject: [PATCH] 6c/8c: eleminate moves by swaping source and destination operands in peephole pass --- sys/src/cmd/6c/peep.c | 24 ++++++++++++++++++++++++ sys/src/cmd/8c/peep.c | 19 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/sys/src/cmd/6c/peep.c b/sys/src/cmd/6c/peep.c index e977b5c1f..e8be730a3 100644 --- a/sys/src/cmd/6c/peep.c +++ b/sys/src/cmd/6c/peep.c @@ -407,6 +407,30 @@ subprop(Reg *r0) case AMOVQL: return 0; + case AORL: + case AORQ: + case AANDL: + case AANDQ: + case AXORL: + case AXORQ: + case AADDL: + case AADDQ: + case AADCL: + case AADCQ: + /* + * can swap when: + * ADD R2, R1 + * MOV R1, R2 + * convert to: + * ADD R1, R2 + * MOV R2, R1 / no use for R1 + */ + if(p->to.type == v1->type && p->from.type == v2->type){ + copysub(&p->from, v2, v1, 1); + goto gotit; + } + break; + case AMOVL: case AMOVQ: if(p->to.type == v1->type) diff --git a/sys/src/cmd/8c/peep.c b/sys/src/cmd/8c/peep.c index 06f668c56..8f0fae88a 100644 --- a/sys/src/cmd/8c/peep.c +++ b/sys/src/cmd/8c/peep.c @@ -315,6 +315,25 @@ subprop(Reg *r0) case AFSTSW: return 0; + case AORL: + case AANDL: + case AXORL: + case AADDL: + case AADCL: + /* + * can swap when: + * ADD R2, R1 + * MOV R1, R2 + * convert to: + * ADD R1, R2 + * MOV R2, R1 / no use for R1 + */ + if(p->to.type == v1->type && p->from.type == v2->type){ + copysub(&p->from, v2, v1, 1); + goto gotit; + } + break; + case AMOVL: if(p->to.type == v1->type) goto gotit;