GlobalVariable/AllocaInst cases are handled by isDerferenceableAndAlignedPointer function.
Details
Diff Detail
Event Timeline
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. |
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. |
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: But, changing this in isDereferenceableAndAlignedPointer is a separate improvement. |
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.
The code in isDereferenceableAndAlignedPointer uses hasExternalWeakLinkage. Are these different in an interesting way?