From df600563e3005614c5ab09aab6ba39218bbd3191 Mon Sep 17 00:00:00 2001 From: maartenbrock Date: Thu, 27 Oct 2005 14:21:46 +0000 Subject: [PATCH] * 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 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3913 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 10 ++++++++- src/mcs51/peeph.def | 29 ++++++++++++++++++++++++- src/mcs51/ralloc.c | 31 ++++++++++++++++++++------- support/regression/tests/bug1337835.c | 28 ++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 support/regression/tests/bug1337835.c diff --git a/ChangeLog b/ChangeLog index 4c4acb9e..ca4c42a5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-10-27 Maarten Brock + + * 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 * 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 - + 2005-10-26 Bernhard Held * src/mcs51/gen.c (genMinus): fixed bug 1270906: reverse subtraction, diff --git a/src/mcs51/peeph.def b/src/mcs51/peeph.def index 77930077..d4bf76ca 100644 --- a/src/mcs51/peeph.def +++ b/src/mcs51/peeph.def @@ -44,7 +44,7 @@ replace { 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 @@ -4475,6 +4475,33 @@ replace { ; 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: diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index e983d48a..82ff7c8d 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -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 */ /*-----------------------------------------------------------------*/ @@ -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) @@ -369,7 +378,7 @@ leastUsedLR (set * sset) { /* 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; @@ -645,10 +654,20 @@ selectSpil (iCode * ic, eBBlock * ebp, symbol * forSym) /* 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); } @@ -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) { - /* 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))) { - 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))) { - 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))) { - /* 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 index 00000000..e88ea8a4 --- /dev/null +++ b/support/regression/tests/bug1337835.c @@ -0,0 +1,28 @@ +/* + bug1057979.c +*/ + +#include +#include + +#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 ); +} -- 2.39.5