* src/SDCCcse.c (algebraicOpts): CSE fun with &|^ and 0x00/0xff literals
authorbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 14 Jul 2003 20:50:48 +0000 (20:50 +0000)
committerbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 14 Jul 2003 20:50:48 +0000 (20:50 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2736 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCCcse.c

index e36c2f66164c1f2b8cb2e197f82acac53ae652f6..f4cf5f821d312e3ac76f9b71e7bcdff6c66b7036 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2003-07-14  Bernhard Held <bernhard@bernhardheld.de>
 
+        * src/SDCCcse.c (algebraicOpts): CSE fun with &|^ and 0x00/0xff literals
        pic16 progress by Vangelis:
        * src/SDCCglobl.h:
        * src/SDCCmain.c:
index 081250a1207687086c55b42ff20e7fb61156ad25..16553d4a748edd9e92fbc736f4a29363be65f94d 100644 (file)
@@ -949,6 +949,124 @@ algebraicOpts (iCode * ic)
          IC_LEFT (ic) = NULL;
          SET_ISADDR (IC_RESULT (ic), 0);
        }
+      break;
+    case BITWISEAND:
+      if (IS_OP_LITERAL (IC_LEFT (ic)))
+        {
+         /* if BITWISEAND then check if one of them is a zero */
+         /* if yes turn it into 0 assignment */
+         if (operandLitValue (IC_LEFT (ic)) == 0.0)
+           {
+             if (IS_OP_VOLATILE (IC_RIGHT (ic)))
+               return;
+             ic->op = '=';
+             IC_RIGHT (ic) = IC_LEFT (ic);
+             IC_LEFT (ic) = NULL;
+             SET_RESULT_RIGHT (ic);
+             return;
+           }
+         /* if BITWISEAND then check if one of them is 0xff... */
+         /* if yes turn it into assignment */
+         if (operandLitValue (IC_LEFT (ic)) == -1.0)
+           {
+             ic->op = '=';
+             IC_LEFT (ic) = NULL;
+             SET_RESULT_RIGHT (ic);
+             return;
+           }
+       }
+      if (IS_OP_LITERAL (IC_RIGHT (ic)))
+        {
+         /* if BITWISEAND then check if one of them is a zero */
+         /* if yes turn it into 0 assignment */
+         if (operandLitValue (IC_RIGHT (ic)) == 0.0)
+           {
+             if (IS_OP_VOLATILE (IC_LEFT (ic)))
+               return;
+             ic->op = '=';
+             IC_LEFT (ic) = NULL;
+             SET_RESULT_RIGHT (ic);
+             return;
+           }
+         /* if BITWISEAND then check if one of them is 0xff... */
+         /* if yes turn it into assignment */
+         if (operandLitValue (IC_RIGHT (ic)) == -1.0)
+           {
+             ic->op = '=';
+             IC_RIGHT (ic) = IC_LEFT (ic);
+             IC_LEFT (ic) = NULL;
+             SET_RESULT_RIGHT (ic);
+             return;
+           }
+       }
+      break;
+    case '|':
+      if (IS_OP_LITERAL (IC_LEFT (ic)))
+        {
+         /* if BITWISEOR then check if one of them is a zero */
+         /* if yes turn it into assignment */
+         if (operandLitValue (IC_LEFT (ic)) == 0.0)
+           {
+             ic->op = '=';
+             IC_LEFT (ic) = NULL;
+             SET_RESULT_RIGHT (ic);
+             return;
+           }
+         /* if BITWISEOR then check if one of them is 0xff... */
+         /* if yes turn it into 0xff... assignment */
+         if (operandLitValue (IC_LEFT (ic)) == -1.0)
+           {
+             ic->op = '=';
+             IC_RIGHT (ic) = IC_LEFT (ic);
+             IC_LEFT (ic) = NULL;
+             SET_RESULT_RIGHT (ic);
+             return;
+           }
+       }
+      if (IS_OP_LITERAL (IC_RIGHT (ic)))
+        {
+         /* if BITWISEOR then check if one of them is a zero */
+         /* if yes turn it into assignment */
+         if (operandLitValue (IC_RIGHT (ic)) == 0.0)
+           {
+             ic->op = '=';
+             IC_RIGHT (ic) = IC_LEFT (ic);
+             IC_LEFT (ic) = NULL;
+             SET_RESULT_RIGHT (ic);
+             return;
+           }
+         /* if BITWISEOR then check if one of them is 0xff... */
+         /* if yes turn it into 0xff... assignment */
+         if (operandLitValue (IC_RIGHT (ic)) == -1.0)
+           {
+             ic->op = '=';
+             IC_LEFT (ic) = NULL;
+             SET_RESULT_RIGHT (ic);
+             return;
+           }
+       }
+      break;
+    case '^':
+      /* if XOR then check if one of them is a zero */
+      /* if yes turn it into assignment */
+      if (IS_OP_LITERAL (IC_LEFT (ic)) &&
+         operandLitValue (IC_LEFT (ic)) == 0.0)
+       {
+         ic->op = '=';
+         IC_LEFT (ic) = NULL;
+         SET_RESULT_RIGHT (ic);
+         return;
+       }
+      if (IS_OP_LITERAL (IC_RIGHT (ic)) &&
+         operandLitValue (IC_RIGHT (ic)) == 0.0)
+       {
+         ic->op = '=';
+         IC_RIGHT (ic) = IC_LEFT (ic);
+         IC_LEFT (ic) = NULL;
+         SET_RESULT_RIGHT (ic);
+         return;
+       }
+      break;
     }
 
   return;
@@ -957,7 +1075,7 @@ algebraicOpts (iCode * ic)
 /*-----------------------------------------------------------------*/
 /* updateSpillLocation - keeps track of register spill location    */
 /*-----------------------------------------------------------------*/
-void 
+void
 updateSpillLocation (iCode * ic, int induction)
 {
        sym_link *setype;