[PATCH] D90529: Allow nonnull attribute to accept poison
Juneyoung Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 31 09:52:08 PDT 2020
aqjune added a comment.
To share my understanding about how nonnull is used in optimizations:
1. It is mainly used to fold away null pointer checks.
define void @f(i8* nonnull %p) {
if (icmp eq %p, null) ret void ; this check can be folded to true
...
}
Note that the new nonnull-or-poison semantics is fine in the above case because if %p is poison we can fold `icmp eq %p, null` into false.
A similar but slightly different case:
...
call void @f(i8* nonnull %p)
if (icmp eq %p, null) ret void
In this case, the nonnull-or-poison semantics cannot make the comparison after call folded, because f may not use the poison argument at all, making the program well-defined.
But, if f has noundef attribute as well, this is fine because passing null to f is now UB:
...
call void @f(i8* noundef nonnull %p)
if (icmp eq %p, null) ret void ; %p is always non-null pointer!
2. It is combined with `dereferenceable_or_null` to infer `dereferenceable`.
This is still fine with the new nonnull-or-poison because passing poison to `dereferenceable_or_null` is still UB, guaranteeing that the pointer is never poison.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90529/new/
https://reviews.llvm.org/D90529
More information about the llvm-commits
mailing list