Fixed mixed type compares and conversions
[fw/sdcc] / src / mcs51 / ralloc.c
index fb5f65c9904b6e9efa463a9bf8b94e0a7a176644..1f77e864200cfa9e3862790d601f0e34bb901603 100644 (file)
@@ -393,9 +393,11 @@ noOverLap (set * itmpStack, symbol * fsym)
   for (sym = setFirstItem (itmpStack); sym;
        sym = setNextItem (itmpStack))
     {
-      if (sym->liveTo > fsym->liveFrom)
-       return 0;
+           if (sym->liveFrom < fsym->liveTo &&
+               sym->liveTo   > fsym->liveTo) return 0;
 
+           if (sym->liveFrom < fsym->liveFrom &&
+               sym->liveTo > fsym->liveFrom) return 0;
     }
 
   return 1;
@@ -1176,7 +1178,7 @@ serialRegAssign (eBBlock ** ebbs, int count)
                 then mark it */
              if (POINTER_GET (ic) && IS_SYMOP (IC_LEFT (ic))
                  && getSize (OP_SYMBOL (IC_LEFT (ic))->type)
-                 <= PTRSIZE)
+                 <= (unsigned int) PTRSIZE)
                {
                  mcs51_ptrRegReq++;
                  ptrRegSet = 1;
@@ -1529,7 +1531,6 @@ farSpacePackable (iCode * ic)
      symbol on the right */
   for (dic = ic->prev; dic; dic = dic->prev)
     {
-
       /* if the definition is a call then no */
       if ((dic->op == CALL || dic->op == PCALL) &&
          IC_RESULT (dic)->key == IC_RIGHT (ic)->key)
@@ -1603,20 +1604,26 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
 
   /* if the true symbol is defined in far space or on stack
      then we should not since this will increase register pressure */
+#if 0
   if (isOperandInFarSpace (IC_RESULT (ic)))
     {
       if ((dic = farSpacePackable (ic)))
        goto pack;
       else
        return 0;
-
     }
+#else
+  if (isOperandInFarSpace(IC_RESULT(ic)) && !farSpacePackable(ic)) {
+    return 0;
+  }
+#endif
+
   /* find the definition of iTempNN scanning backwards if we find a 
      a use of the true symbol in before we find the definition then 
      we cannot */
   for (dic = ic->prev; dic; dic = dic->prev)
     {
-
+#if 0 // jwk 20010410
       /* if there is a function call and this is
          a parameter & not my parameter then don't pack it */
       if ((dic->op == CALL || dic->op == PCALL) &&
@@ -1626,6 +1633,14 @@ packRegsForAssign (iCode * ic, eBBlock * ebp)
          dic = NULL;
          break;
        }
+#else
+      /* if there is a function call then don't pack it */
+      if ((dic->op == CALL || dic->op == PCALL))
+       {
+         dic = NULL;
+         break;
+       }
+#endif
 
       if (SKIP_IC2 (dic))
        continue;
@@ -1812,6 +1827,7 @@ packRegsForSupport (iCode * ic, eBBlock * ebp)
   /* for the left & right operand :- look to see if the
      left was assigned a true symbol in far space in that
      case replace them */
+
   if (IS_ITEMP (IC_LEFT (ic)) &&
       OP_SYMBOL (IC_LEFT (ic))->liveTo <= ic->seq)
     {
@@ -1835,7 +1851,7 @@ packRegsForSupport (iCode * ic, eBBlock * ebp)
     }
 
   /* do the same for the right operand */
-right:
+ right:
   if (!change &&
       IS_ITEMP (IC_RIGHT (ic)) &&
       OP_SYMBOL (IC_RIGHT (ic))->liveTo <= ic->seq)
@@ -1889,7 +1905,7 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
 
   /* only upto 2 bytes since we cannot predict
      the usage of b, & acc */
-  if (getSize (operandType (op)) > (fReturnSize - 2) &&
+  if (getSize (operandType (op)) > (fReturnSizeMCS51 - 2) &&
       ic->op != RETURN &&
       ic->op != SEND &&
       !POINTER_SET (ic) &&
@@ -1911,7 +1927,7 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
   if (bitVectnBitsOn (OP_DEFS (op)) > 1)
     return NULL;               /* has more than one definition */
 
-  /* get the that definition */
+  /* get that definition */
   if (!(dic =
        hTabItemWithKey (iCodehTab,
                         bitVectFirstBit (OP_DEFS (op)))))
@@ -1997,6 +2013,12 @@ packRegsForOneuse (iCode * ic, operand * op, eBBlock * ebp)
        {
          return NULL;
        }
+      /* if left or right or result is on stack */
+      if (isOperandOnStack(IC_LEFT(dic)) ||
+         isOperandOnStack(IC_RIGHT(dic)) ||
+         isOperandOnStack(IC_RESULT(dic))) {
+       return NULL;
+      }
     }
 
   OP_SYMBOL (op)->ruonly = 1;
@@ -2011,23 +2033,18 @@ static bool
 isBitwiseOptimizable (iCode * ic)
 {
   sym_link *ltype = getSpec (operandType (IC_LEFT (ic)));
-  sym_link *rtype = getSpec (operandType (IC_RIGHT (ic)));
 
   /* bitwise operations are considered optimizable
      under the following conditions (Jean-Louis VERN) 
 
-     x & lit
      bit & bit
      bit & x
      bit ^ bit
      bit ^ x
-     x   ^ lit
-     x   | lit
      bit | bit
      bit | x
    */
-  if (IS_LITERAL (rtype) ||
-      (IS_BITVAR (ltype) && IN_BITSPACE (SPEC_OCLS (ltype))))
+  if ((IS_BITVAR (ltype) && IN_BITSPACE (SPEC_OCLS (ltype))))
     return TRUE;
   else
     return FALSE;
@@ -2173,7 +2190,8 @@ accuse:
 static void
 packForPush (iCode * ic, eBBlock * ebp)
 {
-  iCode *dic;
+  iCode *dic, *lic;
+  bitVect *dbv;
 
   if (ic->op != IPUSH || !IS_ITEMP (IC_LEFT (ic)))
     return;
@@ -2191,6 +2209,13 @@ packForPush (iCode * ic, eBBlock * ebp)
   if (dic->op != '=' || POINTER_SET (dic))
     return;
 
+  /* make sure the right side does not have any definitions
+     inbetween */
+  dbv = OP_DEFS(IC_RIGHT(dic));
+  for (lic = ic; lic && lic != dic ; lic = lic->prev) {
+    if (bitVectBitValue(dbv,lic->key)) 
+      return ;
+  }
   /* we now we know that it has one & only one def & use
      and the that the definition is an assignment */
   IC_LEFT (ic) = IC_RIGHT (dic);
@@ -2220,8 +2245,6 @@ packRegisters (eBBlock * ebp)
       /* TrueSym := iTempNN:1             */
       for (ic = ebp->sch; ic; ic = ic->next)
        {
-
-
          /* find assignment of the form TrueSym := iTempNN:1 */
          if (ic->op == '=' && !POINTER_SET (ic))
            change += packRegsForAssign (ic, ebp);
@@ -2233,7 +2256,6 @@ packRegisters (eBBlock * ebp)
 
   for (ic = ebp->sch; ic; ic = ic->next)
     {
-
       /* if this is an itemp & result of a address of a true sym 
          then mark this as rematerialisable   */
       if (ic->op == ADDRESS_OF &&
@@ -2273,8 +2295,6 @@ packRegisters (eBBlock * ebp)
           bitVectnBitsOn (OP_DEFS (IC_RESULT (ic))) == 1 &&
           IS_OP_LITERAL (IC_RIGHT (ic))))
        {
-
-         //int i = operandLitValue (IC_RIGHT (ic));
          OP_SYMBOL (IC_RESULT (ic))->remat = 1;
          OP_SYMBOL (IC_RESULT (ic))->rematiCode = ic;
          OP_SYMBOL (IC_RESULT (ic))->usl.spillLoc = NULL;
@@ -2315,15 +2335,11 @@ packRegisters (eBBlock * ebp)
          is defined in the previous instruction then
          mark the itemp as a conditional */
       if ((IS_CONDITIONAL (ic) ||
-          ((ic->op == BITWISEAND ||
-            ic->op == '|' ||
-            ic->op == '^') &&
-           isBitwiseOptimizable (ic))) &&
+          (IS_BITWISE_OP(ic) && isBitwiseOptimizable (ic))) &&
          ic->next && ic->next->op == IFX &&
          isOperandEqual (IC_RESULT (ic), IC_COND (ic->next)) &&
          OP_SYMBOL (IC_RESULT (ic))->liveTo <= ic->next->seq)
        {
-
          OP_SYMBOL (IC_RESULT (ic))->regType = REG_CND;
          continue;
        }
@@ -2336,8 +2352,14 @@ packRegisters (eBBlock * ebp)
          can be eliminated for return statements */
       if ((ic->op == RETURN || ic->op == SEND) &&
          !isOperandInFarSpace (IC_LEFT (ic)) &&
-         options.model == MODEL_SMALL)
-       packRegsForOneuse (ic, IC_LEFT (ic), ebp);
+         options.model == MODEL_SMALL) {
+       if (0 && options.stackAuto) {
+         /* we should check here if acc will be clobbered for stack
+            offset calculations */
+       } else {
+         packRegsForOneuse (ic, IC_LEFT (ic), ebp);
+       }
+      }
 
       /* if pointer set & left has a size more than
          one and right is not in far space */
@@ -2439,7 +2461,6 @@ packRegisters (eBBlock * ebp)
          getSize (operandType (IC_RESULT (ic))) <= 2)
 
        packRegsForAccUse (ic);
-
     }
 }
 
@@ -2501,7 +2522,7 @@ mcs51_assignRegisters (eBBlock ** ebbs, int count)
   if (options.dump_rassgn)
     {
       dumpEbbsToFileExt (".dumprassgn", ebbs, count);
-      dumpLiveRanges (".lrange", liveRanges);
+      dumpLiveRanges (".dumplrange", liveRanges);
     }
 
   /* do the overlaysegment stuff SDCCmem.c */