Fixed a loop invariant bug & a casting bug
[fw/sdcc] / src / ds390 / ralloc.c
index 1e6e8dc8c0eec1559f514c27ed5a2bc24dd36df6..9d12c973d1c0609d175dc38cb595f9352daa03de 100644 (file)
@@ -36,8 +36,6 @@
 /* since the pack the registers depending strictly on the MCU      */
 /*-----------------------------------------------------------------*/
 
-extern void gen390Code(iCode *);
-
 /* Global data */
 static struct {
     bitVect *spiltSet;
@@ -629,11 +627,13 @@ static symbol *selectSpil (iCode *ic, eBBlock *ebp, symbol *forSym)
           used in the remainder of the block */
        if (!_G.blockSpil && (selectS = liveRangesWith(lrcs,notUsedInRemaining,ebp,ic))) {
            sym = leastUsedLR (selectS);
-           if (!sym->remat) {
-               sym->remainSpil = 1;
-               _G.blockSpil++;
+           if (sym != forSym) {
+               if (!sym->remat) {
+                   sym->remainSpil = 1;
+                   _G.blockSpil++;
+               }
+               return sym;
            }
-           return sym;
        }
     }   
 
@@ -870,7 +870,7 @@ static void deassignLRs (iCode *ic, eBBlock *ebp)
                  sym->nRegs) >= result->nRegs)
                ) {
                
-               for (i = 0 ; i < max(sym->nRegs,result->nRegs) ; i++)
+               for (i = 0 ; i < result->nRegs ; i++)
                    if (i < sym->nRegs )
                        result->regs[i] = sym->regs[i] ;
                    else
@@ -2098,7 +2098,7 @@ static void packRegisters (eBBlock *ebp)
              bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) == 1 &&
             IS_OP_LITERAL(IC_RIGHT(ic))) ) {
 
-           int i = operandLitValue(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;
@@ -2191,7 +2191,8 @@ static void packRegisters (eBBlock *ebp)
            link *toType = operandType(IC_LEFT(ic));
 
            if (IS_INTEGRAL(fromType) && IS_INTEGRAL(toType) &&
-               getSize(fromType) != getSize(toType) ) {
+               getSize(fromType) != getSize(toType) && 
+               SPEC_USIGN(fromType) == SPEC_USIGN(toType)) {
 
                iCode *dic = packRegsForOneuse(ic,IC_RIGHT(ic),ebp);
                if (dic) {
@@ -2311,6 +2312,9 @@ void ds390_assignRegisters (eBBlock **ebbs, int count)
     if (options.dump_rassgn)
        dumpEbbsToFileExt(".dumprassgn",ebbs,count);
 
+    /* do the overlaysegment stuff SDCCmem.c */
+    doOverlays(ebbs,count);
+
     /* now get back the chain */
     ic = iCodeLabelOptimize(iCodeFromeBBlock (ebbs,count));