<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><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>"Sanjay Patel via llvm-dev" <llvm-dev@lists.llvm.org><br><b>To: </b>"llvm-dev" <llvm-dev@lists.llvm.org><br><b>Sent: </b>Wednesday, December 14, 2016 3:47:03 PM<br><b>Subject: </b>[llvm-dev] analysis based on nonnull attribute<br><br><div id="DWT50626" 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></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.<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="DWT50627" 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>It should be replaced by !nonnull metadata on the load. We might not be doing that today, however.<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"> %z.i = icmp ugt i32 %y.i, 23<br> %null_check = icmp eq i32* %x, null<br> br i1 %null_check, label %t, label %f<br><br>t: <br> ret i1 true<br><br>f: <br> ret i1 %z.i<br>}<br><br></div>
<br>_______________________________________________<br>LLVM Developers mailing list<br>llvm-dev@lists.llvm.org<br>http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br></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>