From: sandeep Date: Sat, 20 Oct 2001 17:55:50 +0000 (+0000) Subject: Early optimization of '?' operator if value already known X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=3064a007acd3a1dff676497e2f748f25318d052b;p=fw%2Fsdcc Early optimization of '?' operator if value already known git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1420 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCast.c b/src/SDCCast.c index 9812f66b..1c79c9ea 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -2902,15 +2902,25 @@ decorateType (ast * tree) tree->opval.val->type); return tree; -/*------------------------------------------------------------------*/ -/*----------------------------*/ + /*------------------------------------------------------------------*/ + /*----------------------------*/ /* conditional operator '?' */ -/*----------------------------*/ + /*----------------------------*/ case '?': /* the type is value of the colon operator (on the right) */ assert(IS_COLON_OP(tree->right)); - TTYPE (tree) = RTYPE(tree); // #HACK LTYPE(tree). - TETYPE (tree) = getSpec (TTYPE (tree)); + /* if already known then replace the tree : optimizer will do it + but faster to do it here */ + if (IS_LITERAL (LTYPE(tree))) { + if ( ((int) floatFromVal (valFromType (LETYPE (tree)))) != 0) { + return tree->right->left ; + } else { + return tree->right->right ; + } + } else { + TTYPE (tree) = RTYPE(tree); // #HACK LTYPE(tree). + TETYPE (tree) = getSpec (TTYPE (tree)); + } return tree; case ':': @@ -4728,6 +4738,7 @@ void ast_print (ast * tree, FILE *outfile, int indent) fprintf(outfile,")\n"); ast_print(tree->left,outfile,indent+4); ast_print(tree->right,outfile,indent+4); + return; case ':': fprintf(outfile,"COLON(:) (%p) type (",tree);