/* if iCodes are not the same */
/* see the operands maybe interchanged */
if (ic->op == cdp->diCode->op &&
- (ic->op == '+' || ic->op == '*') &&
+ IS_ASSOCIATIVE(ic) &&
isOperandEqual (IC_LEFT (ic), IC_RIGHT (cdp->diCode)) &&
isOperandEqual (IC_RIGHT (ic), IC_LEFT (cdp->diCode)))
{
case '+':
/* if adding the same thing change to left shift by 1 */
if (IC_LEFT (ic)->key == IC_RIGHT (ic)->key &&
- !IS_FLOAT (operandType (IC_RESULT (ic))))
+ !(IS_FLOAT (operandType (IC_RESULT (ic)))
+ || IS_FIXED(operandType (IC_RESULT (ic)))))
{
ic->op = LEFT_OP;
IC_RIGHT (ic) = operandFromLit (1);
if (IS_OP_LITERAL (IC_LEFT (ic)) &&
operandLitValue (IC_LEFT (ic)) == 0.0)
{
- if (compareType (operandType (IC_RESULT (ic)),
- operandType (IC_RIGHT (ic)))<0)
+ int typematch;
+ typematch = compareType (operandType (IC_RESULT (ic)),
+ operandType (IC_RIGHT (ic)));
+ if (typematch<0)
{
ic->op = CAST;
IC_LEFT (ic) = operandFromLink (operandType (IC_RESULT (ic)));
{
ic->op = '=';
IC_LEFT (ic) = NULL;
+ if (typematch==0)
+ {
+ /* for completely different types, preserve the source type */
+ IC_RIGHT (ic) = operandFromOperand (IC_RIGHT (ic));
+ setOperandType (IC_RIGHT (ic), operandType (IC_RESULT (ic)));
+ }
}
SET_ISADDR (IC_RESULT (ic), 0);
SET_ISADDR (IC_RIGHT (ic), 0);
if (IS_OP_LITERAL (IC_RIGHT (ic)) &&
operandLitValue (IC_RIGHT (ic)) == 0.0)
{
- if (compareType (operandType (IC_RESULT (ic)),
- operandType (IC_LEFT (ic)))<0)
+ int typematch;
+ typematch = compareType (operandType (IC_RESULT (ic)),
+ operandType (IC_LEFT (ic)));
+ if (typematch<0)
{
ic->op = CAST;
IC_RIGHT (ic) = IC_LEFT (ic);
ic->op = '=';
IC_RIGHT (ic) = IC_LEFT (ic);
IC_LEFT (ic) = NULL;
+ if (typematch==0)
+ {
+ /* for completely different types, preserve the source type */
+ IC_RIGHT (ic) = operandFromOperand (IC_RIGHT (ic));
+ setOperandType (IC_RIGHT (ic), operandType (IC_RESULT (ic)));
+ }
}
SET_ISADDR (IC_RIGHT (ic), 0);
SET_ISADDR (IC_RESULT (ic), 0);
ifxOptimize (iCode * ic, set * cseSet,
int computeOnly,
eBBlock * ebb, int *change,
- eBBlock ** ebbs, int count)
+ ebbIndex * ebbi)
{
operand *pdop;
symbol *label;
/* this is very expensive but it does not happen */
/* too often, if it does happen then the user pays */
/* the price */
- computeControlFlow (ebbs, count, 1);
+ computeControlFlow (ebbi);
if (!options.lessPedantic) {
werrorfl (ic->filename, ic->lineno, W_CONTROL_FLOW);
}
we can remove this conditional statement */
label = (IC_TRUE (ic) ? IC_TRUE (ic) : IC_FALSE (ic));
if (elementsInSet (ebb->succList) == 1 &&
- isinSet (ebb->succList, eBBWithEntryLabel (ebbs, label, count)))
+ isinSet (ebb->succList, eBBWithEntryLabel (ebbi, label)))
{
if (!options.lessPedantic) {
else
{
remiCodeFromeBBlock (ebb, ic);
- computeControlFlow (ebbs, count, 1);
+ computeControlFlow (ebbi);
return;
}
}
ic->op != '-')
return 0;
- /* this check is a hueristic to prevent live ranges
+ /* this check is a heuristic to prevent live ranges
from becoming too long */
if (IS_PTR (operandType (IC_RESULT (ic))))
return 0;
return 0;
/* check if we can find a definition for the
- right hand side */
+ left hand side */
if (!(applyToSet (cseSet, diCodeForSym, IC_LEFT (ic), &dic)))
return 0;
case RRC:
case RLC:
case GETHBIT:
+ case GETABIT:
+ case GETBYTE:
+ case GETWORD:
case RIGHT_OP:
case CAST:
case ARRAYINIT:
/*-----------------------------------------------------------------*/
int
cseBBlock (eBBlock * ebb, int computeOnly,
- eBBlock ** ebbs, int count)
+ ebbIndex * ebbi)
{
+ eBBlock ** ebbs = ebbi->bbOrder;
+ int count = ebbi->count;
set *cseSet;
iCode *ic;
int change = 0;
{
ifxOptimize (ic, cseSet, computeOnly,
ebb, &change,
- ebbs, count);
+ ebbi);
continue;
}
/* if after all this it becomes an assignment to self
then delete it and continue */
- if (ASSIGNMENT_TO_SELF (ic))
+ if (ASSIGNMENT_TO_SELF (ic) && !isOperandVolatile (IC_RIGHT(ic), FALSE))
{
remiCodeFromeBBlock (ebb, ic);
continue;
/* cseAllBlocks - will sequentially go thru & do cse for all blocks */
/*-----------------------------------------------------------------*/
int
-cseAllBlocks (eBBlock ** ebbs, int count, int computeOnly)
+cseAllBlocks (ebbIndex * ebbi, int computeOnly)
{
+ eBBlock ** ebbs = ebbi->dfOrder;
+ int count = ebbi->count;
int i;
int change = 0;
/* if optimization turned off */
for (i = 0; i < count; i++)
- change += cseBBlock (ebbs[i], computeOnly, ebbs, count);
+ change += cseBBlock (ebbs[i], computeOnly, ebbi);
return change;
}