This is an archive of the discontinued LLVM Phabricator instance.

Hoist loads known to be in bounds of allocations
AbandonedPublic

Authored by reames on Apr 20 2017, 6:06 PM.

Details

Reviewers
sanjoy
Summary

Extend the dereferenceability analysis to exploit our existing implementation for computing a minimal object size. If we can tell we're within a known allocation, we can speculate the load without changing dereferenceability. This does assume that allocations are dereferenceable within their entire extend, but that seems like an entirely reasonable definition. (It also appears to be true of the existing code.)

Diff Detail

Event Timeline

reames created this revision.Apr 20 2017, 6:06 PM
sanjoy added inline comments.Apr 20 2017, 6:23 PM
lib/Analysis/Loads.cpp
123

Does this work in the presence of free? That is:

char *ptr = malloc(20)
free(ptr);
for (;;) {
  if (false)
    v = ptr[0];
}
reames abandoned this revision.Apr 24 2017, 9:48 PM

The test case Sanjoy added shows a fatal flaw in this approach. If free is possible, my reason would have to be context sensitive and that's not worth implementing at this time.