Added some pointer pre inc/dec optimization
[fw/sdcc] / src / SDCCcse.c
index 04e6337f071d2010121341b95dfb65ba9a04be64..52efaef7754eb3b3381cc4e22c0572234d8074a5 100644 (file)
@@ -67,6 +67,8 @@ int pcseDef (void *item, va_list ap)
     cseDef *cdp = item;
     iCodeTable *icTab ;
 
+    (void)ap;
+    
     if (!cdp->sym)
        fprintf(stdout,"**null op**");
     printOperand(cdp->sym,stdout);
@@ -86,6 +88,35 @@ void replaceAllSymBySym (iCode *ic, operand *from , operand *to)
     for (lic = ic ; lic ; lic = lic->next ) {
        int siaddr ;
 
+       /* do the special cases first */
+       if (lic->op == IFX) {
+               if (IS_SYMOP(to) &&
+                   IC_COND(lic)->key == from->key) {
+                       
+                       bitVectUnSetBit (OP_USES(from),lic->key);
+                       OP_USES(to) = bitVectSetBit(OP_USES(to),lic->key);
+                       siaddr = IC_COND(lic)->isaddr ;
+                       IC_COND(lic) = operandFromOperand(to);
+                       IC_COND(lic)->isaddr = siaddr ;
+                       
+               }
+               continue ;
+       }
+
+       if (lic->op == JUMPTABLE) {
+               if (IS_SYMOP(to) &&
+                   IC_JTCOND(lic)->key == from->key) {
+                       
+                       bitVectUnSetBit (OP_USES(from),lic->key);
+                       OP_USES(to) = bitVectSetBit(OP_USES(to),lic->key);
+                       siaddr = IC_COND(lic)->isaddr ;
+                       IC_JTCOND(lic) = operandFromOperand(to);
+                       IC_JTCOND(lic)->isaddr = siaddr ;
+                       
+               }
+               continue ;
+       }
+
        if (IC_RESULT(lic) && IC_RESULT(lic)->key == from->key ) {
            /* maintain du chains */
            if (POINTER_SET(lic)) {
@@ -101,7 +132,8 @@ void replaceAllSymBySym (iCode *ic, operand *from , operand *to)
            IC_RESULT(lic)->isaddr = siaddr ;
        }
 
-       if (IC_RIGHT(lic) && IC_RIGHT(lic)->key == from->key ) {
+       if (IS_SYMOP(to) &&
+           IC_RIGHT(lic) && IC_RIGHT(lic)->key == from->key ) {
            bitVectUnSetBit (OP_USES(from),lic->key);
            OP_USES(to) = bitVectSetBit(OP_USES(to),lic->key);
            siaddr = IC_RIGHT(lic)->isaddr ;
@@ -109,7 +141,8 @@ void replaceAllSymBySym (iCode *ic, operand *from , operand *to)
            IC_RIGHT(lic)->isaddr = siaddr ;
        }
 
-       if (IC_LEFT(lic) && IC_LEFT(lic)->key == from->key ) {
+       if (IS_SYMOP(to) &&
+           IC_LEFT(lic) && IC_LEFT(lic)->key == from->key ) {
            bitVectUnSetBit (OP_USES(from),lic->key);
            OP_USES(to) = bitVectSetBit(OP_USES(to),lic->key);
            siaddr = IC_LEFT(lic)->isaddr ;
@@ -854,7 +887,7 @@ void ifxOptimize (iCode *ic, set *cseSet,
     /* if the conditional is a literal then */
     if (IS_OP_LITERAL(IC_COND(ic))) {         
 
-       if ( operandLitValue(IC_COND(ic)) && IC_TRUE(ic)) {
+       if ( (operandLitValue(IC_COND(ic)) != 0.0) && IC_TRUE(ic)) {
            
            /* change to a goto */
            ic->op = GOTO ;
@@ -1101,6 +1134,14 @@ int cseBBlock ( eBBlock *ebb, int computeOnly,
        if (SKIP_IC2(ic))
            continue ;
 
+       /* if this is an assignment from true symbol
+          to a temp then do pointer post inc/dec optimzation */
+       if (ic->op == '=' && !POINTER_SET(ic) &&
+           IS_TRUE_SYMOP(IC_RIGHT(ic)) && IS_ITEMP(IC_RESULT(ic)) &&
+           IS_PTR(operandType(IC_RESULT(ic)))) {
+           ptrPostIncDecOpt(ic);
+       }
+
        /* clear the def & use chains for the operands involved */
        /* in this operation . since it can change due to opts  */
        unsetDefsAndUses (ic);