<div dir="ltr"><div><div><div>Hi, <br><br></div>I'm trying to optimize a simple C code and came across a situation where invariant code is not being moved out:<br><br></div>On an -O3 compilation, I noticed that the "load" for the loop bounds (which remain invariant throughout) happens on each iteration of both the loops, even though it is not modified anywhere in the function "bigLoop". It seems that alias analysis is not able to say that the writes to one field in the structure does not impact the other field, leading to LICM being ineffective.<br><br></div>Do any of the alias analyses currently have some kind of field sensitivity that can help in this case?<br><div><div><div><div><div><br></div><div>------------------------- test case ------------------------------------<br></div><div>#include <stdlib.h><br>#include <stdio.h><br><br>#define SIZE 100<br><br>struct AS {<br>  int a[SIZE+4];<br>  int size;<br>} A;<br><br>void bigLoop(void)<br>{<br>  unsigned i, j;<br><br>  for (i = 0; i < A.size; i++) {<br>    A.a[i+2] +=  A.a[i];<br>  }<br>  for (i = 0; i < A.size; i++) {<br>    A.a[i+2] *=  A.a[i];<br>  }<br>}<br><br>int main()<br>{<br>  A.size = random()%SIZE;<br>  for (unsigned i = 0; i < A.size; i++) {<br>    A.a[i] = random()%23;<br>  }<br>  bigLoop();<br>  return 0;<br>}<br><br></div><div>Thanks,<br></div><div><br clear="all"><div><div class="gmail_signature"><div dir="ltr">  - Vaivaswatha<br></div></div></div>
</div></div></div></div></div></div>