[Bug tree-optimization/58915] New: [missed optimization] GCC fails to get the loop bound for some loops.

congh at google dot com gcc-bugzilla@gcc.gnu.org
Tue Oct 29 20:08:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58915

            Bug ID: 58915
           Summary: [missed optimization] GCC fails to get the loop bound
                    for some loops.
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: congh at google dot com

Getting the correct loop upper bound is important for some optimizations. GCC
tries to get this bound by calling bound_difference() in
tree-ssa-loop-niters.c, where GCC finds all control-dependent predicates of the
loop and attempt to extract bound information from each predicate. 

However, GCC fails to get the bound for some loops. Below shows such an
example:

unsigned int i;
if (i > 0) {
   ...
   if (i < 4) {
      do {
         ...
         --i;
      } while (i > 0);
   }
}

Clearly the upper bound is 3. But GCC could not get it for this loop. The
reason is that GCC check i<4 (i could be zero) and i>0 separately and from
neither condition can the upper bound be calculated. Those two conditions may
not be combined into one as there may exist other statements between them. 

One possible solution is letting GCC collect all conditions first then merge
them before calculating the upper bound.


Any comments?



More information about the Gcc-bugs mailing list