fixed bug #460088
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 5 Apr 2003 15:17:31 +0000 (15:17 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 5 Apr 2003 15:17:31 +0000 (15:17 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2482 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCcse.c
src/SDCCcse.h
src/SDCCopt.c

index bc784a21a45aad48e0508589a156d4f8fb7507c4..ea64e30c70d5ce77e09ed2c851273144d20826c3 100644 (file)
@@ -1401,7 +1401,7 @@ cseBBlock (eBBlock * ebb, int computeOnly,
 
   /* if this block is not reachable */
   if (ebb->noPath)
-    return change;
+    return 0;
 
   /* set of common subexpressions */
   cseSet = setFromSet (ebb->inExprs);
@@ -1521,9 +1521,11 @@ cseBBlock (eBBlock * ebb, int computeOnly,
       if (SKIP_IC (ic))
        continue;
 
-      /* do some algebraic optimizations if possible */
-      algebraicOpts (ic);
-      while (constFold (ic, cseSet));
+      if (!computeOnly) {
+       /* do some algebraic optimizations if possible */
+       algebraicOpts (ic);
+       while (constFold (ic, cseSet));
+      }
 
       /* small klugde */
       if (POINTER_GET (ic) && !IS_PTR (operandType (IC_LEFT (ic))))
@@ -1541,7 +1543,7 @@ cseBBlock (eBBlock * ebb, int computeOnly,
 
       /* if this is a condition statment then */
       /* check if the condition can be replaced */
-      if (ic->op == IFX)
+      if (!computeOnly && ic->op == IFX)
        {
          ifxOptimize (ic, cseSet, computeOnly,
                       ebb, &change,
@@ -1551,7 +1553,7 @@ cseBBlock (eBBlock * ebb, int computeOnly,
 
       /* if the assignment & result is a temp */
       /* see if we can replace it             */
-      if (ic->op == '=')
+      if (!computeOnly && ic->op == '=')
        {
 
          /* update the spill location for this */
@@ -1635,7 +1637,7 @@ cseBBlock (eBBlock * ebb, int computeOnly,
          while (constFold (ic, cseSet));
        }
 
-      /* if after all this it becomes a assignment to self
+      /* if after all this it becomes an assignment to self
          then delete it and continue */
       if (ASSIGNMENT_TO_SELF (ic))
        {
@@ -1797,7 +1799,7 @@ cseBBlock (eBBlock * ebb, int computeOnly,
 /* cseAllBlocks - will sequentially go thru & do cse for all blocks */
 /*-----------------------------------------------------------------*/
 int 
-cseAllBlocks (eBBlock ** ebbs, int count)
+cseAllBlocks (eBBlock ** ebbs, int count, int computeOnly)
 {
   int i;
   int change = 0;
@@ -1805,7 +1807,7 @@ cseAllBlocks (eBBlock ** ebbs, int count)
   /* if optimization turned off */
 
   for (i = 0; i < count; i++)
-    change += cseBBlock (ebbs[i], FALSE, ebbs, count);
+    change += cseBBlock (ebbs[i], computeOnly, ebbs, count);
 
   return change;
 }
index f2770b7682ef25028a73f11cbde71f23ac5194fa..b9532c0b8728ce4dbb6ad69b05889f1236d55dc5 100644 (file)
@@ -51,7 +51,7 @@ DEFSETFUNC (findPrevIc);
 DEFSETFUNC (ifOperandsHave);
 DEFSETFUNC (findCheaperOp);
 int cseBBlock (eBBlock *, int, eBBlock **, int);
-int cseAllBlocks (eBBlock **, int);
+int cseAllBlocks (eBBlock **, int, int computeOnly);
 void ifxOptimize (iCode *, set *, int, eBBlock *, int *, eBBlock **, int);
 void unsetDefsAndUses (iCode *);
 void updateSpillLocation (iCode * ic,int);
index 25ca302e7583af2e80a0b09587b9cba3fa6578c7..31d2858df3b21148facb6f5c7dfd22d7cc2fd64e 100644 (file)
@@ -695,6 +695,7 @@ killDeadCode (eBBlock ** ebbs, int count)
              /* kill this one if required */
              if (kill)
                {
+                 printf ("kill ic %d\n", ic->key);
                  change = 1;
                  gchange++;
                  /* eliminate this */
@@ -830,7 +831,7 @@ eBBlockFromiCode (iCode * ic)
     dumpEbbsToFileExt (DUMP_RAW1, ebbs, count);
 
   /* do common subexpression elimination for each block */
-  change = cseAllBlocks (ebbs, saveCount);
+  change = cseAllBlocks (ebbs, saveCount, FALSE);
 
   /* dumpraw if asked for */
   if (options.dump_raw)
@@ -846,10 +847,15 @@ eBBlockFromiCode (iCode * ic)
   /* global common subexpression elimination  */
   if (optimize.global_cse)
     {
-      change += cseAllBlocks (ebbs, saveCount);
+      change += cseAllBlocks (ebbs, saveCount, TRUE);
       if (options.dump_gcse)
        dumpEbbsToFileExt (DUMP_GCSE, ebbs, saveCount);
     }
+  else
+    {
+      // compute the dataflow only
+      assert(cseAllBlocks (ebbs, saveCount, FALSE)==0);
+    }
   /* kill dead code */
   kchange = killDeadCode (ebbs, saveCount);
 
@@ -871,7 +877,7 @@ eBBlockFromiCode (iCode * ic)
   if (lchange || kchange)
     {
       computeDataFlow (ebbs, saveCount);
-      change += cseAllBlocks (ebbs, saveCount);
+      change += cseAllBlocks (ebbs, saveCount, TRUE);
       if (options.dump_loop)
        dumpEbbsToFileExt (DUMP_LOOPG, ebbs, count);