This is an archive of the discontinued LLVM Phabricator instance.

isSafeToLoadUnconditionally cleanup
Needs RevisionPublic

Authored by apilipenko on Jan 15 2016, 9:16 AM.

Details

Reviewers
hfinkel
Summary

GlobalVariable/AllocaInst cases are handled by isDerferenceableAndAlignedPointer function.

Diff Detail

Event Timeline

apilipenko updated this revision to Diff 45002.Jan 15 2016, 9:16 AM
apilipenko retitled this revision from to isSafeToLoadUnconditionally cleanup.
apilipenko updated this object.
apilipenko added reviewers: hfinkel, reames.
apilipenko added a subscriber: llvm-commits.
reames requested changes to this revision.Feb 9 2016, 9:27 AM
reames edited edge metadata.
reames added inline comments.
lib/Analysis/Loads.cpp
96

The code in isDereferenceableAndAlignedPointer uses hasExternalWeakLinkage. Are these different in an interesting way?

111

I'm really not sure this code is dead. Specifically, this is using getPrefTypeAlignment whereas the code in isAligned, via isDereferenceableAndAlignedPointer, is using getABITypeAlignment. (Specifically, for the alloca case.)

For the GV case, we use getPrefTypeAlignment which is documented as being the preferred *stack* alignment vs the global specific one in isAligned. Again, different.

I'm not sure the current code is *correct*, but this definitely doesn't appear to be NFC. Can you comment on this?

114

This part does not appear to be handled in the isDereferenceAndAlignedPointer. Specifically, this is checking *dereferenceability*. This is likely a bug in isDereferenceAndAlignedPointer.

This revision now requires changes to proceed.Feb 9 2016, 9:27 AM
apilipenko added inline comments.Feb 10 2016, 10:07 AM
lib/Analysis/Loads.cpp
96

This code prohibits any overriding of the global because it allegedly might change its size (I write allegedly here because I don't know how can this happen). The size is important here because later it checks that the access is within the allocation size of the object (see the comment on line 114).

isDereferenceableAndAlignedPointer cares only about linkage which might result in null globals and don't care about size change because it doesn't use size to determine dereferenceability, but rather does it "symbolically".

111

This is NFC for GV. isDereferenceableAndAlignedPointer calls isAligned, which calls getAlignment, which in turn handles GV without specified alignment. For strongly linked globals it's DL.getPrefTypeAlignment. This code only handles strongly linked globals and also uses DL.getPrefTypeAlignment.

For allocas isDereferenceableAndAlignedPointer is more conservative by using getABITypeAlignment. I can't find any confirmation that using preferred alignment is correct here. For example, computeKnownBits assumes that default alignment for an alloca is ABI alignment.

114

This check here is required because the base might have a type different from the access type. That can happen because GetPointerBaseWithConstantOffset strips bitcasts.

%base.i8 = alloca i8
%base.32 = bitcast %base to i32
%v = load i32, %base.32

On the other hand isDereferenceAndAlignedPointer doesn't strip bitcasts from smaller types to larger types.

apilipenko added inline comments.Feb 10 2016, 10:45 AM
lib/Analysis/Loads.cpp
111

I've just found Hal's reply on llvm-dev which confirms that using preferred alignment as default alignment for allocas is correct:
http://lists.llvm.org/pipermail/llvm-dev/2015-June/086277.html

But, changing this in isDereferenceableAndAlignedPointer is a separate improvement.

reames resigned from this revision.Feb 22 2016, 2:13 PM
reames removed a reviewer: reames.

Artur, I'm sorry, but I don't feel comfortable signing off on this patch. I'm not convinced that this change actually is NFC and I don't understand this area of code well enough to approving changes. I'm going to have to defer to Hal or another reviewer.