* src/mcs51/ralloc.c (bitType): added to detect bit variables,
authormaartenbrock <maartenbrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 27 Oct 2005 14:21:46 +0000 (14:21 +0000)
committermaartenbrock <maartenbrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 27 Oct 2005 14:21:46 +0000 (14:21 +0000)
  (selectSpil): fixed bug 1337835 by not spilling bit variables
* support/regression/tests/bug1337835.c: added test for this bug
* src/mcs51/peeph.def: restart after rule 3.c,
  addded rules 263.x to optimize loading constants

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

ChangeLog
src/mcs51/peeph.def
src/mcs51/ralloc.c
support/regression/tests/bug1337835.c [new file with mode: 0644]

index 4c4acb9eb2ed6e99fd542f5f8e5479a4d6796d40..ca4c42a553f855e759762645fa29df75d864be00 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-10-27 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * src/mcs51/ralloc.c (bitType): added to detect bit variables,
+         (selectSpil): fixed bug 1337835 by not spilling bit variables
+       * support/regression/tests/bug1337835.c: added test for this bug
+       * src/mcs51/peeph.def: restart after rule 3.c,
+         addded rules 263.x to optimize loading constants
+
 2005-10-26 Raphael Neider <rneider AT web.de>
 
        * src/SDCCsymt.c (compStructSize): allow signed bitfields for PIC ports
 2005-10-26 Raphael Neider <rneider AT web.de>
 
        * src/SDCCsymt.c (compStructSize): allow signed bitfields for PIC ports
@@ -8,7 +16,7 @@
        * src/pic16/glue.c (pic16emitStaticSeg): fixed(?) handling of fixed
          extern variables, added verbose error message
        * device/include/pic16/{string.h,errno.h}: added #pragma library c
        * src/pic16/glue.c (pic16emitStaticSeg): fixed(?) handling of fixed
          extern variables, added verbose error message
        * device/include/pic16/{string.h,errno.h}: added #pragma library c
-       
+
 2005-10-26 Bernhard Held <bernhard AT bernhardheld.de>
 
        * src/mcs51/gen.c (genMinus): fixed bug 1270906: reverse subtraction,
 2005-10-26 Bernhard Held <bernhard AT bernhardheld.de>
 
        * src/mcs51/gen.c (genMinus): fixed bug 1270906: reverse subtraction,
index 779300776f08b72477e860e221eff26109f4e7e0..d4bf76ca16cd96bb9d3895c95a650e6c7c84eaf8 100644 (file)
@@ -44,7 +44,7 @@ replace {
        mov     %1,a
 }
 
        mov     %1,a
 }
 
-replace {
+replace restart {
 // saving 1 byte, loosing 1 cycle but maybe allowing peephole 3.b to start
        mov     %1,#0x00
        mov     %2,#0x00
 // saving 1 byte, loosing 1 cycle but maybe allowing peephole 3.b to start
        mov     %1,#0x00
        mov     %2,#0x00
@@ -4475,6 +4475,33 @@ replace {
        ;       Peephole 262    removed redundant cpl c
 }
 
        ;       Peephole 262    removed redundant cpl c
 }
 
+replace {
+       mov     %1,#%2
+       inc     %1
+       inc     %1
+       inc     %1
+} by {
+       ;       Peephole 263.a  optimized loading const
+       mov     %1,#(%2 + 3)
+}
+
+replace {
+       mov     %1,#%2
+       inc     %1
+       inc     %1
+} by {
+       ;       Peephole 263.b  optimized loading const
+       mov     %1,#(%2 + 2)
+}
+
+replace {
+       mov     %1,#%2
+       inc     %1
+} by {
+       ;       Peephole 263.c  optimized loading const
+       mov     %1,#(%2 + 1)
+}
+
 // should be one of the last peepholes
 replace{
 %1:
 // should be one of the last peepholes
 replace{
 %1:
index e983d48ae692bc768447ed980d691629a9075036..82ff7c8dc70c3ae045f188f36262a9e536ddd417 100644 (file)
@@ -247,6 +247,15 @@ computeSpillable (iCode * ic)
 
 }
 
 
 }
 
+/*-----------------------------------------------------------------*/
+/* bitType - will return 1 if the symbol has type REG_BIT          */
+/*-----------------------------------------------------------------*/
+static int
+bitType (symbol * sym, eBBlock * ebp, iCode * ic)
+{
+  return (sym->regType == REG_BIT ? 1 : 0);
+}
+
 /*-----------------------------------------------------------------*/
 /* noSpilLoc - return true if a variable has no spil location      */
 /*-----------------------------------------------------------------*/
 /*-----------------------------------------------------------------*/
 /* noSpilLoc - return true if a variable has no spil location      */
 /*-----------------------------------------------------------------*/
@@ -266,7 +275,7 @@ hasSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
 }
 
 /*-----------------------------------------------------------------*/
 }
 
 /*-----------------------------------------------------------------*/
-/* directSpilLoc - will return 1 if the splilocation is in direct  */
+/* directSpilLoc - will return 1 if the spillocation is in direct  */
 /*-----------------------------------------------------------------*/
 static int
 directSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
 /*-----------------------------------------------------------------*/
 static int
 directSpilLoc (symbol * sym, eBBlock * ebp, iCode * ic)
@@ -369,7 +378,7 @@ leastUsedLR (set * sset)
     {
 
       /* if usage is the same then prefer
     {
 
       /* if usage is the same then prefer
-         the spill the smaller of the two */
+         to spill the smaller of the two */
       if (lsym->used == sym->used)
         if (getSize (lsym->type) < getSize (sym->type))
           sym = lsym;
       if (lsym->used == sym->used)
         if (getSize (lsym->type) < getSize (sym->type))
           sym = lsym;
@@ -645,10 +654,20 @@ selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
   /* get the spillable live ranges */
   lrcs = computeSpillable (ic);
 
   /* get the spillable live ranges */
   lrcs = computeSpillable (ic);
 
-  /* get all live ranges that are rematerizable */
-  if ((selectS = liveRangesWith (lrcs, rematable, ebp, ic)))
+  /* remove incompatible registers */
+  if ((forSym->regType == REG_PTR) || (forSym->regType == REG_GPR))
+    {
+      selectS = liveRangesWith (lrcs, bitType, ebp, ic);
+      
+      for (sym = setFirstItem (selectS); sym; sym = setNextItem (selectS))
     {
     {
+          bitVectUnSetBit (lrcs, sym->key);
+        }
+    }
 
 
+  /* get all live ranges that are rematerializable */
+  if ((selectS = liveRangesWith (lrcs, rematable, ebp, ic)))
+    {
       /* return the least used of these */
       return leastUsedLR (selectS);
     }
       /* return the least used of these */
       return leastUsedLR (selectS);
     }
@@ -670,7 +689,6 @@ selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
   /* if the symbol is local to the block then */
   if (forSym->liveTo < ebp->lSeq)
     {
   /* if the symbol is local to the block then */
   if (forSym->liveTo < ebp->lSeq)
     {
-
       /* check if there are any live ranges allocated
          to registers that are not used in this block */
       if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInBlock, ebp, ic)))
       /* check if there are any live ranges allocated
          to registers that are not used in this block */
       if (!_G.blockSpil && (selectS = liveRangesWith (lrcs, notUsedInBlock, ebp, ic)))
@@ -707,7 +725,6 @@ selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
   /* find live ranges with spillocation && not used as pointers */
   if ((selectS = liveRangesWith (lrcs, hasSpilLocnoUptr, ebp, ic)))
     {
   /* find live ranges with spillocation && not used as pointers */
   if ((selectS = liveRangesWith (lrcs, hasSpilLocnoUptr, ebp, ic)))
     {
-
       sym = leastUsedLR (selectS);
       /* mark this as allocation required */
       sym->usl.spillLoc->allocreq++;
       sym = leastUsedLR (selectS);
       /* mark this as allocation required */
       sym->usl.spillLoc->allocreq++;
@@ -717,7 +734,6 @@ selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
   /* find live ranges with spillocation */
   if ((selectS = liveRangesWith (lrcs, hasSpilLoc, ebp, ic)))
     {
   /* find live ranges with spillocation */
   if ((selectS = liveRangesWith (lrcs, hasSpilLoc, ebp, ic)))
     {
-
       sym = leastUsedLR (selectS);
       sym->usl.spillLoc->allocreq++;
       return sym;
       sym = leastUsedLR (selectS);
       sym->usl.spillLoc->allocreq++;
       return sym;
@@ -728,7 +744,6 @@ selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym)
      used ofcourse */
   if ((selectS = liveRangesWith (lrcs, noSpilLoc, ebp, ic)))
     {
      used ofcourse */
   if ((selectS = liveRangesWith (lrcs, noSpilLoc, ebp, ic)))
     {
-
       /* return a created spil location */
       sym = createStackSpil (leastUsedLR (selectS));
       sym->usl.spillLoc->allocreq++;
       /* return a created spil location */
       sym = createStackSpil (leastUsedLR (selectS));
       sym->usl.spillLoc->allocreq++;
diff --git a/support/regression/tests/bug1337835.c b/support/regression/tests/bug1337835.c
new file mode 100644 (file)
index 0000000..e88ea8a
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+   bug1057979.c
+*/
+
+#include <testfwk.h>
+#include <stdbool.h>
+
+#ifndef BOOL
+#define BOOL bool
+#endif
+
+char e;
+
+void foo (unsigned long ul, BOOL b, char c) REENTRANT
+{
+       if (b && (long) ul < 0)
+               e = 0;
+       if (ul && b && c)
+               e = 1;
+}
+
+void
+test_1337835(void)
+{
+  e = 2;
+  foo(0, 1, 0);
+  ASSERT( e == 2 );
+}