Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC can't vectorize this simple loop ('number of iterations cannot be computed') yet managed a similar one in the same code?

So, I have C++ code with this loop:

for(i=0;i<(m-1);i++)    N4[i]=(i+m-1-Rigta[i]-1-N3[i])/N0;

All the quantitiy involved are int's. From GCC's vectorization report I get:

babar.cpp:233: note: ===== analyze_loop_nest =====
babar.cpp:233: note: === vect_analyze_loop_form ===
babar.cpp:233: note: === get_loop_niters ===
babar.cpp:233: note: not vectorized: number of iterations cannot be computed.
babar.cpp:233: note: bad loop form.

I wondering why 'the number of iteration cannot be computed'!? FWIW, m is declared as const int& m. What makes this even more puzzling is that just above in the same code I have:

for(i=1;i<(m-1);i++)    a2[i]=(x[i]+x[i+m-1])*0.5f;

and the loop above gets vectorized just fine (here a2 and x are floats). I'm compiling with the

-Ofast -ftree-vectorizer-verbose=10 -mtune=native -march=native

flags on GCC 4.8.1 on a i7.

Thanks in advance,

Edit:

After @nodakai idea, I tried this:

const int mm = m;
for(i=0;i<(m-1);i++)    N4[i]=(i+m-1-Rigta[i]-1-N3[i])/N0;

this didn't get me quiet there:

babar.cpp:234: note: not vectorized: relevant stmt not supported: D.55255_812 = D.55254_811 / N0_34;
babar.cpp:234: note: bad operation or unsupported loop bound.

so of course, I tried:

const int mm=m;
const float G0=1.0f/(float)N0;
for(i=0;i<(mm-1);i++)   N4[i]=(i+mm-1-Rigta[i]-1-N3[i])*G0;

which then produced:

babar.cpp:235: note: LOOP VECTORIZED.

(e.g. success). Oddly enough, the mm seems necessary(?!).

like image 783
user189035 Avatar asked Oct 21 '22 11:10

user189035


1 Answers

Can you try these two steps and see if there's any differences?

  1. insert const int mm = m; just before the loop.
  2. replace all the occurences of m with mm.
like image 63
nodakai Avatar answered Oct 23 '22 10:10

nodakai