]> git.sur5r.net Git - cc65/commitdiff
Minor code improvement.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 1 Sep 2009 09:15:19 +0000 (09:15 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 1 Sep 2009 09:15:19 +0000 (09:15 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@4106 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/coptind.c

index 21607d0d6d7f1ac9d92b154606eff6b018d05826..b80610b56b83858fd1ff04b9937014bdc336b566 100644 (file)
@@ -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 */