icc is not performing loop invariant code motion

icc is not performing loop invariant code motion

Chandan G's picture

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.

//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];
}}

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?

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
QIAOMIN Q. (Intel)'s picture

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.

 

 

Login to leave a comment.