From cde97a4d5f17fe597cc55aa4653082bf2c01598c Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 29 Mar 2014 19:44:04 +0100 Subject: [PATCH] 6c, 8c: optimize away CMPL/CMPQ reg, $0 instruction in peephole pass when the previous instruction sets the zero flag, we can remove the CMPL/CMPQ instruction. this removes compares for zero/non zero tests only. it only looks at the previous non-nop instruction to see if it sets our compare value register. --- sys/src/cmd/6c/peep.c | 47 +++++++++++++++++++++++++++++++++++++++++++ sys/src/cmd/8c/peep.c | 30 +++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/sys/src/cmd/6c/peep.c b/sys/src/cmd/6c/peep.c index 2511b6c7e..b04b85a25 100644 --- a/sys/src/cmd/6c/peep.c +++ b/sys/src/cmd/6c/peep.c @@ -196,6 +196,53 @@ loop1: p->from = zprog.from; } break; + + case ACMPL: + case ACMPQ: + if(p->to.type != D_CONST || p->to.offset != 0 || regtyp(&p->from) == 0) + break; + if(p->link == P || (p->link->as != AJEQ && p->link->as != AJNE)) + break; + r1 = uniqp(r); + while(r1 != R && r1->prog->as == ANOP) + r1 = uniqp(r1); + if(r1 == R || r1->prog->to.type != p->from.type) + break; + p1 = r1->prog; + switch(p1->as){ + case AANDQ: + case AORQ: + case AXORQ: + case ANEGQ: + case AADDQ: + case AADCQ: + case ASUBQ: + case ASBBQ: + case ASHLQ: + case ASHRQ: + case ASALQ: + case ASARQ: + case AINCQ: + case ADECQ: + if(p->as != ACMPQ) + break; + case AANDL: + case AORL: + case AXORL: + case ANEGL: + case AADDL: + case AADCL: + case ASUBL: + case ASBBL: + case ASHLL: + case ASHRL: + case ASALL: + case ASARL: + case AINCL: + case ADECL: + excise(r); + } + break; } } if(t) diff --git a/sys/src/cmd/8c/peep.c b/sys/src/cmd/8c/peep.c index 5f61925d7..b0f639dd7 100644 --- a/sys/src/cmd/8c/peep.c +++ b/sys/src/cmd/8c/peep.c @@ -137,6 +137,36 @@ loop1: p->from = zprog.from; } break; + + case ACMPL: + if(p->to.type != D_CONST || p->to.offset != 0 || regtyp(&p->from) == 0) + break; + if(p->link == P || (p->link->as != AJEQ && p->link->as != AJNE)) + break; + r1 = uniqp(r); + while(r1 != R && r1->prog->as == ANOP) + r1 = uniqp(r1); + if(r1 == R || r1->prog->to.type != p->from.type) + break; + p1 = r1->prog; + switch(p1->as){ + case AANDL: + case AORL: + case AXORL: + case ANEGL: + case AADDL: + case AADCL: + case ASUBL: + case ASBBL: + case ASHLL: + case ASHRL: + case ASALL: + case ASARL: + case AINCL: + case ADECL: + excise(r); + } + break; } } if(t)