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

             Bug #: 50286
           Summary: Missed optimization, fails to propagate bool
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: gmaxw...@gmail.com


GCC 4.7.0 (and prior) are unable to determine maximum loop counts in code that
looks like:

#include <stdio.h>
int main(int argc, char **argv)
{
  int i;
  const int flag=argc>1;
  i=0;
  do{
    printf("%d\n",i*i);
  }while(++i<1+flag);
  return 0;
}

and so it doesn't unroll the loop.

If 1+flag is changed to 1+!!flag, 1+(bool)flag, or 1+(argc>1) then -O3 unrolls
the loop.

Interestingly, making flag type bool doesn't fix it and also doesn't unroll in
the 1+!!flag case.

Reply via email to