<div dir="ltr"><div>Thanks Mehdi,</div><div><br></div><div>I tried to use this, but some debug information can be lost in these optimizations.</div><div>I need write in the source file to insert information before the loops, and in</div><div>some cases, I'm writing after the loop header.</div><div><br></div><div>Please, take a look:</div><div><br></div><div>int foo1 (int *a, int *b, int n) {                                               </div><div>  int i, s= 0;                                                                   </div><div>  for (i = 0; i < n; i++) {                                                      </div><div>    s = s * a[i];                                                                </div><div>  }                                                                              </div><div>                                                                               </div><div>  for (i = 0; i < n; i++) {                                                      </div><div>    b[i] = a[i] + 3;                                                             </div><div>    s += a[i];                                                                   </div><div>   }                                                                              </div><div>  return s;                                                                      </div><div>} </div><div><br></div><div>In this case, using the line obtained by this one in the LLVM's IR:</div><div><br></div><div>Line = l->getStartLoc().getLine(); </div><div><br></div><div>The source file is cloned, and I'm writing my annotations inside the loop now.</div><div>I can't do several modifications in the struct of code, just the necessary, thats the problem.</div><div><br></div><div>Regards,</div><div><br></div><div>    Gleison</div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-02-03 1:07 GMT-02:00 Mehdi Amini <span dir="ltr"><<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Feb 2, 2016, at 8:35 AM, Gleison Souza via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br><div><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></div></blockquote><div><br></div><div><br></div></span><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></div><div>Try: clang -O1 -S -o - -mllvm -print-after-all</div><div><br></div><div>— </div><span class="HOEnZb"><font color="#888888"><div>Mehdi</div><div><br></div><div><br></div></font></span></div></div></blockquote></div><br></div>