Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 792

Show
Ignore:
Timestamp:
12/08/10 01:08:41 (14 years ago)
Author:
walter
Message:

bugzilla 5294 -O optimization breaks for loop

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmd-1.x/src/backend/el.h

    r728 r792  
    8080            tym_t Ety_;                 // data type (TYxxxx) 
    8181            #define Ety _EU._EO.Ety_ 
    8282            unsigned Eexp_;             // index into expnod[] 
    8383            #define Eexp _EU._EO.Eexp_ 
    8484 
    8585            // These flags are all temporary markers, used once and then 
    8686            // thrown away. 
    8787            unsigned char Nflags_;      // NFLxxx 
    8888            #define Nflags _EU._EO.Nflags_ 
    8989                #define NFLli     1     // loop invariant 
    9090                #define NFLnogoal 2     // evaluate elem for side effects only 
    9191                #define NFLassign 8     // unambiguous assignment elem 
    9292                #define NFLaecp 0x10    // AE or CP or VBE expression 
    9393                #define NFLdelcse 0x40  // this is not the generating CSE 
    9494#if !TX86 
    9595                #define NFLfcall  0x20  // flag that there has been a function call on RHS 
    9696                                        // of an assignment of this LHS value hence do not 
    9797                                        // propagate this assignment into a paramter list 
    9898                                        // (see glocal.c) 
    9999#endif 
     100                #define NFLtouns 0x80   // relational operator was changed from signed to unsigned 
    100101#if MARS 
    101102            unsigned char Ejty_;                // original Jupiter/Mars type 
    102103            #define Ejty _EU._EO.Ejty_ 
    103104#endif 
    104105        }_EO; 
    105106 
    106107        // CODGEN 
    107108        struct 
    108109        { 
    109110            // Ety2: Must be in same position as Ety! 
    110111            tym_t Ety2_;                        // data type (TYxxxx) 
    111112            #define Ety2 _EU._EC.Ety2_ 
    112113            unsigned char Ecomsub_;     // number of remaining references to 
    113114                                        // this common subexp (used to determine 
    114115                                        // first, intermediate, and last references 
    115116                                        // to a CSE) 
    116117            #define Ecomsub _EU._EC.Ecomsub_ 
    117118 
    118119#if TARGET_POWERPC 
    119120            unsigned char Gflags; 
  • branches/dmd-1.x/src/backend/gloop.c

    r768 r792  
    31663166                         c1 & ~0x7FFFL) 
    31673167                       ) 
    31683168                        continue; 
    31693169 
    31703170                    if (sz == LONGSIZE && 
    31713171                        ((ref->E2->Eoper == OPconst && 
    31723172                        c1 * el_tolong(ref->E2) & ~0x7FFFFFFFL) || 
    31733173                         c1 & ~0x7FFFFFFFL) 
    31743174                       ) 
    31753175                        continue; 
    31763176#if LONGLONG && __INTSIZE >= 4 
    31773177                    if (sz == LLONGSIZE && 
    31783178                        ((ref->E2->Eoper == OPconst && 
    31793179                        c1 * el_tolong(ref->E2) & ~0x7FFFFFFFFFFFFFFFLL) || 
    31803180                         c1 & ~0x7FFFFFFFFFFFFFFFLL) 
    31813181                       ) 
    31823182                        continue; 
    31833183#endif 
    31843184                } 
    31853185 
     3186                /* If loop started out with a signed conditional that was 
     3187                 * replaced with an unsigned one, don't do it if c2 
     3188                 * is less than 0. 
     3189                 */ 
     3190                if (ref->Nflags & NFLtouns && fl->c2->Eoper == OPconst) 
     3191                { 
     3192                    targ_llong c2 = el_tolong(fl->c2); 
     3193                    if (c2 < 0) 
     3194                        continue; 
     3195                } 
     3196 
    31863197                elem *refE2 = el_copytree(ref->E2); 
    31873198                int refEoper = ref->Eoper; 
    31883199 
    31893200                /* if c1 < 0 and relop is < <= > >= 
    31903201                   then adjust relop as if both sides were multiplied 
    31913202                   by -1 
    31923203                 */ 
    31933204                if (!tyuns(ty) && 
    31943205                    (tyintegral(ty) && el_tolong(fl->c1) < 0 || 
    31953206#if TARGET_68K && __POWERPC 
    31963207                     tyfloating(ty) && Xlt(el_toldouble(fl->c1),Xzero()) )) 
    31973208#else 
    31983209                     tyfloating(ty) && el_toldouble(fl->c1) < 0.0)) 
    31993210#endif 
    32003211                        refEoper = swaprel(refEoper); 
    32013212 
    32023213                /* Replace (X relop e) with (X relop (short)e) 
    32033214                   if T is 1 word but e is 2 
    32043215                 */ 
    32053216                if (tysize(flty) == SHORTSIZE && 
  • branches/dmd-1.x/src/backend/gother.c

    r609 r792  
    788788//              initial,increment,final); 
    789789 
    790790        /* Determine if we can make the relational an unsigned  */ 
    791791        if (initial >= 0) 
    792792        {   if (final >= initial) 
    793793            {   if (increment > 0 && ((final - initial) % increment) == 0) 
    794794                    goto makeuns; 
    795795            } 
    796796            else if (final >= 0) 
    797797            {   /* 0 <= final < initial */ 
    798798                if (increment < 0 && ((final - initial) % increment) == 0 && 
    799799                    !(final + increment < 0 && 
    800800                        (relatop == OPge || relatop == OPlt) 
    801801                     ) 
    802802                   ) 
    803803                { 
    804804                makeuns: 
    805805                    if (!tyuns(rel->pelem->E2->Ety)) 
    806806                    { 
    807807                        rel->pelem->E2->Ety = touns(rel->pelem->E2->Ety); 
     808                        rel->pelem->Nflags |= NFLtouns; 
    808809#ifdef DEBUG 
    809810                        if (debugc) 
    810811                        {   WReqn(rel->pelem); 
    811812                            dbg_printf(" made unsigned, initial = %ld, increment = %ld,\ 
    812813 final = %ld\n",initial,increment,final); 
    813814                        } 
    814815#endif 
    815816                        changes++; 
    816817                    } 
    817818#if 0 
    818819                    // Eliminate loop if it is empty 
    819820                    if (relatop == OPlt && 
    820821                        rb->BC == BCiftrue && 
    821822                        list_block(rb->Bsucc) == rb && 
    822823                        rb->Belem->Eoper == OPcomma && 
    823824                        rb->Belem->E1 == rdinc && 
    824825                        rb->Belem->E2 == rel->pelem 
    825826                       ) 
    826827                     { 
    827828                        rel->pelem->Eoper = OPeq; 
  • trunk/src/backend/el.h

    r728 r792  
    8080            tym_t Ety_;                 // data type (TYxxxx) 
    8181            #define Ety _EU._EO.Ety_ 
    8282            unsigned Eexp_;             // index into expnod[] 
    8383            #define Eexp _EU._EO.Eexp_ 
    8484 
    8585            // These flags are all temporary markers, used once and then 
    8686            // thrown away. 
    8787            unsigned char Nflags_;      // NFLxxx 
    8888            #define Nflags _EU._EO.Nflags_ 
    8989                #define NFLli     1     // loop invariant 
    9090                #define NFLnogoal 2     // evaluate elem for side effects only 
    9191                #define NFLassign 8     // unambiguous assignment elem 
    9292                #define NFLaecp 0x10    // AE or CP or VBE expression 
    9393                #define NFLdelcse 0x40  // this is not the generating CSE 
    9494#if !TX86 
    9595                #define NFLfcall  0x20  // flag that there has been a function call on RHS 
    9696                                        // of an assignment of this LHS value hence do not 
    9797                                        // propagate this assignment into a paramter list 
    9898                                        // (see glocal.c) 
    9999#endif 
     100                #define NFLtouns 0x80   // relational operator was changed from signed to unsigned 
    100101#if MARS 
    101102            unsigned char Ejty_;                // original Jupiter/Mars type 
    102103            #define Ejty _EU._EO.Ejty_ 
    103104#endif 
    104105        }_EO; 
    105106 
    106107        // CODGEN 
    107108        struct 
    108109        { 
    109110            // Ety2: Must be in same position as Ety! 
    110111            tym_t Ety2_;                        // data type (TYxxxx) 
    111112            #define Ety2 _EU._EC.Ety2_ 
    112113            unsigned char Ecomsub_;     // number of remaining references to 
    113114                                        // this common subexp (used to determine 
    114115                                        // first, intermediate, and last references 
    115116                                        // to a CSE) 
    116117            #define Ecomsub _EU._EC.Ecomsub_ 
    117118 
    118119#if TARGET_POWERPC 
    119120            unsigned char Gflags; 
  • trunk/src/backend/gloop.c

    r768 r792  
    31663166                         c1 & ~0x7FFFL) 
    31673167                       ) 
    31683168                        continue; 
    31693169 
    31703170                    if (sz == LONGSIZE && 
    31713171                        ((ref->E2->Eoper == OPconst && 
    31723172                        c1 * el_tolong(ref->E2) & ~0x7FFFFFFFL) || 
    31733173                         c1 & ~0x7FFFFFFFL) 
    31743174                       ) 
    31753175                        continue; 
    31763176#if LONGLONG && __INTSIZE >= 4 
    31773177                    if (sz == LLONGSIZE && 
    31783178                        ((ref->E2->Eoper == OPconst && 
    31793179                        c1 * el_tolong(ref->E2) & ~0x7FFFFFFFFFFFFFFFLL) || 
    31803180                         c1 & ~0x7FFFFFFFFFFFFFFFLL) 
    31813181                       ) 
    31823182                        continue; 
    31833183#endif 
    31843184                } 
    31853185 
     3186                /* If loop started out with a signed conditional that was 
     3187                 * replaced with an unsigned one, don't do it if c2 
     3188                 * is less than 0. 
     3189                 */ 
     3190                if (ref->Nflags & NFLtouns && fl->c2->Eoper == OPconst) 
     3191                { 
     3192                    targ_llong c2 = el_tolong(fl->c2); 
     3193                    if (c2 < 0) 
     3194                        continue; 
     3195                } 
     3196 
    31863197                elem *refE2 = el_copytree(ref->E2); 
    31873198                int refEoper = ref->Eoper; 
    31883199 
    31893200                /* if c1 < 0 and relop is < <= > >= 
    31903201                   then adjust relop as if both sides were multiplied 
    31913202                   by -1 
    31923203                 */ 
    31933204                if (!tyuns(ty) && 
    31943205                    (tyintegral(ty) && el_tolong(fl->c1) < 0 || 
    31953206#if TARGET_68K && __POWERPC 
    31963207                     tyfloating(ty) && Xlt(el_toldouble(fl->c1),Xzero()) )) 
    31973208#else 
    31983209                     tyfloating(ty) && el_toldouble(fl->c1) < 0.0)) 
    31993210#endif 
    32003211                        refEoper = swaprel(refEoper); 
    32013212 
    32023213                /* Replace (X relop e) with (X relop (short)e) 
    32033214                   if T is 1 word but e is 2 
    32043215                 */ 
    32053216                if (tysize(flty) == SHORTSIZE && 
  • trunk/src/backend/gother.c

    r609 r792  
    788788//              initial,increment,final); 
    789789 
    790790        /* Determine if we can make the relational an unsigned  */ 
    791791        if (initial >= 0) 
    792792        {   if (final >= initial) 
    793793            {   if (increment > 0 && ((final - initial) % increment) == 0) 
    794794                    goto makeuns; 
    795795            } 
    796796            else if (final >= 0) 
    797797            {   /* 0 <= final < initial */ 
    798798                if (increment < 0 && ((final - initial) % increment) == 0 && 
    799799                    !(final + increment < 0 && 
    800800                        (relatop == OPge || relatop == OPlt) 
    801801                     ) 
    802802                   ) 
    803803                { 
    804804                makeuns: 
    805805                    if (!tyuns(rel->pelem->E2->Ety)) 
    806806                    { 
    807807                        rel->pelem->E2->Ety = touns(rel->pelem->E2->Ety); 
     808                        rel->pelem->Nflags |= NFLtouns; 
    808809#ifdef DEBUG 
    809810                        if (debugc) 
    810811                        {   WReqn(rel->pelem); 
    811812                            dbg_printf(" made unsigned, initial = %ld, increment = %ld,\ 
    812813 final = %ld\n",initial,increment,final); 
    813814                        } 
    814815#endif 
    815816                        changes++; 
    816817                    } 
    817818#if 0 
    818819                    // Eliminate loop if it is empty 
    819820                    if (relatop == OPlt && 
    820821                        rb->BC == BCiftrue && 
    821822                        list_block(rb->Bsucc) == rb && 
    822823                        rb->Belem->Eoper == OPcomma && 
    823824                        rb->Belem->E1 == rdinc && 
    824825                        rb->Belem->E2 == rel->pelem 
    825826                       ) 
    826827                     { 
    827828                        rel->pelem->Eoper = OPeq;