If the pointer was loaded/stored before the null check, the check is redundant and can be removed. For now the optimizers do not remove the nullptr check, see https://gcc.godbolt.org/z/H2r5GG. The patch allows to use more nonnull constraints. Also, it found one more optimization in some PowerPC test. This is my first llvm review, I am free to any comments.
Also, I don't have commit rights.
Patch by Danila Kutenin.
I don't think this makes sense. Getting the address space is not expensive. You can just refetch it below.
Alternatively, if you really do want to extract it, then the whole NullPointerIsDefined check should be extracted.