Sanjay Patel via llvm-dev
2016-Dec-14 21:47 UTC
[llvm-dev] analysis based on nonnull attribute
Does the nonnull parameter attribute give us information about subsequent uses of that value outside of the function that has the attribute? Example: define i1 @bar(i32* nonnull %x) { ; %x must be non-null in this function %y = load i32, i32* %x %z = icmp ugt i32 %y, 23 ret i1 %z } define i1 @foo(i32* %x) { %d = call i1 @bar(i32* %x) %null_check = icmp eq i32* %x, null ; check if null after call that guarantees non-null? br i1 %null_check, label %t, label %f t: ret i1 1 f: ret i1 %d } $ opt -inline nonnull.ll -S ... define i1 @foo(i32* %x) { %y.i = load i32, i32* %x ; inlined and non-null knowledge is lost? %z.i = icmp ugt i32 %y.i, 23 %null_check = icmp eq i32* %x, null br i1 %null_check, label %t, label %f t: ret i1 true f: ret i1 %z.i } -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161214/4620b87a/attachment.html>
Hal Finkel via llvm-dev
2016-Dec-14 21:51 UTC
[llvm-dev] analysis based on nonnull attribute
----- Original Message -----> From: "Sanjay Patel via llvm-dev" <llvm-dev at lists.llvm.org> > To: "llvm-dev" <llvm-dev at lists.llvm.org> > Sent: Wednesday, December 14, 2016 3:47:03 PM > Subject: [llvm-dev] analysis based on nonnull attribute> Does the nonnull parameter attribute give us information about > subsequent uses of that value outside of the function that has the > attribute?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.> Example:> define i1 @bar(i32* nonnull %x) { ; %x must be non-null in this > function > %y = load i32, i32* %x > %z = icmp ugt i32 %y, 23 > ret i1 %z > }> define i1 @foo(i32* %x) { > %d = call i1 @bar(i32* %x) > %null_check = icmp eq i32* %x, null ; check if null after call that > guarantees non-null? > br i1 %null_check, label %t, label %f > t: > ret i1 1 > f: > ret i1 %d > }> $ opt -inline nonnull.ll -S > ... > define i1 @foo(i32* %x) { > %y.i = load i32, i32* %x ; inlined and non-null knowledge is lost?It should be replaced by !nonnull metadata on the load. We might not be doing that today, however. -Hal> %z.i = icmp ugt i32 %y.i, 23 > %null_check = icmp eq i32* %x, null > br i1 %null_check, label %t, label %f> t: > ret i1 true> f: > ret i1 %z.i > }> _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-- Hal Finkel Lead, Compiler Technology and Programming Languages Leadership Computing Facility Argonne National Laboratory -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161214/de70eac1/attachment.html>
Sanjay Patel via llvm-dev
2016-Dec-14 22:03 UTC
[llvm-dev] analysis based on nonnull attribute
On Wed, Dec 14, 2016 at 2:51 PM, Hal Finkel <hfinkel at anl.gov> wrote:> > > ------------------------------ > > *From: *"Sanjay Patel via llvm-dev" <llvm-dev at lists.llvm.org> > *To: *"llvm-dev" <llvm-dev at lists.llvm.org> > *Sent: *Wednesday, December 14, 2016 3:47:03 PM > *Subject: *[llvm-dev] analysis based on nonnull attribute > > Does the nonnull parameter attribute give us information about subsequent > uses of that value outside of the function that has the attribute? > > 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. >Thanks! I don't know if that will actually solve our sub-optimal output for dyn_cast (!), but it might help... https://llvm.org/bugs/show_bug.cgi?id=28430> > > Example: > > define i1 @bar(i32* nonnull %x) { ; %x must be non-null in this function > %y = load i32, i32* %x > %z = icmp ugt i32 %y, 23 > ret i1 %z > } > > define i1 @foo(i32* %x) { > %d = call i1 @bar(i32* %x) > %null_check = icmp eq i32* %x, null ; check if null after call that > guarantees non-null? > br i1 %null_check, label %t, label %f > t: > ret i1 1 > f: > ret i1 %d > } > > $ opt -inline nonnull.ll -S > ... > define i1 @foo(i32* %x) { > %y.i = load i32, i32* %x ; inlined and non-null knowledge is lost? > > It should be replaced by !nonnull metadata on the load. We might not be > doing that today, however. > >We can't tag this load with !nonnull though because this isn't a load of the pointer? "The existence of the !nonnull metadata on the instruction tells the optimizer that the value loaded is known to never be null. This is analogous to the nonnull attribute on parameters and return values. This metadata can only be applied to loads of a pointer type." -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161214/ca5ef458/attachment.html>