]> git.gag.com Git - fw/sdcc/commitdiff
* src/mcs51/gen.c (genPlusIncr, genMinusDec, genAddrOf): small
authorMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 29 Sep 2006 11:58:45 +0000 (11:58 +0000)
committerMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Fri, 29 Sep 2006 11:58:45 +0000 (11:58 +0000)
  optimizations, see also patch 887161 by Stas Sergeev
* src/mcs51/peeph.def(104, 207, 209, 212): disabled as they do not seem
  to be necessary anymore,
  (102, 103, 104, 127): renamed all occurances of bp to _bp

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4390 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/mcs51/gen.c
src/mcs51/peeph.def

index a3c0ca41a532eceea2e8cc31da85567a9cf5b3d2..3368fca2df38c259f048c2a056a8cc7ed9e62486 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-09-29 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * src/mcs51/gen.c (genPlusIncr, genMinusDec, genAddrOf): small
+         optimizations, see also patch 887161 by Stas Sergeev
+       * src/mcs51/peeph.def(104, 207, 209, 212): disabled as they do not seem
+         to be necessary anymore,
+         (102, 103, 104, 127): renamed all occurances of bp to _bp
+
 2006-09-27 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * device/include/mcs51/at89c51snd1c.h: fixed MSK_SREQ definition
index 732c97a31d767e74deb56328d901c5b4fbf14dcc..7f091daed7d43da26dd2210af8abca3a11e8b75a 100644 (file)
@@ -4085,7 +4085,9 @@ genPlusIncr (iCode * ic)
   D(emitcode (";     genPlusIncr",""));
 
   /* if increment >=16 bits in register or direct space */
-  if ((AOP_TYPE(IC_LEFT(ic)) == AOP_REG || AOP_TYPE(IC_LEFT(ic)) == AOP_DIR ) &&
+  if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG || 
+        AOP_TYPE(IC_LEFT(ic)) == AOP_DIR ||
+        (IS_AOP_PREG (IC_LEFT(ic)) && !AOP_NEEDSACC (IC_LEFT(ic))) ) &&
       sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
       !isOperandVolatile (IC_RESULT (ic), FALSE) &&
       (size > 1) &&
@@ -4219,6 +4221,14 @@ genPlusIncr (iCode * ic)
       return TRUE;
     }
 
+  if (icount == 1)
+    {
+      MOVA (aopGet (IC_LEFT (ic), 0, FALSE, FALSE));
+      emitcode ("inc", "a");
+      aopPut (IC_RESULT (ic), "a", 0);
+      return TRUE;
+    }
+
   return FALSE;
 }
 
@@ -4545,7 +4555,9 @@ genMinusDec (iCode * ic)
   D (emitcode (";", "genMinusDec"));
 
   /* if decrement >=16 bits in register or direct space */
-  if ((AOP_TYPE(IC_LEFT(ic)) == AOP_REG || AOP_TYPE(IC_LEFT(ic)) == AOP_DIR) &&
+  if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG || 
+        AOP_TYPE(IC_LEFT(ic)) == AOP_DIR ||
+        (IS_AOP_PREG (IC_LEFT(ic)) && !AOP_NEEDSACC (IC_LEFT(ic))) ) &&
       sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
       (size > 1) &&
       (icount == 1))
@@ -4656,6 +4668,14 @@ genMinusDec (iCode * ic)
       return TRUE;
     }
 
+  if (icount == 1)
+    {
+      MOVA (aopGet (IC_LEFT (ic), 0, FALSE, FALSE));
+      emitcode ("dec", "a");
+      aopPut (IC_RESULT (ic), "a", 0);
+      return TRUE;
+    }
+
   return FALSE;
 }
 
@@ -7498,7 +7518,7 @@ genXor (iCode * ic, iCode * ifx)
                   MOVA (aopGet (right, offset, FALSE, FALSE));
                   emitcode ("xrl", "a,%s", aopGet (left, offset, FALSE, TRUE));
                 }
-              
+
               emitcode ("jnz", "%05d$", tlbl->key + 100);
               offset++;
             }
@@ -10877,11 +10897,25 @@ genAddrOf (iCode * ic)
       /* if it has an offset then we need to compute it */
       if (sym->stack)
         {
-          emitcode ("mov", "a,%s", SYM_BP (sym));
-          emitcode ("add", "a,#0x%02x", ((sym->stack < 0) ?
-                                         ((char) (sym->stack - _G.nRegsSaved)) :
-                                         ((char) sym->stack)) & 0xff);
-          aopPut (IC_RESULT (ic), "a", 0);
+          int stack_offset = ((sym->stack < 0) ?
+                              ((char) (sym->stack - _G.nRegsSaved)) :
+                              ((char) sym->stack)) & 0xff;
+          if ((abs(stack_offset) == 1) &&
+              !AOP_NEEDSACC(IC_RESULT (ic)) &&
+              !isOperandVolatile (IC_RESULT (ic), FALSE))
+            {
+              aopPut (IC_RESULT (ic), SYM_BP (sym), 0);
+              if (stack_offset > 0)
+                emitcode ("inc", "%s", aopGet (IC_RESULT (ic), LSB, FALSE, FALSE));
+              else
+                emitcode ("dec", "%s", aopGet (IC_RESULT (ic), LSB, FALSE, FALSE));
+            }
+          else
+            {
+              emitcode ("mov", "a,%s", SYM_BP (sym));
+              emitcode ("add", "a,#0x%02x", stack_offset);
+              aopPut (IC_RESULT (ic), "a", 0);
+            }
         }
       else
         {
index 8c8f01c848e389d5a35490a78c53607d36c10694..2dbda21629664330792b47a8c9629caa17dec22d 100644 (file)
@@ -215,19 +215,19 @@ replace {
 %3:
        mov     dpl,%1
 %7:
-       mov     sp,bp
-       pop     bp
+       mov     sp,_bp
+       pop     _bp
 } by {
-       ;       Peephole 102    removed redundant mov
+       ;       Peephole 102    removed redundant mov to %1
        mov     dpl,%2
        ljmp    %3
 %4:
        mov     dpl,%5
 %3:
 %7:
-       mov     sp,bp
-       pop     bp
-} if notVolatile %1
+       mov     sp,_bp
+       pop     _bp
+} if notVolatile(%1), labelRefCount(%3 1)
 
 replace {
        mov     %1,%2
@@ -237,30 +237,31 @@ replace {
 %3:
        mov     dpl,%1
 %7:
-       mov     sp,bp
-       pop     bp
+       mov     sp,_bp
+       pop     _bp
 } by {
-       ;       Peephole 103    removed redundant mov
+       ;       Peephole 103    removed redundant mov to %1
        mov     dpl,%2
        ljmp    %3
 %4:
        mov     dpl,%5
 %3:
 %7:
-       mov     sp,bp
-       pop     bp
-}
+       mov     sp,_bp
+       pop     _bp
+} if labelRefCount(%3 1)
 
-replace {
-       mov     a,bp
-       clr     c
-       add     a,#0x01
-       mov     r%1,a
-} by {
-       ;       Peephole 104    optimized increment (acc not set to r%1, flags undefined)
-       mov     r%1,bp
-       inc     r%1
-}
+// Does not seem to be triggered anymore
+//replace {
+//     mov     a,_bp
+//     clr     c
+//     add     a,#0x01
+//     mov     r%1,a
+//} by {
+//     ;       Peephole 104    optimized increment (acc not set to r%1, flags undefined)
+//     mov     r%1,_bp
+//     inc     r%1
+//}
 
 replace {
        mov     %1,a
@@ -582,11 +583,11 @@ replace {
 replace {
        push    psw
        mov     psw,%1
-       push    bp
-       mov     bp,%2
+       push    _bp
+       mov     _bp,%2
 %3:
-       mov     %2,bp
-       pop     bp
+       mov     %2,_bp
+       pop     _bp
        pop     psw
        ret
 } by {
@@ -1973,14 +1974,15 @@ replace {
        ;       Peephole 206    removed redundant mov %1,%1
 } if notVolatile
 
-replace {
-       mov     a,_bp
-       add     a,#0x00
-       mov     %1,a
-} by {
-       ;       Peephole 207    removed zero add (acc not set to %1, flags undefined)
-       mov     %1,_bp
-}
+// Does not seem to be triggered anymore
+//replace {
+//     mov     a,_bp
+//     add     a,#0x00
+//     mov     %1,a
+//} by {
+//     ;       Peephole 207    removed zero add (acc not set to %1, flags undefined)
+//     mov     %1,_bp
+//}
 
 replace {
        push    acc
@@ -1991,16 +1993,17 @@ replace {
        mov     r%1,_bp
 }
 
-replace {
-       mov     a,_bp
-       add     a,#0x00
-       inc     a
-       mov     %1,a
-} by {
-       ;       Peephole 209    optimized increment (acc not set to %1, flags undefined)
-       mov     %1,_bp
-       inc     %1
-}
+// Does not seem to be triggered anymore
+//replace {
+//     mov     a,_bp
+//     add     a,#0x00
+//     inc     a
+//     mov     %1,a
+//} by {
+//     ;       Peephole 209    optimized increment (acc not set to %1, flags undefined)
+//     mov     %1,_bp
+//     inc     %1
+//}
 
 replace {
        mov     dptr,#((((%1 >> 8)) <<8) + %1)
@@ -2016,15 +2019,16 @@ replace {
        ;       Peephole 211    removed redundant push %1 pop %1
 }
 
-replace {
-       mov     a,_bp
-       add     a,#0x01
-       mov     r%1,a
-} by {
-       ;       Peephole 212    reduced add sequence to inc
-       mov     r%1,_bp
-       inc     r%1
-}
+// Does not seem to be triggered anymore
+//replace {
+//     mov     a,_bp
+//     add     a,#0x01
+//     mov     r%1,a
+//} by {
+//     ;       Peephole 212    reduced add sequence to inc
+//     mov     r%1,_bp
+//     inc     r%1
+//}
 
 // reverts peephole 159? asx8051 cannot handle, too complex?
 replace {