From: johanknol Date: Sat, 5 Apr 2003 15:17:31 +0000 (+0000) Subject: fixed bug #460088 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=d78670def0d8de75614601941b3e69ce937b2714;p=fw%2Fsdcc fixed bug #460088 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2482 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCcse.c b/src/SDCCcse.c index bc784a21..ea64e30c 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -1401,7 +1401,7 @@ cseBBlock (eBBlock * ebb, int computeOnly, /* if this block is not reachable */ if (ebb->noPath) - return change; + return 0; /* set of common subexpressions */ cseSet = setFromSet (ebb->inExprs); @@ -1521,9 +1521,11 @@ cseBBlock (eBBlock * ebb, int computeOnly, if (SKIP_IC (ic)) continue; - /* do some algebraic optimizations if possible */ - algebraicOpts (ic); - while (constFold (ic, cseSet)); + if (!computeOnly) { + /* do some algebraic optimizations if possible */ + algebraicOpts (ic); + while (constFold (ic, cseSet)); + } /* small klugde */ if (POINTER_GET (ic) && !IS_PTR (operandType (IC_LEFT (ic)))) @@ -1541,7 +1543,7 @@ cseBBlock (eBBlock * ebb, int computeOnly, /* if this is a condition statment then */ /* check if the condition can be replaced */ - if (ic->op == IFX) + if (!computeOnly && ic->op == IFX) { ifxOptimize (ic, cseSet, computeOnly, ebb, &change, @@ -1551,7 +1553,7 @@ cseBBlock (eBBlock * ebb, int computeOnly, /* if the assignment & result is a temp */ /* see if we can replace it */ - if (ic->op == '=') + if (!computeOnly && ic->op == '=') { /* update the spill location for this */ @@ -1635,7 +1637,7 @@ cseBBlock (eBBlock * ebb, int computeOnly, while (constFold (ic, cseSet)); } - /* if after all this it becomes a assignment to self + /* if after all this it becomes an assignment to self then delete it and continue */ if (ASSIGNMENT_TO_SELF (ic)) { @@ -1797,7 +1799,7 @@ cseBBlock (eBBlock * ebb, int computeOnly, /* cseAllBlocks - will sequentially go thru & do cse for all blocks */ /*-----------------------------------------------------------------*/ int -cseAllBlocks (eBBlock ** ebbs, int count) +cseAllBlocks (eBBlock ** ebbs, int count, int computeOnly) { int i; int change = 0; @@ -1805,7 +1807,7 @@ cseAllBlocks (eBBlock ** ebbs, int count) /* if optimization turned off */ for (i = 0; i < count; i++) - change += cseBBlock (ebbs[i], FALSE, ebbs, count); + change += cseBBlock (ebbs[i], computeOnly, ebbs, count); return change; } diff --git a/src/SDCCcse.h b/src/SDCCcse.h index f2770b76..b9532c0b 100644 --- a/src/SDCCcse.h +++ b/src/SDCCcse.h @@ -51,7 +51,7 @@ DEFSETFUNC (findPrevIc); DEFSETFUNC (ifOperandsHave); DEFSETFUNC (findCheaperOp); int cseBBlock (eBBlock *, int, eBBlock **, int); -int cseAllBlocks (eBBlock **, int); +int cseAllBlocks (eBBlock **, int, int computeOnly); void ifxOptimize (iCode *, set *, int, eBBlock *, int *, eBBlock **, int); void unsetDefsAndUses (iCode *); void updateSpillLocation (iCode * ic,int); diff --git a/src/SDCCopt.c b/src/SDCCopt.c index 25ca302e..31d2858d 100644 --- a/src/SDCCopt.c +++ b/src/SDCCopt.c @@ -695,6 +695,7 @@ killDeadCode (eBBlock ** ebbs, int count) /* kill this one if required */ if (kill) { + printf ("kill ic %d\n", ic->key); change = 1; gchange++; /* eliminate this */ @@ -830,7 +831,7 @@ eBBlockFromiCode (iCode * ic) dumpEbbsToFileExt (DUMP_RAW1, ebbs, count); /* do common subexpression elimination for each block */ - change = cseAllBlocks (ebbs, saveCount); + change = cseAllBlocks (ebbs, saveCount, FALSE); /* dumpraw if asked for */ if (options.dump_raw) @@ -846,10 +847,15 @@ eBBlockFromiCode (iCode * ic) /* global common subexpression elimination */ if (optimize.global_cse) { - change += cseAllBlocks (ebbs, saveCount); + change += cseAllBlocks (ebbs, saveCount, TRUE); if (options.dump_gcse) dumpEbbsToFileExt (DUMP_GCSE, ebbs, saveCount); } + else + { + // compute the dataflow only + assert(cseAllBlocks (ebbs, saveCount, FALSE)==0); + } /* kill dead code */ kchange = killDeadCode (ebbs, saveCount); @@ -871,7 +877,7 @@ eBBlockFromiCode (iCode * ic) if (lchange || kchange) { computeDataFlow (ebbs, saveCount); - change += cseAllBlocks (ebbs, saveCount); + change += cseAllBlocks (ebbs, saveCount, TRUE); if (options.dump_loop) dumpEbbsToFileExt (DUMP_LOOPG, ebbs, count);