<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: arial,helvetica,sans-serif; font-size: 10pt; color: #000000'><br><br><hr id="zwchr"><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>"Michael Kuperstein" <michael.kuperstein@gmail.com><br><b>To: </b>"Hal Finkel" <hfinkel@anl.gov><br><b>Cc: </b>"Sanjay Patel" <spatel@rotateright.com>, "llvm-dev" <llvm-dev@lists.llvm.org>, "Michael Kuperstein" <mkuper@google.com><br><b>Sent: </b>Thursday, December 15, 2016 1:13:07 AM<br><b>Subject: </b>Re: [llvm-dev] analysis based on nonnull attribute<br><br><div dir="ltr">I think what Sanjay is getting at is that it's not an integer, it's still a pointer - but it's not clear where information about non-nullness of the pointer should be propagated to.<div><br><div>In this particular case, since the def of %x in the caller is also an argument, we could propagate it to the def directly, e.g.</div><div><br></div><div><span style="color: rgb(0, 0, 0); font-family: helvetica,arial,sans-serif; font-size: 16px;">define i1 @foo(i32* nonnull %x) {</span><br style="color: rgb(0, 0, 0); font-family: helvetica,arial,sans-serif; font-size: 16px;"><span style="color: rgb(0, 0, 0); font-family: helvetica,arial,sans-serif; font-size: 16px;">  %y.i = load i32, i32* %x   ; inlined, still known to be nonnull</span><br></div><div><span style="color: rgb(0, 0, 0); font-family: helvetica,arial,sans-serif; font-size: 16px;"><br></span></div>And if the def of %x was a load, we could use !nonnull. But I'm not sure what we can do in the general case (say, %x = select...).</div><div id="DWT59679">The best I can think of is generating an llvm.assume for the condition.</div></div></blockquote>True. In this case, the preferred thing would be to add the nonnull attribute to the caller's parameter. Adding llvm.assume is indeed a general solution.<br><br> -Hal<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 dir="ltr"><div></div><div><br></div><div>Michael</div><div class="gmail_extra"><br><div class="gmail_quote">On 14 December 2016 at 14:05, Hal Finkel via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 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);"><br><hr id="m_-7730040808428572051m_-2858323345671407143zwchr"><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" <<a href="mailto:spatel@rotateright.com" target="_blank">spatel@rotateright.com</a>><br><b>To: </b>"Hal Finkel" <<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>><br><b>Cc: </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 4:03:40 PM<br><b>Subject: </b>Re: [llvm-dev] analysis based on nonnull attribute<div><div class="m_-7730040808428572051h5"><br><br><div dir="ltr"><br><div id="m_-7730040808428572051m_-2858323345671407143DWT51043" 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="m_-7730040808428572051m_-2858323345671407143gmail-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="m_-7730040808428572051m_-2858323345671407143gmail-"><br><br><div id="m_-7730040808428572051m_-2858323345671407143gmail-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" target="_blank">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="m_-7730040808428572051m_-2858323345671407143gmail-"><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="m_-7730040808428572051m_-2858323345671407143gmail-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="m_-7730040808428572051m_-2858323345671407143gmail-HOEnZb"><font color="#888888"><div><span></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="m_-7730040808428572051m_-2858323345671407143gmail-docutils m_-7730040808428572051m_-2858323345671407143gmail-literal"><span class="m_-7730040808428572051m_-2858323345671407143gmail-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="m_-7730040808428572051m_-2858323345671407143gmail-docutils m_-7730040808428572051m_-2858323345671407143gmail-literal"><span class="m_-7730040808428572051m_-2858323345671407143gmail-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></div></div></div></div></blockquote>True, but we have range metadata for integers.<br><br> -Hal<span><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 dir="ltr"><div class="gmail_extra"><br><br></div></div>
</blockquote><br><br><br>-- <br><div><span></span>Hal Finkel<br>Lead, Compiler Technology and Programming Languages<br>Leadership Computing Facility<br>Argonne National Laboratory<span></span><br></div></span></div></div><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>
</blockquote><br><br><br>-- <br><div><span name="x"></span>Hal Finkel<br>Lead, Compiler Technology and Programming Languages<br>Leadership Computing Facility<br>Argonne National Laboratory<span name="x"></span><br></div></div></body></html>