<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jul 29, 2014 at 6:14 PM, Sean Silva <span dir="ltr"><<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Did you mean to phrase this as a proposed approach and ask for feasibility?</div>
</blockquote><div>Yes.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>
Or are you more interested in the question "Rust has these language semantics, how can I get LLVM to best exploit this?"? LLVM may have an existing mechanism which would serve your needs.</div></div></blockquote>
<div>I am interested in that as well. Rust has the very nice property where references never alias, with the exception of references to UnsafeCell.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr">
<div><br></div><div>Do you have some concrete examples of IR produced by the Rust frontend that you are seeing LLVM not optimize as well as it could?</div></div></blockquote><div>An example my proposed approach would solve if the Rust frontend was modified to output !inheritalias metadata:</div>
<div><div><br></div><div>!0 = metadata !{}</div><div><br></div><div>define void @foo(i8** noalias nocapture readonly %g) {</div><div>  %1 = load i8** %g, align 8, !inheritalias !0</div><div>  %2 = load i8* %1, align 1</div>
<div>  tail call void @bar(i8 signext %2)</div><div>  %3 = load i8** %g, align 8, !inheritalias !0</div><div>  %4 = load i8* %3, align 1</div><div>  tail call void @bar(i8 signext %4)</div><div>  ret void</div><div>}</div>
<div><br></div><div>declare void @bar(i8 signext)</div></div><div><br></div><div>With this metadata LLVM could infer that %1 and %3 doesn't alias with anything since %g doesn't and optimize @foo to:</div><div><br>
</div><div>define void @foo(i8** noalias nocapture readonly %g) {</div><div>  %1 = load i8** %g, align 8, !inheritalias !0</div><div>  %2 = load i8* %1, align 1</div><div>  tail call void @bar(i8 signext %2)</div><div>  tail call void @bar(i8 signext %2)</div>
<div>  ret void</div><div>}</div><div> </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div><br></div><div>-- Sean Silva</div></div><div class="gmail_extra">
<br><br><div class="gmail_quote"><div class="">On Mon, Jul 28, 2014 at 6:35 PM, John Kåre Alsaker <span dir="ltr"><<a href="mailto:john.mailinglists@gmail.com" target="_blank">john.mailinglists@gmail.com</a>></span> wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="">
<div dir="ltr">Since Rust references usually never aliases it would be nice if we could exploit this for code generation. One idea I had to improve alias analysis is to insert metadata on pointer loads. !inheritalias could be added to load instructions to indicate that if we know all the aliases of the pointer we load from, then we also know all the aliases of the pointer value loaded. Given that pointer loads are common and things are likely marked with `noalias` in Rust, this seems like useful metadata. It could also for example apply to loading C++'s unique_ptr fields.<br>


<div><br></div><div>I'm wondering what the feasibility of extending BasicAliasAnalysis to utilize the proposed metadata would be.</div></div>
<br></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></blockquote></div><br></div>
</blockquote></div><br></div></div>