* src/SDCCast.c (decorateType): fix for RFE 1475742, optimize 'ifx (op == 0)' resp...
authorbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 25 Apr 2006 14:05:04 +0000 (14:05 +0000)
committerbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 25 Apr 2006 14:05:04 +0000 (14:05 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4125 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCCast.c

index eb0c7676e10a7244044e24a6faad2d05bd7592c0..8b9ffa364eaf80ad74194daf99dc9a06187faba1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,9 @@
 2006-04-25 Bernhard Held <bernhard AT bernhardheld.de>
 
        * 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 <bernhard AT bernhardheld.de>
 
index 9a5bf4385365554783452b845fbf267d759880d9..66452408a22bd8a0763695d22b88918b499262ae 100644 (file)
@@ -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)) &&