* 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
+2006-04-06 Maarten Brock <sourceforge.brock AT dse.nl>
+
+ * 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 <sourceforge.brock AT dse.nl>
* src/SDCCmain.c (preProcess): implemented RFE 1449908, define SDCC as the
2006-04-05 Maarten Brock <sourceforge.brock AT dse.nl>
* src/SDCCmain.c (preProcess): implemented RFE 1449908, define SDCC as the
+ /* 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);
label = hTabItemWithKey (vars, 5);
if (!label) return FALSE;
len = strlen(label);
/* 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) */
/* 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 */
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);
freeAsmop (IC_JTCOND (ic), NULL, ic, TRUE);
jtab = newiTempLabel (NULL);
--- /dev/null
+/*
+ bug1464657.c
+*/
+
+#include <testfwk.h>
+
+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);
+}