<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 14, 2016 at 2:51 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><br><div style="font-family:arial,helvetica,sans-serif;font-size:10pt;color:rgb(0,0,0)"><br><hr id="gmail-m_3630810500302298505zwchr"><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:helvetica,arial,sans-serif;font-size:12pt"><b>From: </b>"Sanjay Patel via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br><b>To: </b>"llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br><b>Sent: </b>Wednesday, December 14, 2016 3:47:03 PM<br><b>Subject: </b>[llvm-dev] analysis based on nonnull attribute<span class="gmail-"><br><br><div id="gmail-m_3630810500302298505DWT50626" dir="ltr">Does the nonnull parameter attribute give us information about subsequent uses of that value outside of the function that has the attribute? <br></div></span></blockquote>Yes. We're guaranteeing that we never pass a null value for the argument, so that information can be used to optimize the caller as well.</div></div></blockquote><div><br></div><div>Thanks! I don't know if that will actually solve our sub-optimal output for dyn_cast (!), but it might help...<br><a href="https://llvm.org/bugs/show_bug.cgi?id=28430">https://llvm.org/bugs/show_bug.cgi?id=28430</a><br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:10pt;color:rgb(0,0,0)"><span class="gmail-"><br><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:helvetica,arial,sans-serif;font-size:12pt"><div id="gmail-m_3630810500302298505DWT50627" dir="ltr"><br>Example:<br><br>define i1 @bar(i32* nonnull %x) { ; %x must be non-null in this function<br> %y = load i32, i32* %x<br> %z = icmp ugt i32 %y, 23<br> ret i1 %z<br>}<br><br>define i1 @foo(i32* %x) {<br> %d = call i1 @bar(i32* %x)<br> %null_check = icmp eq i32* %x, null ; check if null after call that guarantees non-null?<br> br i1 %null_check, label %t, label %f<br>t:<br> ret i1 1<br>f:<br> ret i1 %d<br>}<br><br>$ opt -inline nonnull.ll -S<br>...<br>define i1 @foo(i32* %x) {<br> %y.i = load i32, i32* %x ; inlined and non-null knowledge is lost?<br></div></blockquote></span>It should be replaced by !nonnull metadata on the load. We might not be doing that today, however.<span class="gmail-HOEnZb"><font color="#888888"><div><span name="x"></span></div></font></span><br></div></div></blockquote><div><br>We can't tag this load with !nonnull though because this isn't a load of the pointer?<br>"The existence of the <code class="gmail-docutils gmail-literal"><span class="gmail-pre">!nonnull</span></code> metadata on the
instruction tells the optimizer that the value loaded is known to
never be null. This is analogous to the <code class="gmail-docutils gmail-literal"><span class="gmail-pre">nonnull</span></code> attribute
on parameters and return values. This metadata can only be applied
to loads of a pointer type." <br></div></div><br><br><br></div></div>