Applied patch #2762516
[fw/sdcc] / src / z80 / ralloc.c
index b9cba56cbc94373a0853b816afb3408fdd98fb21..b738cda597d8c35e7774708fee738e50e43811f8 100644 (file)
@@ -53,7 +53,7 @@ enum
     DISABLE_PACK_ACC = 0,
     DISABLE_PACK_ASSIGN = 0,
     DISABLE_PACK_ONE_USE = 0,
-    DISABLE_PACK_HL = 1,
+    DISABLE_PACK_HL = 0,
     DISABLE_PACK_IY = 0
   };
 
@@ -146,7 +146,7 @@ allocReg (short type)
             {
               currFunc->regsUsed = bitVectSetBit (currFunc->regsUsed, i);
             }
-          D (D_ALLOC, ("allocReg: alloced %p\n", &regsZ80[i]));
+          D (D_ALLOC, ("allocReg: alloced %s\n", regsZ80[i].name));
           return &regsZ80[i];
         }
     }
@@ -1039,11 +1039,11 @@ tryAllocatingRegPair (symbol * sym)
               currFunc->regsUsed =
                 bitVectSetBit (currFunc->regsUsed, i + 1);
             }
-          D (D_ALLOC, ("tryAllocRegPair: succeded for sym %p\n", sym));
+          D (D_ALLOC, ("tryAllocatingRegPair: succeded for sym %p\n", sym));
           return TRUE;
         }
     }
-  D (D_ALLOC, ("tryAllocRegPair: failed on sym %p\n", sym));
+  D (D_ALLOC, ("tryAllocatingRegPair: failed on sym %p\n", sym));
   return FALSE;
 }
 
@@ -1234,6 +1234,14 @@ serialRegAssign (eBBlock ** ebbs, int count)
                             break;
                         }
                     }
+                  /* Make sure we didn't allocate a register pair with bytes swapped */
+                  if(sym->nRegs == 2 && sym->regs[0] == sym->regs[1] + 1 && sym->regs[0] != &regsZ80[2])
+                  {
+                       freeReg(sym->regs[0]);
+                       freeReg(sym->regs[1]);
+                       if(!tryAllocatingRegPair(sym))
+                               wassertl(0, "Failed to swap register pair bytes back.");
+                  }
                 }
               /* if it shares registers with operands make sure
                  that they are in the same position */
@@ -2470,14 +2478,18 @@ packRegsForHLUse3 (iCode * lic, operand * op, eBBlock * ebp)
       if (ic->op == LEFT_OP && isOperandLiteral (IC_RIGHT (ic)))
         continue;
 
+      if (ic->op == '+' &&
+         (isOperandEqual (op, IC_LEFT (ic)) || isOperandEqual (op, IC_RIGHT (ic))))
+        continue;
+
       if ((ic->op == '=' && !POINTER_SET(ic)) ||
           ic->op == UNARYMINUS ||
-          ic->op == '+' ||
           ic->op == '-' ||
           ic->op == '>' ||
           ic->op == '<' ||
           ic->op == EQ_OP ||
-          0)
+          (ic->op == '+' && getSize (operandType (IC_RESULT (ic))) == 1))
+          /* 16 bit addition uses add hl, rr */
         continue;
 
       if (ic->op == '*' && isOperandEqual (op, IC_LEFT (ic)))
@@ -2894,7 +2906,7 @@ packRegsForAccUse2 (iCode * ic)
                 D (D_ACCUSE2, ("  + Dropping as last in list and next doesn't start a block\n"));
                 return;
               }
-          } /*This caused bug #1292721 */
+          } //This caused bug #1292721 */
         else if (scan->next == NULL)
           {
             D (D_ACCUSE2, ("  + Dropping as hit the end of the list\n"));