From: bernhardheld Date: Mon, 14 Jul 2003 20:50:48 +0000 (+0000) Subject: * src/SDCCcse.c (algebraicOpts): CSE fun with &|^ and 0x00/0xff literals X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=e6f5545a7aa61ed3893f644a950eb28cf9b68f7d;p=fw%2Fsdcc * src/SDCCcse.c (algebraicOpts): CSE fun with &|^ and 0x00/0xff literals git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2736 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index e36c2f66..f4cf5f82 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2003-07-14 Bernhard Held + * src/SDCCcse.c (algebraicOpts): CSE fun with &|^ and 0x00/0xff literals pic16 progress by Vangelis: * src/SDCCglobl.h: * src/SDCCmain.c: diff --git a/src/SDCCcse.c b/src/SDCCcse.c index 081250a1..16553d4a 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -949,6 +949,124 @@ algebraicOpts (iCode * ic) IC_LEFT (ic) = NULL; SET_ISADDR (IC_RESULT (ic), 0); } + break; + case BITWISEAND: + if (IS_OP_LITERAL (IC_LEFT (ic))) + { + /* if BITWISEAND then check if one of them is a zero */ + /* if yes turn it into 0 assignment */ + if (operandLitValue (IC_LEFT (ic)) == 0.0) + { + if (IS_OP_VOLATILE (IC_RIGHT (ic))) + return; + ic->op = '='; + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + /* if BITWISEAND then check if one of them is 0xff... */ + /* if yes turn it into assignment */ + if (operandLitValue (IC_LEFT (ic)) == -1.0) + { + ic->op = '='; + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + } + if (IS_OP_LITERAL (IC_RIGHT (ic))) + { + /* if BITWISEAND then check if one of them is a zero */ + /* if yes turn it into 0 assignment */ + if (operandLitValue (IC_RIGHT (ic)) == 0.0) + { + if (IS_OP_VOLATILE (IC_LEFT (ic))) + return; + ic->op = '='; + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + /* if BITWISEAND then check if one of them is 0xff... */ + /* if yes turn it into assignment */ + if (operandLitValue (IC_RIGHT (ic)) == -1.0) + { + ic->op = '='; + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + } + break; + case '|': + if (IS_OP_LITERAL (IC_LEFT (ic))) + { + /* if BITWISEOR then check if one of them is a zero */ + /* if yes turn it into assignment */ + if (operandLitValue (IC_LEFT (ic)) == 0.0) + { + ic->op = '='; + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + /* if BITWISEOR then check if one of them is 0xff... */ + /* if yes turn it into 0xff... assignment */ + if (operandLitValue (IC_LEFT (ic)) == -1.0) + { + ic->op = '='; + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + } + if (IS_OP_LITERAL (IC_RIGHT (ic))) + { + /* if BITWISEOR then check if one of them is a zero */ + /* if yes turn it into assignment */ + if (operandLitValue (IC_RIGHT (ic)) == 0.0) + { + ic->op = '='; + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + /* if BITWISEOR then check if one of them is 0xff... */ + /* if yes turn it into 0xff... assignment */ + if (operandLitValue (IC_RIGHT (ic)) == -1.0) + { + ic->op = '='; + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + } + break; + case '^': + /* if XOR then check if one of them is a zero */ + /* if yes turn it into assignment */ + if (IS_OP_LITERAL (IC_LEFT (ic)) && + operandLitValue (IC_LEFT (ic)) == 0.0) + { + ic->op = '='; + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + if (IS_OP_LITERAL (IC_RIGHT (ic)) && + operandLitValue (IC_RIGHT (ic)) == 0.0) + { + ic->op = '='; + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + break; } return; @@ -957,7 +1075,7 @@ algebraicOpts (iCode * ic) /*-----------------------------------------------------------------*/ /* updateSpillLocation - keeps track of register spill location */ /*-----------------------------------------------------------------*/ -void +void updateSpillLocation (iCode * ic, int induction) { sym_link *setype;