This is an archive of the discontinued LLVM Phabricator instance.

isKnownNonNull: recognize GEP inbounds as non-null
AbandonedPublic

Authored by nlopes on Jul 26 2017, 5:54 AM.

Details

Summary

A GEP inbounds cannot return a null pointer in address space 0 because:

  1. the input is non-zero
  2. arithmetic cannot overflow

This patch makes isKnownNonNull() recognize this fact.

Diff Detail

Repository
rL LLVM

Event Timeline

nlopes created this revision.Jul 26 2017, 5:54 AM
nlopes added a subscriber: llvm-commits.

Just realized there's a complicated isGEPKnownNonNull() in ValueTracking.cpp, which is use solely by isKnownNonZero().
I don't believe such a thing is necessary, since the input pointer to a GEP inbounds has to be non-null in address space 0. If others agree I'll also remove that function in a subsequent patch.

nlopes abandoned this revision.Jul 28 2017, 6:12 AM

Ah, thanks for the pointer.
Then I'll abandon this patch. I'm not sure why I understand why we have isKnownNotNull and isKnownNotZero. The difference seems to be that the latter is recursive and the former is not. I dunno if that was intended or not.
The current situation is that not all tricks are duplicated in the two functions, so the clients miss out if they use isKnownNotNull().
Any opinions or pointers to historical artifacts?

isKnownNonZero was added in r124183; isKnownNonNull was originally part of BasicAA, then moved in r151446.

isKnownNonZero was added in r124183; isKnownNonNull was originally part of BasicAA, then moved in r151446.

Thanks for the pointers, Eli!