]> git.gag.com Git - fw/sdcc/commitdiff
Fixed bug #483124
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 19 Nov 2001 13:49:17 +0000 (13:49 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 19 Nov 2001 13:49:17 +0000 (13:49 +0000)
The experimental if-optimizer/warner goes with it

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1622 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCast.c
src/SDCCicode.c
src/SDCCsymt.h
src/ds390/ralloc.c
src/mcs51/ralloc.c
support/Util/SDCCerr.c
support/Util/SDCCerr.h

index dc1c8f9494c3672f38ec4fefc5103c66f0a4541b..bf5b3abf36243ddc146f058dd0d69153c074adb7 100644 (file)
@@ -3986,6 +3986,63 @@ optimizeCompare (ast * root)
   vright = (root->right->type == EX_VALUE ?
            root->right->opval.val : NULL);
 
+  //#define EXPERIMENTAL
+#ifdef EXPERIMENTAL
+  /* if left is unsigned and right is literal */
+  if (vleft && vright && 
+      IS_UNSIGNED(vleft->etype) &&
+      IS_LITERAL(vright->etype)) {
+    double dval=floatFromVal(vright);
+    int op=root->opval.op;
+
+    fprintf (stderr,"op: '");
+    switch (op) {
+    case LE_OP: fprintf (stderr, "<= '"); break;
+    case EQ_OP: fprintf (stderr, "== '"); break;
+    case GE_OP: fprintf (stderr, ">= '"); break;
+    default: fprintf (stderr, "%c '", op); break;
+    }
+    fprintf (stderr, "%f\n", dval);
+
+    switch (op)
+      {
+      case EQ_OP:
+      case LE_OP:
+      case '<':
+       if (dval<0 || (op=='<' && dval==0)) {
+         // unsigned is never < 0
+         werror (W_IF_NEVER_TRUE);
+         optExpr = newAst_VALUE (constVal("0"));
+         return decorateType (optExpr);
+       }
+       if (dval==0) {
+         if (op==LE_OP) {
+           // change this into a cheaper EQ_OP
+           fprintf (stderr, "warning *** changed '<=' to '==' because of unsigned\n");
+           root->opval.op=EQ_OP;
+           return root;
+         }
+       }
+       break;
+      case GE_OP:
+      case '>':
+       if (dval>0 || (op==GE_OP && dval==0)) {
+         // unsigned is never < 0
+         werror (W_IF_ALWAYS_TRUE);
+         optExpr = newAst_VALUE (constVal("1"));
+         return decorateType (optExpr);
+       }
+       if (dval==0) {
+         if (op=='>') {
+           // change this into a cheaper reversed EQ_OP
+           fprintf (stderr, "warning *** changed '>' to '!=' because of unsigned\n");
+           root->opval.op=EQ_OP;
+         }
+       }
+      }
+  }
+#endif
+
   /* if left is a BITVAR in BITSPACE */
   /* and right is a LITERAL then opt- */
   /* imize else do nothing       */
index 460fc5d47d3cb28967308acb9d8a576c0b3a3fba..6d0f16edd05b462483f6b722a7c6a8363a762f48 100644 (file)
@@ -918,6 +918,7 @@ isOperandInDirSpace (operand * op)
 /*-----------------------------------------------------------------*/
 /* isOperandOnStack - will return true if operand is on stack      */
 /*-----------------------------------------------------------------*/
+#if 0
 bool 
 isOperandOnStack (operand * op)
 {
@@ -933,6 +934,27 @@ isOperandOnStack (operand * op)
 
   return ((IN_STACK (etype)) ? TRUE : FALSE);
 }
+#else
+bool 
+isOperandOnStack (operand * op)
+{
+  sym_link *etype;
+
+  if (!op)
+    return FALSE;
+
+  if (!IS_SYMOP (op))
+    return FALSE;
+
+  etype = getSpec (operandType (op));
+  if (IN_STACK (etype) ||
+      OP_SYMBOL(op)->onStack ||
+      (SPIL_LOC(op) && SPIL_LOC(op)->onStack))
+    return TRUE;
+
+  return FALSE;
+}
+#endif
 
 /*-----------------------------------------------------------------*/
 /* operandLitValue - literal value of an operand                   */
index bf0544bcb5150ea2c3c7e9b341af13ead7d2d13a..d0274ac0711a849281d83a1cdf3cfaf03c247c16 100644 (file)
@@ -299,7 +299,6 @@ symbol;
 #define IFFUNC_CALLEESAVES(x) (IS_FUNC(x) && FUNC_CALLEESAVES(x))
 #define FUNC_ISISR(x) (x->funcAttrs.intrtn)
 #define IFFUNC_ISISR(x) (IS_FUNC(x) && FUNC_ISISR(x))
-//#define FUNC_RBANK(x) (x->funcAttrs.rbank)
 #define IFFUNC_RBANK(x) (IS_FUNC(x) && FUNC_RBANK(x))
 #define FUNC_INTNO(x) (x->funcAttrs.intno)
 #define FUNC_REGBANK(x) (x->funcAttrs.regbank)
@@ -371,6 +370,7 @@ symbol;
 #define IS_GENPTR(x) (IS_DECL(x) && DCL_TYPE(x) == GPOINTER)
 #define IS_FUNC(x)   (IS_DECL(x) && DCL_TYPE(x) == FUNCTION)
 #define IS_LONG(x)   (IS_SPEC(x) && x->select.s._long)
+#define IS_UNSIGNED(x) (IS_SPEC(x) && x->select.s._unsigned)
 #define IS_TYPEDEF(x)(IS_SPEC(x) && x->select.s._typedef)
 #define IS_CONSTANT(x)  (IS_SPEC(x) && ( x->select.s._const == 1))
 #define IS_STRUCT(x) (IS_SPEC(x) && x->select.s.noun == V_STRUCT)
index 9adf61c4fa77af30a5e2c5889ea96bd57f669177..485f47a47c628ce51ad8f35e2a557732625634d1 100644 (file)
@@ -2243,9 +2243,14 @@ packRegsForAccUse (iCode * ic)
 
   /* make sure that the result of this icode is not on the
      stack, since acc is used to compute stack offset */
+#if 0
   if (IS_TRUE_SYMOP (IC_RESULT (uic)) &&
       OP_SYMBOL (IC_RESULT (uic))->onStack)
     return;
+#else
+  ifSymbolOnStack(IC_RESULT(uic))
+    return;
+#endif
 
   /* if either one of them in far space then we cannot */
   if ((IS_TRUE_SYMOP (IC_LEFT (uic)) &&
index 57bac398663cb29882b6af528b6b6fad7ace0aaf..057531573ad7d0fc6de8da3d44f60fa7bb86ddf7 100644 (file)
@@ -2149,9 +2149,14 @@ packRegsForAccUse (iCode * ic)
 
   /* make sure that the result of this icode is not on the
      stack, since acc is used to compute stack offset */
+#if 0
   if (IS_TRUE_SYMOP (IC_RESULT (uic)) &&
       OP_SYMBOL (IC_RESULT (uic))->onStack)
+     return;
+#else
+  ifSymbolOnStack(IC_RESULT(uic))
     return;
+#endif
 
   /* if either one of them in far space then we cannot */
   if ((IS_TRUE_SYMOP (IC_LEFT (uic)) &&
index 0be9ab4827bf8dd5ab837a2ea0f5ca11968972fd..ed6eebd678d7a5279d16408cae9c64657cb1240a 100644 (file)
@@ -241,7 +241,7 @@ struct
 { W_DOUBLE_UNSUPPORTED, ERROR_LEVEL_WARNING,
    "type 'double' not supported assuming 'float'" },
 { W_IF_NEVER_TRUE, ERROR_LEVEL_WARNING,
-   "if-statement condition always false.if-statement not generated" },
+   "if-statement condition always falseif-statement not generated" },
 { W_FUNC_NO_RETURN, ERROR_LEVEL_WARNING,
    "no 'return' statement found for function '%s'" },
 { W_PRE_PROC_WARNING, ERROR_LEVEL_WARNING,
@@ -370,6 +370,8 @@ struct
     "symbol name too long, truncated to %d chars" },
 { W_CAST_STRUCT_PTR,ERROR_LEVEL_WARNING,
          "cast of struct %s * to struct %s * " },
+{ W_IF_ALWAYS_TRUE, ERROR_LEVEL_WARNING,
+   "if-statement condition always true, if-statement not generated" },
 };
 
 /*
index ae338face3e610b8fb22ee3da1298b229ad81996..e8df9922db8e66bff9abb4488d9fbf41464da591 100644 (file)
@@ -173,6 +173,7 @@ SDCCERR - SDCC Standard error handler
 #define W_PTR2INTEGRAL_NOCAST 155
 #define W_SYMBOL_NAME_TOO_LONG 156
 #define W_CAST_STRUCT_PTR 157 /* pointer to different structure types */
+#define W_IF_ALWAYS_TRUE 158
 
 /** Describes the maximum error level that will be logged.  Any level
  *  includes all of the levels listed after it.