[all-commits] [llvm/llvm-project] 4479c0: Allow nonnull/align attribute to accept poison

Juneyoung Lee via All-commits all-commits at lists.llvm.org
Tue Jan 19 18:54:50 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4479c0c2c0be019b9932c6f1380a40e6cb48da25
      https://github.com/llvm/llvm-project/commit/4479c0c2c0be019b9932c6f1380a40e6cb48da25
  Author: Juneyoung Lee <aqjune at gmail.com>
  Date:   2021-01-20 (Wed, 20 Jan 2021)

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

  Log Message:
  -----------
  Allow nonnull/align attribute to accept poison

Currently LLVM is relying on ValueTracking's `isKnownNonZero` to attach `nonnull`, which can return true when the value is poison.
To make the semantics of `nonnull` consistent with the behavior of `isKnownNonZero`, this makes the semantics of `nonnull` to accept poison, and return poison if the input pointer isn't null.
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)
```

Instead, 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.
Having `noundef` attribute there re-allows this.

```
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
}
```

Another attribute that needs to be updated is `align`. This patch updates the semantics of align to accept poison as well.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D90529




More information about the All-commits mailing list