From: johanknol Date: Mon, 19 Nov 2001 13:49:17 +0000 (+0000) Subject: Fixed bug #483124 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=7489be486a8008b25b31654823bd7ac115d7ad85;p=fw%2Fsdcc Fixed bug #483124 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 --- diff --git a/src/SDCCast.c b/src/SDCCast.c index dc1c8f94..bf5b3abf 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -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 */ diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 460fc5d4..6d0f16ed 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -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 */ diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index bf0544bc..d0274ac0 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -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) diff --git a/src/ds390/ralloc.c b/src/ds390/ralloc.c index 9adf61c4..485f47a4 100644 --- a/src/ds390/ralloc.c +++ b/src/ds390/ralloc.c @@ -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)) && diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index 57bac398..05753157 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -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)) && diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index 0be9ab48..ed6eebd6 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -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 false, if-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" }, }; /* diff --git a/support/Util/SDCCerr.h b/support/Util/SDCCerr.h index ae338fac..e8df9922 100644 --- a/support/Util/SDCCerr.h +++ b/support/Util/SDCCerr.h @@ -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.