I was wondering how exactly GCC unrolls loops. Like I can imagine if you have:
it can just put a 100nd times a(). But what if you have:Code:for (int i=0; i<100; ++i) {a();};
so the compiler won't know the value of max. Can this loop be unrolled with -O3 -funroll-all-loops? Is there a way for the compiler to optimize this loop in terms of speed?Code:int max; .... for (int i=0; i<max; ++i) {a();};
If you have two loops like:
is there any way to merge somehow the loops to gain speed?Code:for (int j=0; j<maxj; ++j) for (int i=0; i<maxi; ++i) { a(); };