[llvm-dev] analysis based on nonnull attribute

Hal Finkel via llvm-dev llvm-dev at lists.llvm.org
Wed Dec 14 14:05:50 PST 2016


----- Original Message -----

> From: "Sanjay Patel" <spatel at rotateright.com>
> To: "Hal Finkel" <hfinkel at anl.gov>
> Cc: "llvm-dev" <llvm-dev at lists.llvm.org>
> Sent: Wednesday, December 14, 2016 4:03:40 PM
> Subject: Re: [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."

True, but we have range metadata for integers. 

-Hal 

-- 

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/a8be4fa4/attachment.html>


More information about the llvm-dev mailing list