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



             Bug #: 55860

           Summary: Turn segmented iteration into nested loops

    Classification: Unclassified

           Product: gcc

           Version: 4.8.0

            Status: UNCONFIRMED

          Keywords: missed-optimization

          Severity: enhancement

          Priority: P3

         Component: tree-optimization

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: gli...@gcc.gnu.org





Hello,



in the code below (compiled with g++ -O3), replacing L2 with L1 in the goto

lets gcc generate much better code (the loop on iii never tests jkl), whereas

with L2 it performs the redundant test every time. I have no idea how hard it

would be to teach gcc to notice that. This kind of code appears in C++ when we

define an iterator that iterates over the elements of several containers

successively.



void f(int,int);

void g(int n,int m){

  int iii=0;

  int jkl=0;

  while(jkl<n)

  {

L1:

    if(iii<m)

    {

      f(jkl,iii);

      ++iii;

      goto L2;

    }

    else

    {

      ++jkl;

      iii=0;

    }

L2:;

  }

}

Reply via email to