From: MaartenBrock Date: Sat, 13 Oct 2007 18:27:11 +0000 (+0000) Subject: * src/mcs51/gen.c (leftRightUseAcc): use macro IS_OP_ACCUSE X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=ea2c54ecaa2ebd7f1e67754a02e316ac1d7ac912;p=fw%2Fsdcc * src/mcs51/gen.c (leftRightUseAcc): use macro IS_OP_ACCUSE * src/SDCCast.c (decorateType): optimize bit=cond?1:0, RFE 1738430 * support/regression/tests/bug-223113.c, * support/regression/tests/bug-426632.c, * support/regression/tests/bug-468811.c, * support/regression/tests/bug-477835.c, * support/regression/tests/bug-478094.c, * support/regression/tests/bug-499644.c, * support/regression/tests/bug-524209.c, * support/regression/tests/bug-524211.c, * support/regression/tests/packcast.c, * support/regression/tests/structidx.c: added empty tests * support/regression/tests/bug-607243.c: enabled test git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4930 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 91d9befd..8f2ee13e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2007-10-13 Maarten Brock + + * src/mcs51/gen.c (leftRightUseAcc): use macro IS_OP_ACCUSE + * src/SDCCast.c (decorateType): optimize bit=cond?1:0, RFE 1738430 + * support/regression/tests/bug-223113.c, + * support/regression/tests/bug-426632.c, + * support/regression/tests/bug-468811.c, + * support/regression/tests/bug-477835.c, + * support/regression/tests/bug-478094.c, + * support/regression/tests/bug-499644.c, + * support/regression/tests/bug-524209.c, + * support/regression/tests/bug-524211.c, + * support/regression/tests/packcast.c, + * support/regression/tests/structidx.c: added empty tests + * support/regression/tests/bug-607243.c: enabled test + 2007-10-06 Borut Razem * .version, doc/sdccman.lyx: bumped version to 2.7.4 to indicate the full diff --git a/src/SDCCast.c b/src/SDCCast.c index 2fb213e9..339aa2ae 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -1225,7 +1225,7 @@ ast * initAggregates (symbol * sym, initList * ival, ast * wid) { /*-----------------------------------------------------------------*/ /* gatherAutoInit - creates assignment expressions for initial */ -/* values */ +/* values */ /*-----------------------------------------------------------------*/ static ast * gatherAutoInit (symbol * autoChain) @@ -2535,7 +2535,7 @@ decorateType (ast * tree, RESULT_TYPE resultType) upon tree->opval.op, if resultType can be propagated */ resultTypeProp = resultTypePropagate (tree, resultType); - if (tree->opval.op == '?') + if ((tree->opval.op == '?') && (resultTypeProp != RESULT_TYPE_BIT)) dtl = decorateType (tree->left, RESULT_TYPE_IFX); else dtl = decorateType (tree->left, resultTypeProp); @@ -3650,7 +3650,7 @@ decorateType (ast * tree, RESULT_TYPE resultType) { if ((resultType == RESULT_TYPE_IFX) || (resultType == RESULT_TYPE_BIT)) { - /* remove double '!!X' by 'X' */ + /* replace double '!!X' by 'X' */ return tree->left->left; } /* remove double '!!X' by 'X ? 1 : 0' */ @@ -4369,6 +4369,19 @@ decorateType (ast * tree, RESULT_TYPE resultType) /* the type is value of the colon operator (on the right) */ assert (IS_COLON_OP (tree->right)); + /* If already known then replace the tree : optimizer will do it + but faster to do it here. If done before decorating tree->right + this can save generating unused const strings. */ + if (IS_LITERAL (LTYPE (tree))) + { + if (((int) ulFromVal (valFromType (LETYPE (tree)))) != 0) + return decorateType (tree->right->left, resultTypeProp); + else + return decorateType (tree->right->right, resultTypeProp); + } + + tree->right = decorateType (tree->right, resultTypeProp); + if (IS_AST_LIT_VALUE (tree->right->left) && IS_AST_LIT_VALUE (tree->right->right)) { double valTrue = AST_LIT_VALUE (tree->right->left); @@ -4378,6 +4391,7 @@ decorateType (ast * tree, RESULT_TYPE resultType) ((resultType == RESULT_TYPE_IFX) || (resultType == RESULT_TYPE_BIT))) { /* assign cond to result */ + tree->left->decorated = 0; return decorateType (tree->left, resultTypeProp); } else if ((valTrue == 0) && (valFalse == 1)) @@ -4391,27 +4405,13 @@ decorateType (ast * tree, RESULT_TYPE resultType) } /* if they are equal then replace the tree */ - if (!astHasVolatile (tree->right) && - isAstEqual (tree->right->left, tree->right->right)) + if (isAstEqual (tree->right->left, tree->right->right)) { - return decorateType (tree->right->left, resultTypeProp); + return tree->right->left; } - /* if already known then replace the tree : optimizer will do it - but faster to do it here */ - if (IS_LITERAL (LTYPE (tree))) - { - if (((int) ulFromVal (valFromType (LETYPE (tree)))) != 0) - return decorateType (tree->right->left, resultTypeProp); - else - return decorateType (tree->right->right, resultTypeProp); - } - else - { - tree->right = decorateType (tree->right, resultTypeProp); - TTYPE (tree) = RTYPE (tree); - TETYPE (tree) = getSpec (TTYPE (tree)); - } + TTYPE (tree) = RTYPE (tree); + TETYPE (tree) = getSpec (TTYPE (tree)); return tree; case ':': diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 8a28956b..f4016b75 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -543,7 +543,7 @@ leftRightUseAcc(iCode *ic) if (ic->op == IFX) { op = IC_COND (ic); - if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse) + if (IS_OP_ACCUSE (op)) { accuse = 1; size = getSize (OP_SYMBOL (op)->type); @@ -554,7 +554,7 @@ leftRightUseAcc(iCode *ic) else if (ic->op == JUMPTABLE) { op = IC_JTCOND (ic); - if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse) + if (IS_OP_ACCUSE (op)) { accuse = 1; size = getSize (OP_SYMBOL (op)->type); @@ -565,7 +565,7 @@ leftRightUseAcc(iCode *ic) else { op = IC_LEFT (ic); - if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse) + if (IS_OP_ACCUSE (op)) { accuse = 1; size = getSize (OP_SYMBOL (op)->type); @@ -573,7 +573,7 @@ leftRightUseAcc(iCode *ic) accuseSize = size; } op = IC_RIGHT (ic); - if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse) + if (IS_OP_ACCUSE (op)) { accuse = 1; size = getSize (OP_SYMBOL (op)->type); diff --git a/support/regression/tests/bug-223113.c b/support/regression/tests/bug-223113.c index aacf1387..d0642417 100644 --- a/support/regression/tests/bug-223113.c +++ b/support/regression/tests/bug-223113.c @@ -3,23 +3,27 @@ */ #include -int putch( int Ch ) -{ - return( Ch ); -} +int putch( int Ch ) +{ + return( Ch ); +} + +int puts( char *Str ) +{ + char *Ptr; -int puts( char *Str ) -{ - char *Ptr; - for( Ptr = Str; *Ptr != '\0'; Ptr++ ) { - putch( *Ptr ); - } - - return( (Ptr - Str) ); -} + putch( *Ptr ); + } + + return( (Ptr - Str) ); +} + +void __main( void ) +{ + puts( "hello world\n" ); +} -void __main( void ) -{ - puts( "hello world\n" ); +void testBug(void) +{ } diff --git a/support/regression/tests/bug-426632.c b/support/regression/tests/bug-426632.c index ff9db32b..5a895470 100644 --- a/support/regression/tests/bug-426632.c +++ b/support/regression/tests/bug-426632.c @@ -3,35 +3,39 @@ */ #include -typedef struct { - unsigned char year; /* Current year (with offset 1900) */ - unsigned char month; /* Month (1 = Jan., ..., 12 = Dec.) */ - unsigned char day; /* Day of month (1 to 31) */ -} DATE_STRUCT; +typedef struct { + unsigned char year; /* Current year (with offset 1900) */ + unsigned char month; /* Month (1 = Jan., ..., 12 = Dec.) */ + unsigned char day; /* Day of month (1 to 31) */ +} DATE_STRUCT; -unsigned char year; -unsigned char month; -unsigned char day; +unsigned char year; +unsigned char month; +unsigned char day; void *__main() -{ - float i; - float y; - void *p; - DATE_STRUCT d; - DATE_STRUCT *date_ptr; - - date_ptr = &d; - - year = date_ptr->year; - month = date_ptr->month; - day = date_ptr->day; - - i = 1.35; - i += 2; - y = 1; - y = y+i; - i = y; - p = &y; - return p; -} +{ + float i; + float y; + void *p; + DATE_STRUCT d; + DATE_STRUCT *date_ptr; + + date_ptr = &d; + + year = date_ptr->year; + month = date_ptr->month; + day = date_ptr->day; + + i = 1.35; + i += 2; + y = 1; + y = y+i; + i = y; + p = &y; + return p; +} + +void testBug(void) +{ +} diff --git a/support/regression/tests/bug-468811.c b/support/regression/tests/bug-468811.c index c5454561..b0e3da65 100644 --- a/support/regression/tests/bug-468811.c +++ b/support/regression/tests/bug-468811.c @@ -18,7 +18,7 @@ set_sprite_tile(UINT8 nb, UINT8 tile) #define MIN_SY 5U /* min y (char) */ #define MAX_SY (MIN_SY+13U) /* max y (char) */ -#define DEF_SP 30U /* sprite null char code */ +#define DEF_SP 30U /* sprite null char code */ /* player */ #define MIN_PX (MIN_SX*8U+8U) /* min x (dot) */ @@ -72,3 +72,7 @@ void enemys() } } } + +void testBug(void) +{ +} diff --git a/support/regression/tests/bug-477835.c b/support/regression/tests/bug-477835.c index 294b4198..c8e75ea8 100644 --- a/support/regression/tests/bug-477835.c +++ b/support/regression/tests/bug-477835.c @@ -29,3 +29,7 @@ fptr2(void (*fp)(void)) for (i = 0; i < 50; i++) dummy(fp2); } + +void testBug(void) +{ +} diff --git a/support/regression/tests/bug-478094.c b/support/regression/tests/bug-478094.c index 10158421..74975645 100644 --- a/support/regression/tests/bug-478094.c +++ b/support/regression/tests/bug-478094.c @@ -4,36 +4,40 @@ -int foo = 16; +int foo = 16; void f( int x ) { UNUSED(x); } -void g(int bar) -{ - int a = 0; - int b = 0; +void g(int bar) +{ + int a = 0; + int b = 0; + + while(1) { + switch(bar) { + case 0: + --foo; + f(foo); + break; + case 1: + ++foo; + f(foo); + break; + case 2: + ++a; + f(a); + break; + case 3: + ++b; + f(b); + break; + } + } +} - while(1) { - switch(bar) { - case 0: - --foo; - f(foo); - break; - case 1: - ++foo; - f(foo); - break; - case 2: - ++a; - f(a); - break; - case 3: - ++b; - f(b); - break; - } - } -} +void testBug(void) +{ +} diff --git a/support/regression/tests/bug-499644.c b/support/regression/tests/bug-499644.c index bec16114..caf4815e 100644 --- a/support/regression/tests/bug-499644.c +++ b/support/regression/tests/bug-499644.c @@ -2,9 +2,13 @@ */ #include -const float a = 0.0; +const float a = 0.0; -float f(void) -{ - return a * 5; -} +float f(void) +{ + return a * 5; +} + +void testBug(void) +{ +} diff --git a/support/regression/tests/bug-524209.c b/support/regression/tests/bug-524209.c index a5b215e1..67d2659e 100644 --- a/support/regression/tests/bug-524209.c +++ b/support/regression/tests/bug-524209.c @@ -31,3 +31,6 @@ void checkCast(void *pIn) _scan((StringBuffer *)p); } +void testBug(void) +{ +} diff --git a/support/regression/tests/bug-524211.c b/support/regression/tests/bug-524211.c index 0dee2d1e..3d3128bd 100644 --- a/support/regression/tests/bug-524211.c +++ b/support/regression/tests/bug-524211.c @@ -28,3 +28,7 @@ void foo(void) { } #endif + +void testBug(void) +{ +} diff --git a/support/regression/tests/bug-607243.c b/support/regression/tests/bug-607243.c index 00ed648d..4209454a 100644 --- a/support/regression/tests/bug-607243.c +++ b/support/regression/tests/bug-607243.c @@ -2,15 +2,15 @@ #include -typedef unsigned int u16_t; +typedef unsigned int u16_t; -struct myhdr { u16_t x; } h, *p; +struct myhdr { u16_t x; } h, *p; -#define NTOHS(n) (((((u16_t)(n) & 0xff)) << 8) | (((u16_t)(n) & 0xff00) >> 8)) -#define IPH_V(hdr) ((u16_t)NTOHS((hdr)->x) >> 12) +#define NTOHS(n) (((((u16_t)(n) & 0xff)) << 8) | (((u16_t)(n) & 0xff00) >> 8)) +#define IPH_V(hdr) ((u16_t)NTOHS((hdr)->x) >> 12) -void foo(void) { - p = &h; - p->x = 0x45; +void testBug(void) { + p = &h; + p->x = 0x45; ASSERT(IPH_V(p)==4); -} +} diff --git a/support/regression/tests/packcast.c b/support/regression/tests/packcast.c index f44542d2..86b8a23b 100644 --- a/support/regression/tests/packcast.c +++ b/support/regression/tests/packcast.c @@ -23,3 +23,7 @@ testCastPack(char x) } } } + +void testBug(void) +{ +} diff --git a/support/regression/tests/structidx.c b/support/regression/tests/structidx.c index 9bfca09e..8a7fdcc7 100644 --- a/support/regression/tests/structidx.c +++ b/support/regression/tests/structidx.c @@ -30,3 +30,7 @@ getWidth(void) { return cursors[current_cursor].w; } + +void testBug(void) +{ +}