X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2FSDCCcse.c;h=23f0205085bd2b543e9d8995b11b3db3811ed8a1;hb=115d5811f8b0d4c6de0412bad52dfc2df11abbb6;hp=7d86488d608017f3c36d5c4c96243ea6a5d63f23;hpb=4c527a8dc0a11d9bb33bebfe2fafa42e34b2895b;p=fw%2Fsdcc diff --git a/src/SDCCcse.c b/src/SDCCcse.c index 7d86488d..23f02050 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -188,7 +188,7 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) #endif for (lic = ic; lic; lic = lic->next) { - int siaddr; + int isaddr; /* do the special cases first */ if (lic->op == IFX) @@ -199,9 +199,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) bitVectUnSetBit (OP_USES (from), lic->key); OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); - siaddr = IC_COND (lic)->isaddr; + isaddr = IC_COND (lic)->isaddr; IC_COND (lic) = operandFromOperand (to); - IC_COND (lic)->isaddr = siaddr; + IC_COND (lic)->isaddr = isaddr; } continue; @@ -215,9 +215,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) bitVectUnSetBit (OP_USES (from), lic->key); OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); - siaddr = IC_COND (lic)->isaddr; + isaddr = IC_COND (lic)->isaddr; IC_JTCOND (lic) = operandFromOperand (to); - IC_JTCOND (lic)->isaddr = siaddr; + IC_JTCOND (lic)->isaddr = isaddr; } continue; @@ -246,9 +246,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) bitVectUnSetBit (OP_DEFS (from), lic->key); OP_DEFS(to)=bitVectSetBit (OP_DEFS (to), lic->key); } - siaddr = IC_RESULT (lic)->isaddr; + isaddr = IC_RESULT (lic)->isaddr; IC_RESULT (lic) = operandFromOperand (to); - IC_RESULT (lic)->isaddr = siaddr; + IC_RESULT (lic)->isaddr = isaddr; } if (IS_SYMOP (to) && @@ -256,9 +256,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) { bitVectUnSetBit (OP_USES (from), lic->key); OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); - siaddr = IC_RIGHT (lic)->isaddr; + isaddr = IC_RIGHT (lic)->isaddr; IC_RIGHT (lic) = operandFromOperand (to); - IC_RIGHT (lic)->isaddr = siaddr; + IC_RIGHT (lic)->isaddr = isaddr; } if (IS_SYMOP (to) && @@ -266,9 +266,9 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) { bitVectUnSetBit (OP_USES (from), lic->key); OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); - siaddr = IC_LEFT (lic)->isaddr; + isaddr = IC_LEFT (lic)->isaddr; IC_LEFT (lic) = operandFromOperand (to); - IC_LEFT (lic)->isaddr = siaddr; + IC_LEFT (lic)->isaddr = isaddr; } } } @@ -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 '/': @@ -1118,6 +1135,7 @@ algebraicOpts (iCode * ic, eBBlock * ebp) { iCode *newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); IC_RESULT (newic) = IC_LEFT (ic); + newic->filename = ic->filename; newic->lineno = ic->lineno; addiCodeToeBBlock (ebp, newic, ic->next); } @@ -1145,6 +1163,7 @@ algebraicOpts (iCode * ic, eBBlock * ebp) { iCode *newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); IC_RESULT (newic) = IC_LEFT (ic); + newic->filename = ic->filename; newic->lineno = ic->lineno; addiCodeToeBBlock (ebp, newic, ic->next); } @@ -1172,7 +1191,7 @@ algebraicOpts (iCode * ic, eBBlock * ebp) default: return; } - if (((unsigned) operandLitValue (IC_RIGHT (ic)) & val) == val) + if (((unsigned) double2ul (operandLitValue (IC_RIGHT (ic))) & val) == val) { ic->op = '='; IC_RIGHT (ic) = IC_LEFT (ic); @@ -1192,6 +1211,7 @@ algebraicOpts (iCode * ic, eBBlock * ebp) { iCode *newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); IC_RESULT (newic) = IC_LEFT (ic); + newic->filename = ic->filename; newic->lineno = ic->lineno; addiCodeToeBBlock (ebp, newic, ic->next); } @@ -1240,12 +1260,13 @@ algebraicOpts (iCode * ic, eBBlock * ebp) default: return; } - if (((unsigned) operandLitValue (IC_RIGHT (ic)) & val) == val) + if (((unsigned) double2ul (operandLitValue (IC_RIGHT (ic))) & val) == val) { if (IS_OP_VOLATILE (IC_LEFT (ic))) { iCode *newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); IC_RESULT (newic) = IC_LEFT (ic); + newic->filename = ic->filename; newic->lineno = ic->lineno; addiCodeToeBBlock (ebp, newic, ic->next); } @@ -1266,11 +1287,13 @@ algebraicOpts (iCode * ic, eBBlock * ebp) { iCode *newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); IC_RESULT (newic) = IC_LEFT (ic); + newic->filename = ic->filename; newic->lineno = ic->lineno; addiCodeToeBBlock (ebp, newic, ic->next); newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); IC_RESULT (newic) = IC_LEFT (ic); + newic->filename = ic->filename; newic->lineno = ic->lineno; addiCodeToeBBlock (ebp, newic, ic->next); } @@ -1892,7 +1915,7 @@ cseBBlock (eBBlock * ebb, int computeOnly, /* and also iTemps derived from globals */ deleteItemIf (&cseSet, ifFromGlobal); - + /* Delete iTemps derived from symbols whose address */ /* has been taken */ deleteItemIf (&cseSet, ifFromAddrTaken); @@ -1980,11 +2003,11 @@ cseBBlock (eBBlock * ebb, int computeOnly, IC_LEFT (ic)->aggr2ptr = 0; fixUpTypes (ic); } - else if (IC_LEFT (ic)->aggr2ptr) + else if (IC_LEFT (ic)->aggr2ptr == 1) {/* band aid for kludge */ setOperandType (IC_LEFT (ic), aggrToPtr (operandType (IC_LEFT (ic)), TRUE)); - IC_LEFT (ic)->aggr2ptr = 0; + IC_LEFT (ic)->aggr2ptr++; fixUpTypes (ic); } } @@ -1997,11 +2020,11 @@ cseBBlock (eBBlock * ebb, int computeOnly, aggrToPtr (operandType (IC_RESULT (ic)), FALSE)); IC_RESULT (ic)->aggr2ptr = 0; } - else if (IC_RESULT (ic)->aggr2ptr) + else if (IC_RESULT (ic)->aggr2ptr == 1) {/* band aid for kludge */ setOperandType (IC_RESULT (ic), aggrToPtr (operandType (IC_RESULT (ic)), TRUE)); - IC_RESULT (ic)->aggr2ptr = 0; + IC_RESULT (ic)->aggr2ptr++; } } @@ -2023,7 +2046,7 @@ cseBBlock (eBBlock * ebb, int computeOnly, /* update the spill location for this */ updateSpillLocation (ic,0); - if (POINTER_SET (ic) && + if (POINTER_SET (ic) && IS_SYMOP (IC_RESULT (ic)) && !(IS_BITFIELD (OP_SYMBOL (IC_RESULT (ic))->etype))) { pdop = NULL; @@ -2090,7 +2113,7 @@ cseBBlock (eBBlock * ebb, int computeOnly, } } - /*right operand */ + /* right operand */ if (IS_SYMOP (IC_RIGHT (ic)) && !computeOnly) { @@ -2132,7 +2155,7 @@ cseBBlock (eBBlock * ebb, int computeOnly, IS_ITEMP (IC_RESULT (ic)) && !computeOnly) { - applyToSet (cseSet, findPrevIc, ic, &pdic); + applyToSet (cseSet, findPrevIc, ic, &pdic); if (pdic && compareType (operandType (IC_RESULT (pdic)), operandType (IC_RESULT (ic))) != 1) pdic = NULL; @@ -2169,6 +2192,7 @@ cseBBlock (eBBlock * ebb, int computeOnly, mine and type is a pointer then delete pointerGets to take care of aliasing */ if (ASSIGNMENT (ic) && + IS_SYMOP (IC_RESULT (ic)) && OTHERS_PARM (OP_SYMBOL (IC_RESULT (ic))) && IS_PTR (operandType (IC_RESULT (ic)))) { @@ -2197,12 +2221,11 @@ cseBBlock (eBBlock * ebb, int computeOnly, /* delete from the cseSet anything that has */ /* operands matching the result of this */ /* except in case of pointer access */ - if (!(POINTER_SET (ic)) && IC_RESULT (ic)) + if (!(POINTER_SET (ic)) && IS_SYMOP (IC_RESULT (ic))) { deleteItemIf (&cseSet, ifOperandsHave, IC_RESULT (ic)); /* delete any previous definitions */ ebb->defSet = bitVectCplAnd (ebb->defSet, OP_DEFS (IC_RESULT (ic))); - } /* add the left & right to the defUse set */ @@ -2211,7 +2234,6 @@ cseBBlock (eBBlock * ebb, int computeOnly, OP_USES(IC_LEFT (ic))= bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key); setUsesDefs (IC_LEFT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); - } if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic))) @@ -2219,12 +2241,11 @@ cseBBlock (eBBlock * ebb, int computeOnly, OP_USES(IC_RIGHT (ic))= bitVectSetBit (OP_USES (IC_RIGHT (ic)), ic->key); setUsesDefs (IC_RIGHT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); - } /* for the result it is special case, put the result */ /* in the defuseSet if it a pointer or array access */ - if (POINTER_SET (defic)) + if (POINTER_SET (defic) && IS_SYMOP (IC_RESULT (ic))) { OP_USES(IC_RESULT (ic))= bitVectSetBit (OP_USES (IC_RESULT (ic)), ic->key); @@ -2243,16 +2264,18 @@ cseBBlock (eBBlock * ebb, int computeOnly, addSetHead (&ptrSetSet, newCseDef (IC_RESULT (ic), ic)); } else - /* add the result to defintion set */ if (IC_RESULT (ic)) { - OP_DEFS(IC_RESULT (ic))= - bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key); - ebb->defSet = bitVectSetBit (ebb->defSet, ic->key); - ebb->outDefs = bitVectCplAnd (ebb->outDefs, OP_DEFS (IC_RESULT (ic))); - ebb->ldefs = bitVectSetBit (ebb->ldefs, ic->key); + /* add the result to definition set */ + if (IS_SYMOP (IC_RESULT (ic))) + { + OP_DEFS(IC_RESULT (ic))= + bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key); + ebb->defSet = bitVectSetBit (ebb->defSet, ic->key); + ebb->outDefs = bitVectCplAnd (ebb->outDefs, OP_DEFS (IC_RESULT (ic))); + ebb->ldefs = bitVectSetBit (ebb->ldefs, ic->key); + } } - /* if this is an addressof instruction then */ /* put the symbol in the address of list & */ /* delete it from the cseSet */