<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 2, 2016, at 8:35 AM, Gleison Souza via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div style="font-size:13px" class="">Dear LLVMers,</div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class="">    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" class=""><br class=""></div><div style="font-size:13px" class="">int *vectorE;</div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class="">void foo (int n) {       </div><div style="font-size:13px" class="">  int i;</div><div style="font-size:13px" class="">  for (i = 0; i < n; i++)</div><div style="font-size:13px" class="">    vectorE[i] = i;</div><div style="font-size:13px" class="">}</div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class="">into this one:</div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class="">int *vectorE;</div><div style="font-size:13px" class=""><br class=""></div><div style="font-size:13px" class="">void foo (int n) {       </div><div style="font-size:13px" class="">  int i;</div><div style="font-size:13px" class="">  int* aux = vectorE;</div><div style="font-size:13px" class="">  for (i = 0; i < n; i++)</div><div style="font-size:13px" class="">    aux[i] = i;</div><div style="font-size:13px" class="">}</div></div></div></blockquote><div><br class=""></div><div><br class=""></div><div>Have you looked at the output of clang with optimization enabled (even O1)? For this C++ code the optimizer moves the access to the global in the loop preheader, and then the loop itself does not access the global at all, which seems to be what you’re looking for.</div><div><br class=""></div><div>Try: clang -O1 -S -o - -mllvm -print-after-all</div><div><br class=""></div><div>— </div><div>Mehdi</div><div><br class=""></div><div><br class=""></div></div></body></html>