From: maartenbrock Date: Thu, 6 Apr 2006 15:24:25 +0000 (+0000) Subject: * src/SDCCpeeph.c (labelIsReturnOnly): fixed bug 1464657 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=21c01843f4c17bdcea28995bd540efe72faf8a12;p=fw%2Fsdcc * src/SDCCpeeph.c (labelIsReturnOnly): fixed bug 1464657 * src/mcs51/gen.c (genJumpTab): fixed bug in medium model * support/regression/bug1464657.c: added, new test git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4081 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index a46a5ca9..9c8c7f5f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-04-06 Maarten Brock + + * src/SDCCpeeph.c (labelIsReturnOnly): fixed bug 1464657 + * src/mcs51/gen.c (genJumpTab): fixed bug in medium model + * support/regression/bug1464657.c: added, new test + 2006-04-05 Maarten Brock * src/SDCCmain.c (preProcess): implemented RFE 1449908, define SDCC as the diff --git a/src/SDCCpeeph.c b/src/SDCCpeeph.c index 3a12a74c..c38627dc 100644 --- a/src/SDCCpeeph.c +++ b/src/SDCCpeeph.c @@ -238,6 +238,10 @@ FBYNAME (labelIsReturnOnly) int len; char * retInst; + /* Don't optimize jumps in a jump table; a more generic test */ + if (currPl->ic && currPl->ic->op == JUMPTABLE) + return FALSE; + label = hTabItemWithKey (vars, 5); if (!label) return FALSE; len = strlen(label); diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 85405e07..e8b5afab 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -10836,15 +10836,24 @@ genJumpTab (iCode * ic) /* this algorithm needs 9 cycles and 7 + 3*n bytes if the switch argument is in a register. (8 cycles and 6+2*n bytes if peepholes can change ljmp to sjmp) */ - /* (MB) What if peephole converts ljmp to sjmp or ret ??? - How will multiply by three be updated ???*/ + /* Peephole may not convert ljmp to sjmp or ret + labelIsReturnOnly & labelInRange must check + currPl->ic->op != JUMPTABLE */ aopOp (IC_JTCOND (ic), ic, FALSE); /* get the condition into accumulator */ l = aopGet (IC_JTCOND (ic), 0, FALSE, FALSE); MOVA (l); /* multiply by three */ - emitcode ("add", "a,acc"); - emitcode ("add", "a,%s", aopGet (IC_JTCOND (ic), 0, FALSE, FALSE)); + if (aopGetUsesAcc (IC_JTCOND (ic), 0)) + { + emitcode ("mov", "b,#3"); + emitcode ("mul", "ab"); + } + else + { + emitcode ("add", "a,acc"); + emitcode ("add", "a,%s", aopGet (IC_JTCOND (ic), 0, FALSE, FALSE)); + } freeAsmop (IC_JTCOND (ic), NULL, ic, TRUE); jtab = newiTempLabel (NULL); diff --git a/support/regression/tests/bug1464657.c b/support/regression/tests/bug1464657.c new file mode 100644 index 00000000..b32bef44 --- /dev/null +++ b/support/regression/tests/bug1464657.c @@ -0,0 +1,70 @@ +/* + bug1464657.c +*/ + +#include + +static void f1(void) +{ +} + +static short f2(void) +{ + return 0; +} + +static unsigned char f3(unsigned char a) +{ + return a+5; +} + +unsigned char var; + +void f() +{ + switch (var) { + case 0: + f1(); + break; + case 1: + f1(); + break; + case 2: + var++; + f1(); + break; + case 4: + f1(); + break; + case 5: + break; + case 7: + f1(); + break; + case 6: + f1(); + break; + case 8: + f1(); + break; + case 9: + f1(); + break; + case 12: + { + unsigned char nc; + unsigned short b = f2(); + unsigned char nb = f3(b); + var = f3(b); + nc = f3(nb); + } + break; + } +} + +void test_Peephole251() +{ + var = 12; + f(); + ASSERT (var==5); +}