[PATCH] D90529: Allow nonnull attribute to accept poison

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 31 06:56:23 PDT 2020


aqjune created this revision.
aqjune added reviewers: jdoerfert, efriedma, nikic, fhahn, hfinkel.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya.
Herald added a project: LLVM.
aqjune requested review of this revision.

Hi all,

There has been an discussion about whether passing poison is allowed to a nonnull parameter/return value.

Currently LLVM is relying on ValueTracking's `isKnownNonZero` to attach nonnull, which can return true even if
the value is poison.
Allowing poison is important because it is hard to reason whether a value is not poison in general.
This makes many transformations like below legal:

  %p = gep inbounds %x, 1 ; % p is non-null pointer or poison
  call void @f(%p)        ; instcombine converts this to call void @f(nonnull %p)

But, this semantics makes propagation of nonnull to caller illegal.
The reason is that, passing poison to nonnull does not immediately raise UB anymore, so such program is still well defined, if the callee does not use the argument.

  define void @f(i8* %p) {       ; functionattr cannot mark %p nonnull here anymore
    call void @g(i8* nonnull %p) ; .. because @g never raises UB if it never uses %p.
    ret void
  }

The discussion didn't reach to the conclusion in the past, but I think now we can make a small progress. :)
The reason is that now we have `noundef`, and when the attribute has both `nonnull` and `noundef`, then
we can propagate `nonnull` to callee now.

Now many library functions are having `noundef` as well, and adding noundef patch is going on, I believe the propagation can be supported in many cases as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90529

Files:
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/Argument.h
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/lib/IR/Function.cpp
  llvm/lib/Transforms/IPO/FunctionAttrs.cpp
  llvm/test/Analysis/ValueTracking/known-nonnull-at.ll
  llvm/test/Transforms/FunctionAttrs/nonnull.ll
  llvm/test/Transforms/InstCombine/call_nonnull_arg.ll
  llvm/test/Transforms/InstCombine/unused-nonnull.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90529.302087.patch
Type: text/x-patch
Size: 9178 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201031/924c6f54/attachment.bin>


More information about the llvm-commits mailing list