This is an archive of the discontinued LLVM Phabricator instance.

[Loads] Globals are dereferenceable, if offset + size <= sizeof(global).
AbandonedPublic

Authored by fhahn on Aug 7 2020, 6:41 AM.

Details

Summary

Currently we fail to determine whether pointers to globals are
dereferenceable. Unless I am missing something, we can treat constant
expression GEPs as dereferenceable, if all the dereferenced bits fall
within the global's size.

Diff Detail

Event Timeline

fhahn created this revision.Aug 7 2020, 6:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2020, 6:41 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
fhahn requested review of this revision.Aug 7 2020, 6:41 AM
nlopes added a comment.Aug 7 2020, 7:06 AM

The reasoning looks good, though the case when offset + size overflows doesn't seem to be considered.

aqjune added a comment.Aug 7 2020, 7:18 AM

It may be a silly question, but can lifetime.end intrinsics be applied to global variables, too?
LangRef isn't clear about this, but it makes sense to say that lifetime.end only works for alloca/mallocs IMO.

I'm not sure I understand why you need a special case here. I think getPointerDereferenceableBytes() and isAligned() should handle global variables without any additional help.

If this does make a difference, it should be possible to write a testcase using LICM or something like that.

IIRC, not all globals are dereferenceable and we have to look at the linkage. Could be wrong though.

This needs a test for sure.

Why * 8 isn't size in bytes too?

Shouldn't we handle gep+global in Value::getPointerDereferenceableBytes instead, that should make this unnecessary, right?

fhahn abandoned this revision.Aug 7 2020, 12:37 PM

I'm not sure I understand why you need a special case here. I think getPointerDereferenceableBytes() and isAligned() should handle global variables without any additional help.

If this does make a difference, it should be possible to write a testcase using LICM or something like that.

You are right, this is already handled, I was just using isDereferenceablePointer with the wrong type, which was why it didn't work initially. Sorry for the noise, this seems not needed after all!