1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-19 06:31:31 +00:00

Fixed a problem with OptCmp3 that was in there for a while but is now

triggered because of the new subtraction code sequence.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4107 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2009-09-01 10:06:39 +00:00
parent 7c4240fe69
commit cdc3afa6ef

View File

@ -434,6 +434,8 @@ unsigned OptCmp3 (CodeSeg* S)
L[1]->OPC == OP65_CMP && L[1]->OPC == OP65_CMP &&
CE_IsKnownImm (L[1], 0)) { CE_IsKnownImm (L[1], 0)) {
int Delete = 0;
/* Check for the call to boolxx. We only remove the compare if /* Check for the call to boolxx. We only remove the compare if
* the carry flag is evaluated later, because the load will not * the carry flag is evaluated later, because the load will not
* set the carry flag. * set the carry flag.
@ -448,8 +450,7 @@ unsigned OptCmp3 (CodeSeg* S)
case CMP_LT: case CMP_LT:
case CMP_LE: case CMP_LE:
/* Remove the compare */ /* Remove the compare */
CS_DelEntry (S, I+1); Delete = 1;
++Changes;
break; break;
case CMP_UGT: case CMP_UGT:
@ -461,35 +462,13 @@ unsigned OptCmp3 (CodeSeg* S)
break; break;
} }
} else { } else if ((L[2]->Info & OF_FBRA) != 0) {
/* Check for a branch on conditions that are set by the load. /* The following insn branches on the condition of a load, so
* Beware: The insn may branch to another conditional branch * the compare instruction can be removed.
* 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; Delete = 1;
break;
} else {
/* Check target of branch */
E = E->JumpTo->Owner;
}
} else {
/* Some other insn */
Delete = 1;
break;
}
} }
/* Delete the compare if we can */ /* Delete the compare if we can */
@ -498,7 +477,6 @@ unsigned OptCmp3 (CodeSeg* S)
++Changes; ++Changes;
} }
} }
}
/* Next entry */ /* Next entry */
++I; ++I;