Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Chandan_G
Beginner
55 Views

icc is not performing loop invariant code motion

Can someone explain the reason why icc is not doing loop invariant code motion (of moving pointer assignment of a) in code 1 below. I see a 40% improvement in performance when the a pointer assignment is moved out of the t6 loop as done in code 2. I tried to mark the pointer 'a' as a const and restrict, to let the compiler know that the pointer 'a' will not be changed inside t6 loop. I am compiling code with '-ansi-alias' , '-03' and '-ipo' option in icc.

[cpp]

//code 1

for(t4=256*t1; t4<=256*t1+254; t4++){

int lbv=256*t2; int ubv=256*t2+255;

for(t6=lbv; t6<=ubv; t6++){

double*restrictconst a= a_trans[lbv/256];//loop invariant code

a[t6-lbv]=a[t6-lbv]/a[t6-lbv];

}

}

//code 2

for(t4=256*t1; t4<=256*t1+254; t4++){

int lbv=256*t2; int ubv=256*t2+255;

double*restrict const a= a_trans[lbv/256];

for(t6=lbv; t6<=ubv; t6++){

a[t6-lbv]=a[t6-lbv]/a[t6-lbv];

}}

[/cpp]

This code is generated by a source to source translator. It is very tedious to manually apply this transformation for lots of loops.  I have marked  'a_trans' as const/restrict with in the function. 

Is there any other keyword that I can use to let icc know that 'a_trans' will not be changed with loop?

0 Kudos
1 Reply
QIAOMIN_Q_
New Contributor I
55 Views

As i can remembe ,you can try "__attribute__(vector(uniform(a_trans[lbv/256])))" before the loop when vectorizing. Generally ,under -O3 + vec  the invariant optimization is enabled .Could you provide your suspected sub-optimal code here? it would encourage more people help you then.

 

 

Reply