* src/SDCCpeeph.c (labelIsReturnOnly): fixed bug 1464657
authormaartenbrock <maartenbrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 6 Apr 2006 15:24:25 +0000 (15:24 +0000)
committermaartenbrock <maartenbrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 6 Apr 2006 15:24:25 +0000 (15:24 +0000)
* 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

ChangeLog
src/SDCCpeeph.c
src/mcs51/gen.c
support/regression/tests/bug1464657.c [new file with mode: 0644]

index a46a5ca918bac47cb45888ee0f1c66bad5d12926..9c8c7f5fba3758de891c4970a81383026155a6f7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+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
index 3a12a74cc57a7be26ffce2c21df4ec3309075703..c38627dc2a7e76bfb81779ad823aead57d3c2198 100644 (file)
@@ -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);
index 85405e07018adae484e6d4a6afd7ffb9d6f37c17..e8b5afaba5abf93112addd9f882e2f8953a2e29e 100644 (file)
@@ -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 (file)
index 0000000..b32bef4
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+   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);
+}