]> git.gag.com Git - fw/sdcc/blobdiff - src/SDCCcse.c
IC_RESULT needs to be a symbol
[fw/sdcc] / src / SDCCcse.c
index a3c8a027c5cd111a077f4a7678e79691ef40f4ad..af3d2ce94a0372abbfc4b8bcac47fcb002eecb51 100644 (file)
@@ -118,7 +118,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset)
 {
   iCode *lic;
 
-  LRH(printf ("replaceAllSymBySym: from %s to %s\n", OP_SYMBOL(from)->name, OP_SYMBOL(to)->name));
+  LRH(printf ("replaceAllSymBySym: from %s to %s\n", 
+             OP_SYMBOL(from)->name, 
+             IS_SYMOP(to) ? OP_SYMBOL(to)->name) : "!SYM");
   for (lic = ic; lic; lic = lic->next)
     {
       int siaddr;
@@ -156,7 +158,8 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset)
          continue;
        }
 
-      if (IC_RESULT (lic) && IC_RESULT (lic)->key == from->key)
+      if (IS_SYMOP(to) && 
+         IC_RESULT (lic) && IC_RESULT (lic)->key == from->key)
        {
          /* maintain du chains */
          if (POINTER_SET (lic))
@@ -334,6 +337,7 @@ DEFSETFUNC (findCheaperOp)
   if ((*opp) && 
       (isOperandLiteral(*opp) || !checkSign || 
        (checkSign &&
+       IS_SPEC(operandType (cop)) && IS_SPEC(operandType (*opp)) &&
        (SPEC_USIGN(operandType (cop))==SPEC_USIGN(operandType (*opp)) &&
         (SPEC_LONG(operandType (cop))==SPEC_LONG(operandType (*opp)))))))
       {
@@ -358,6 +362,28 @@ DEFSETFUNC (findCheaperOp)
          *opp = operandFromOperand (*opp);
          (*opp)->isaddr = cop->isaddr;
        }
+         
+      if (IS_SPEC(operandType (cop)) && IS_SPEC(operandType (*opp)) &&
+         SPEC_NOUN(operandType(cop)) != SPEC_NOUN(operandType(*opp)))
+       {
+           // special case: we can make an unsigned char literal 
+           // into an int literal with no cost.
+           if (isOperandLiteral(*opp)
+            && SPEC_NOUN(operandType(*opp)) == V_CHAR
+            && SPEC_NOUN(operandType(cop)) == V_INT)
+           {
+               *opp = operandFromOperand (*opp);
+               SPEC_NOUN(operandType(*opp)) = V_INT;
+           }
+           else
+           {
+               // No clue...
+               *opp = NULL;
+               return 0;
+           }
+           
+        }
+         
       LRH(printf ("findCheaperOp: %s < %s\n",\
              IS_SYMOP((*opp)) ? OP_SYMBOL((*opp))->name : "!SYM",\
              OP_SYMBOL(cop)->name));