* src/SDCCloop.c (loopInvariants): fixed bug #1234048
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 23 Jul 2005 03:31:19 +0000 (03:31 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 23 Jul 2005 03:31:19 +0000 (03:31 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3810 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCCloop.c

index 8f6fbbe93d3edb763b7714edd08f0114a0590a5b..395becbec7747368ac2af6e95e8b436e83b17357 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2005-07-23 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
+
+       * src/SDCCloop.c (loopInvariants): fixed bug #1234048
+
 2005-07-22 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
 
        * src/hc08/gen.c (genMinus): fixed bug #1241835,
index 0ecfe9446497fce864216199db13f10af98874ec..f12fe1b35f4065a1b1bc699567615304875a88a9 100644 (file)
@@ -569,6 +569,10 @@ loopInvariants (region * theLoop, ebbIndex * ebbi)
              for (sBlock = setFirstItem (lSet); sBlock;
                   sBlock = setNextItem (lSet))
                {
+                  iCode *ic2;
+                  int used;
+                  int defDominates;
+
                  /* if this is the block make sure the definition */
                  /* reaches the end of the block */
                  if (sBlock == lBlock)
@@ -579,25 +583,48 @@ loopInvariants (region * theLoop, ebbIndex * ebbi)
                  else if (bitVectBitsInCommon (sBlock->defSet, OP_DEFS (IC_RESULT (ic))))
                    break;
 
-                  if (IC_RESULT(ic))
+                  /* Check that this definition is not assigned */
+                  /* any other value in this block. Also check */
+                  /* that any usage in the block is dominated by */
+                  /* by this definition. */
+                  defDominates = bitVectBitValue (sBlock->domVect, lBlock->bbnum);
+                  used = 0;
+                  for (ic2 = sBlock->sch; ic2; ic2 = ic2->next)
                     {
-                      iCode *ic2;
-                      /* check that this definition is not assigned */
-                      /* any other value in this block */
-                      for (ic2 = sBlock->sch; ic2; ic2 = ic2->next)
+                      if (ic2->op == IFX)
+                        {
+                          if (isOperandEqual (IC_RESULT (ic), IC_COND (ic2)))
+                            used = 1;
+                        }
+                      else if (ic2->op == JUMPTABLE)
                         {
+                          if (isOperandEqual (IC_RESULT (ic), IC_JTCOND (ic2)))
+                            used = 1;
+                        }
+                      else
+                        {
+                          if (IC_LEFT (ic2) && isOperandEqual (IC_RESULT (ic), IC_LEFT (ic2)))
+                            used = 1;
+                          if (IC_RIGHT (ic2) && isOperandEqual (IC_RESULT (ic), IC_RIGHT (ic2)))
+                            used = 1;
                           if ((ic != ic2) && (isOperandEqual(IC_RESULT(ic), IC_RESULT(ic2))))
                             break;
+                          /* If used before this definition, might not be invariant */
+                          if ((ic == ic2) && used)
+                            break;
                         }
-                      if (ic2) /* found another definition */
+                      if (used && !defDominates)
                         break;
                     }
+                  if (ic2) /* found another definition or a usage before the definition */
+                    break;
                }
 
              if (sBlock)
                continue;       /* another definition present in the block */
+              
 
-             /* now check if it exists in the in of this block */
+              /* now check if it exists in the in of this block */
              /* if not then it was killed before this instruction */
              if (!bitVectBitValue (lBlock->inDefs, ic->key))
                continue;