<div dir="ltr"><div>What are you actually trying to achieve? <br><br>I would have thought that [once it gets optimised enough], the compiler does that, or something similar anyway [in particular `*aux++ = i;` would be what I'd expect to see]. <br></div><div>(Obviously, with global variables, there's always a bit of a problem if the compiler believes that some other code may change `vectorE` during the execution of `foo`, and what is expected to happen if that is the case)<br></div><div><br>--<br></div>Mats<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 2 February 2016 at 16:35, Gleison Souza via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div style="font-size:13px">Dear LLVMers,</div><div style="font-size:13px"><br></div><div style="font-size:13px"> I am trying to implement a particular type of loop optimization, but I am having problems with global variables. To solve this problem, I would like to know if LLVM has some pass that moves loads outside loops. I will illustrate with an example. I want to transform this code below. I am writing in C for readability, but I am analysing LLVM IR:</div><div style="font-size:13px"><br></div><div style="font-size:13px">int *vectorE;</div><div style="font-size:13px"><br></div><div style="font-size:13px">void foo (int n) { </div><div style="font-size:13px"> int i;</div><div style="font-size:13px"> for (i = 0; i < n; i++)</div><div style="font-size:13px"> vectorE[i] = i;</div><div style="font-size:13px">}</div><div style="font-size:13px"><br></div><div style="font-size:13px">into this one:</div><div style="font-size:13px"><br></div><div style="font-size:13px">int *vectorE;</div><div style="font-size:13px"><br></div><div style="font-size:13px">void foo (int n) { </div><div style="font-size:13px"> int i;</div><div style="font-size:13px"> int* aux = vectorE;</div><div style="font-size:13px"> for (i = 0; i < n; i++)</div><div style="font-size:13px"> aux[i] = i;</div><div style="font-size:13px">}</div><div style="font-size:13px"><br></div><div style="font-size:13px">Regards,</div><div style="font-size:13px"><br></div><div style="font-size:13px">Gleison</div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>