From a562b2018aa7ee365be762916ca88c26b81d62dd Mon Sep 17 00:00:00 2001 From: borutr Date: Sat, 19 Jan 2008 23:49:32 +0000 Subject: [PATCH] * src/SDCCcse.c: partially fixed enhancement request #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 | 6 ++++++ src/SDCCcse.c | 25 +++++++++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index b973a16b..3c846a25 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-01-20 Borut Razem + + * 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 * as/mcs51/asx8051.dsp: removed define SDK diff --git a/src/SDCCcse.c b/src/SDCCcse.c index fc45babf..f6e6ec03 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -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 '/': -- 2.30.2