From: uz Date: Tue, 1 Sep 2009 09:15:19 +0000 (+0000) Subject: Minor code improvement. X-Git-Tag: V2.13.0rc1~150 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7c4240fe696770c96c263b99bb576cf231b8c63c;p=cc65 Minor code improvement. git-svn-id: svn://svn.cc65.org/cc65/trunk@4106 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/coptind.c b/src/cc65/coptind.c index 21607d0d6..b80610b56 100644 --- a/src/cc65/coptind.c +++ b/src/cc65/coptind.c @@ -752,7 +752,7 @@ unsigned OptCondBranches1 (CodeSeg* S) CS_DelEntry (S, I+1); /* Remember, we had changes */ - ++Changes; + ++Changes; } else if ((BC == BC_EQ && E->Num == 0) || (BC == BC_NE && E->Num != 0) || @@ -1880,17 +1880,33 @@ unsigned OptPrecalc (CodeSeg* S) } break; - case OP65_ADC: case OP65_ASL: case OP65_EOR: case OP65_LSR: - case OP65_SBC: if (RegValIsKnown (Out->RegA)) { /* Accu op zp with known contents */ Arg = MakeHexArg (Out->RegA); } break; + case OP65_ADC: + case OP65_SBC: + /* If this is an operation with an immediate operand of zero, + * and the register is zero, the operation won't give us any + * results we don't already have (including the flags), so + * remove it. Something like this is generated as a result of + * a compare where parts of the values are known to be zero. + */ + if (In->RegA == 0 && CE_IsKnownImm (E, 0x00)) { + /* 0-0 or 0+0 -> remove */ + CS_DelEntry (S, I); + ++Changes; + } else if (RegValIsKnown (Out->RegA)) { + /* Accu op zp with known contents */ + Arg = MakeHexArg (Out->RegA); + } + break; + case OP65_AND: if (CE_IsKnownImm (E, 0xFF)) { /* AND with 0xFF, remove */