From b33843fcef1cb27230e52589c1af2d07be48ee95 Mon Sep 17 00:00:00 2001 From: bernhardheld Date: Tue, 25 Apr 2006 14:05:04 +0000 Subject: [PATCH] * src/SDCCast.c (decorateType): fix for RFE 1475742, optimize 'ifx (op == 0)' resp. 'ifx (op != 0)' git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4125 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 4 +++- src/SDCCast.c | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index eb0c7676..8b9ffa36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,9 @@ 2006-04-25 Bernhard Held * src/SDCCast.c (decorateType): partial fix for RFE 1475769, - remove cast to same type + remove cast to same type + * src/SDCCast.c (decorateType): fix for RFE 1475742, + optimize 'ifx (op == 0)' resp. 'ifx (op != 0)' 2006-04-24 Bernhard Held diff --git a/src/SDCCast.c b/src/SDCCast.c index 9a5bf438..66452408 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -3923,6 +3923,7 @@ decorateType (ast * tree, RESULT_TYPE resultType) goto errorTreeReturn; } } + /* if unsigned value < 0 then always false */ /* if (unsigned value) > 0 then '(unsigned value) ? 1 : 0' */ if (SPEC_USIGN(LETYPE(tree)) && @@ -3950,9 +3951,23 @@ decorateType (ast * tree, RESULT_TYPE resultType) tree->right); /* val 0 */ tree->right->lineno = tree->lineno; tree->right->left->lineno = tree->lineno; - decorateType (tree->right, RESULT_TYPE_NONE); + tree->decorated = 0; + return decorateType (tree, resultType); } } + + /* 'ifx (op == 0)' -> 'ifx (!(op))' */ + if (IS_LITERAL(RTYPE(tree)) && + floatFromVal (valFromType (RETYPE (tree))) == 0 && + tree->opval.op == EQ_OP && + resultType == RESULT_TYPE_IFX) + { + tree->opval.op = '!'; + tree->right = NULL; + tree->decorated = 0; + return decorateType (tree, resultType); + } + /* if they are both literal then */ /* rewrite the tree */ if (IS_LITERAL (RTYPE (tree)) && -- 2.30.2