* src/SDCCcse.c: partially fixed enhancement request
authorborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 19 Jan 2008 23:49:32 +0000 (23:49 +0000)
committerborutr <borutr@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 19 Jan 2008 23:49:32 +0000 (23:49 +0000)
  #1793872 - multiply by -1 not collapsed
* support/regression/tests/arithcsi.c: added regression test

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

ChangeLog
src/SDCCcse.c

index b973a16b4397c2ec8761a4c69d3f8daab798f3a3..3c846a25b5d97e1a96fa2e10f7e9db4930f36c50 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-01-20 Borut Razem <borut.razem AT siol.net>
+
+       * src/SDCCcse.c: partially fixed enhancement request
+         #1793872 - multiply by -1 not collapsed
+       * support/regression/tests/arithcsi.c: added regression test
+
 2008-01-19 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * as/mcs51/asx8051.dsp: removed define SDK
index fc45babf2fe0f1a81f940bcc25148a993ba90314..f6e6ec03a313cecf33a649478bf3f43e0fca8b15 100644 (file)
@@ -957,8 +957,9 @@ algebraicOpts (iCode * ic, eBBlock * ebp)
     case '*':
       if (IS_OP_LITERAL (IC_LEFT (ic)))
         {
+         double leftValue = operandLitValue (IC_LEFT (ic));
 
-          if (operandLitValue (IC_LEFT (ic)) == 0.0)
+          if (leftValue == 0.0)
             {
               ic->op = '=';
               IC_RIGHT (ic) = IC_LEFT (ic);
@@ -966,7 +967,7 @@ algebraicOpts (iCode * ic, eBBlock * ebp)
               SET_RESULT_RIGHT (ic);
               return;
             }
-          if (operandLitValue (IC_LEFT (ic)) == 1.0)
+          if (leftValue == 1.0)
             {
               /* '*' can have two unsigned chars as operands */
               /* and an unsigned int as result.              */
@@ -987,12 +988,21 @@ algebraicOpts (iCode * ic, eBBlock * ebp)
                 }
               return;
             }
+          if (leftValue == -1.0)
+            {
+              /* convert -1 * x to -x */
+              ic->op = UNARYMINUS;
+              IC_LEFT (ic) = IC_RIGHT (ic);
+              IC_RIGHT (ic) = NULL;
+              return;
+            }
         }
 
       if (IS_OP_LITERAL (IC_RIGHT (ic)))
         {
+          double rightValue = operandLitValue (IC_RIGHT (ic));
 
-          if (operandLitValue (IC_RIGHT (ic)) == 0.0)
+          if (rightValue == 0.0)
             {
               ic->op = '=';
               IC_LEFT (ic) = NULL;
@@ -1000,7 +1010,7 @@ algebraicOpts (iCode * ic, eBBlock * ebp)
               return;
             }
 
-          if (operandLitValue (IC_RIGHT (ic)) == 1.0)
+          if (rightValue == 1.0)
             {
               /* '*' can have two unsigned chars as operands */
               /* and an unsigned int as result.              */
@@ -1026,6 +1036,13 @@ algebraicOpts (iCode * ic, eBBlock * ebp)
                 }
               return;
             }
+          if (rightValue == -1.0)
+            {
+              /* convert x * -1 to -x */
+              ic->op = UNARYMINUS;
+              IC_RIGHT (ic) = NULL;
+              return;
+            }
         }
       break;
     case '/':