[llvm-dev] analysis based on nonnull attribute
Hal Finkel via llvm-dev
llvm-dev at lists.llvm.org
Wed Dec 14 13:51:40 PST 2016
----- 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>
More information about the llvm-dev
mailing list