X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fcoptcmp.c;h=b99c1a69a48c544d0829ad63f83351bca560ba52;hb=7aefd9b4e7b67908b7b3c38b6003c7f1a8d3ee2d;hp=cd01c3b298386444b89febf027e5224b01af664b;hpb=82919fa2f8eb5baf6d859f8334271d63fd848660;p=cc65 diff --git a/src/cc65/coptcmp.c b/src/cc65/coptcmp.c index cd01c3b29..b99c1a69a 100644 --- a/src/cc65/coptcmp.c +++ b/src/cc65/coptcmp.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2001-2009, Ullrich von Bassewitz */ +/* (C) 2001-2012, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -56,11 +56,6 @@ static const unsigned char CmpInvertTab [] = { CMP_ULE, CMP_ULT, CMP_UGE, CMP_UGT }; -/* Table to show which compares are signed (use the N flag) */ -static const char CmpSignedTab [] = { - 0, 0, 1, 1, 1, 1, 0, 0, 0, 0 -}; - /*****************************************************************************/ @@ -434,70 +429,48 @@ unsigned OptCmp3 (CodeSeg* S) L[1]->OPC == OP65_CMP && CE_IsKnownImm (L[1], 0)) { + int Delete = 0; + /* Check for the call to boolxx. We only remove the compare if * the carry flag is evaluated later, because the load will not * set the carry flag. */ if (L[2]->OPC == OP65_JSR) { - switch (FindBoolCmpCond (L[2]->Arg)) { - - case CMP_EQ: - case CMP_NE: - case CMP_GT: - case CMP_GE: - case CMP_LT: - case CMP_LE: - /* Remove the compare */ - CS_DelEntry (S, I+1); - ++Changes; - break; - - case CMP_UGT: + switch (FindBoolCmpCond (L[2]->Arg)) { + + case CMP_EQ: + case CMP_NE: + case CMP_GT: + case CMP_GE: + case CMP_LT: + case CMP_LE: + /* Remove the compare */ + Delete = 1; + break; + + case CMP_UGT: case CMP_UGE: - case CMP_ULT: - case CMP_ULE: - case CMP_INV: - /* Leave it alone */ - break; - } + case CMP_ULT: + case CMP_ULE: + case CMP_INV: + /* Leave it alone */ + break; + } - } else { + } else if ((L[2]->Info & OF_FBRA) != 0) { - /* Check for a branch on conditions that are set by the load. - * Beware: The insn may branch to another conditional branch - * that evaluates other flags, so check that. - */ - CodeEntry* E = L[2]; - int Delete = 0; - while (1) { - if ((E->Info & (OF_CBRA|OF_UBRA)) != 0) { - /* A conditional branch. Check if it jumps on a - * condition not set by the load. - */ - if ((E->Info & (OF_FBRA|OF_UBRA)) == 0) { - /* Invalid branch */ - break; - } else if (E->JumpTo == 0) { - /* Jump to external */ - Delete = 1; - break; - } else { - /* Check target of branch */ - E = E->JumpTo->Owner; - } - } else { - /* Some other insn */ - Delete = 1; - break; - } - } + /* The following insn branches on the condition of a load, so + * the compare instruction can be removed. + */ + Delete = 1; - /* Delete the compare if we can */ - if (Delete) { - CS_DelEntry (S, I+1); - ++Changes; - } - } + } + + /* Delete the compare if we can */ + if (Delete) { + CS_DelEntry (S, I+1); + ++Changes; + } } /* Next entry */ @@ -812,9 +785,6 @@ unsigned OptCmp8 (CodeSeg* S) unsigned Changes = 0; unsigned I; - /* Generate register info for this step */ - CS_GenRegInfo (S); - /* Walk over the entries */ I = 0; while (I < CS_GetEntryCount (S)) { @@ -911,9 +881,6 @@ NextEntry: } - /* Free register info */ - CS_FreeRegInfo (S); - /* Return the number of changes made */ return Changes; }