[PATCH] D82614: ValueTracking: Fix isKnownNonZero for non-0 null pointers for byval

Johannes Doerfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 25 19:40:36 PDT 2020


jdoerfert added a comment.

In D82614#2115906 <https://reviews.llvm.org/D82614#2115906>, @arsenm wrote:

> In D82614#2115882 <https://reviews.llvm.org/D82614#2115882>, @jdoerfert wrote:
>
> > Honestly, `nonnull` should only mean `!= 0`. I guess not deducing `nonnull` from `byval` is reasonable for any `AS != 0`.
> >  I'm not really in favor of making `nonnull` mean "valid pointer", `dereferenceable` is already way closer to that and `nonnull` is used as "not 0" too often already.
>
>
> Without a marker for a known-invalid pointer, I don't see how you can repurpose dereferenceable to optimize out "null" checks for other invalid pointer values. The useful property is this pointer is known to never be a valid object; we don't have an isKnownNotDereferenceable


Fair, but reusing `nonnull` is not the solution. A "null" check, i.a. `ptr == 0`, is where `nonnull` comes in. For the lack of an alternative people started to overload the meaning. This is problematic but I guess already happening. I mean, `nonnull` cannot be equivalent to `!= 0` and at the same time equivalent to "not a valid pointer" because that would mean `!= 0` is equivalent to "not a valid pointer" (which it is not). I think both interpretations have been used in the past. I argue we need to fix it to one and introduce something else for the other. I would strongly favor `!= 0` as the canonical meaning of `nonnull`, basically how I read the langref right now. Unclear if "not a valid pointer" needs to be an attribute but maybe.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82614/new/

https://reviews.llvm.org/D82614





More information about the llvm-commits mailing list