<div dir="ltr">On Sat, Jan 5, 2013 at 6:17 AM, Somenath Chakraborty <span dir="ltr"><<a href="mailto:some.chak@gmail.com" target="_blank">some.chak@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote">I completely agree with you.</div><div class="gmail_quote"> </div><div class="gmail_quote">The source code I wrote here has the main function and is a complete code. That's why I was expecting load/store analysis could have been incorporated across the module. Thanks.</div>
</blockquote><div><br></div><div style>Clang doesn't know it's a complete program.  You only told it to compile to IR, so it has no idea what it will link against.  I could write another C file with "extern int a" and link these two together.</div>
<div style><br></div><div style>Now if you use static, e.g. "static int a, b, c;", then clang does optimize them away.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_quote"> </div><div class="HOEnZb"><div class="h5">
<div class="gmail_quote"> </div><div class="gmail_quote">On Fri, Jan 4, 2013 at 10:43 PM, Daniel Berlin <span dir="ltr"><<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>></span> wrote:<br>

<blockquote style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid" class="gmail_quote">I'm not sure what you mean by "use" check.<br>


If you compile this with LTO and multiple modules, and guarantee that<br>
you have the main function, yes, you could optimize this.<br>
In all other cases, it's not possible to eliminate any of the<br>
remaining loads or stores you see, because you have no guarantee about<br>
what else could read it.<br>
<br>
Heck, a conforming implementation of printf could read from any of<br>
these globals, so you don't even need other modules.<br>
<div><div><br>
<br>
<br>
<br>
<br>
On Fri, Jan 4, 2013 at 11:45 AM, Somenath Chakraborty<br>
<<a href="mailto:some.chak@gmail.com" target="_blank">some.chak@gmail.com</a>> wrote:<br>
> Thanks for your reply. So, we don't do any "use" check (for globals<br>
> variables) beyond a module scope. If so, it answers my question.<br>
><br>
> On Fri, Jan 4, 2013 at 6:53 PM, Justin Holewinski<br>
> <<a href="mailto:justin.holewinski@gmail.com" target="_blank">justin.holewinski@gmail.com</a>> wrote:<br>
>><br>
>> Since a, b, and c are globals, how does the optimize *know* they are not<br>
>> used elsewhere (e.g. another module)?<br>
><br>
><br>
><br>
</div></div><div><div>> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div>
</div></div>