This is an archive of the discontinued LLVM Phabricator instance.

Minor refactoring of GEP handling in isDereferenceablePointer
ClosedPublic

Authored by apilipenko on May 20 2015, 3:14 AM.

Details

Summary

For GEP instructions isDereferenceablePointer checks that all indices are constant and within bounds. Replace this index calculation logic to a call to accumulateConstantOffset. Separated from the D9791.

Diff Detail

Repository
rL LLVM

Event Timeline

apilipenko updated this revision to Diff 26134.May 20 2015, 3:14 AM
apilipenko retitled this revision from to Minor refactoring of GEP handling in isDereferenceablePointer.
apilipenko updated this object.
apilipenko edited the test plan for this revision. (Show Details)
apilipenko added a reviewer: sanjoy.
apilipenko added a subscriber: Unknown Object (MLST).
reames added a subscriber: reames.May 28 2015, 11:04 AM

Artur, I'm a bit confused on what this code is trying to accomplish. First, is this intended to be an NFC change? If not, where's the test case?

It appears like this is basically trying to infer the "inbounds" property on GEPs. I'm sure we have some code for this in InstCombine, have you looked there to see what it does? Having a function of the form isInboundsGEP(GetElementPointer *GEP) which is used from both places might be a good factoring.

sanjoy requested changes to this revision.May 28 2015, 11:14 AM
sanjoy edited edge metadata.

I'm not sure that this is an NFC change -- I think the previous code will return false on the %1 below while the new code will return true.

%struct.A = type { [8 x i8], [5 x i8] }

define i8 @f(%struct.A* %a) {
  %1 = getelementptr inbounds %struct.A, %struct.A* %a, i64 0, i32 0, i64 10
  %2 = load i8, i8* %1
  ret i8 %2
}

Please add a test case that shows this difference.

lib/Analysis/ValueTracking.cpp
2987 ↗(On Diff #26134)

LLVM style is Type *.

2989 ↗(On Diff #26134)

Can we simplify this to return (Offset + LoadSize).ule(DL.getTypeAllocSize(BaseType))?

This revision now requires changes to proceed.May 28 2015, 11:14 AM

Philip, the change was separated from D9791 by Sanjoy's suggestion. To take alignment into account I need to know GEP's offset. That was intended to be a NFC, but it turned out to be not.

Sanjoy, you are right, it will give another result for your code. I think it's OK as long as we stay within the underlying object size. Will add a test case.

apilipenko updated this revision to Diff 26776.May 29 2015, 5:00 AM
apilipenko edited edge metadata.

Address review findings

reames added a comment.Jun 3 2015, 9:19 AM

I'm deferring to Sanjoy because I don't understand the context of the patch. Sanjoy, can you comment?

sanjoy accepted this revision.Jun 3 2015, 6:01 PM
sanjoy edited edge metadata.
sanjoy added inline comments.
test/Analysis/ValueTracking/memory-dereferenceable.ll
63 ↗(On Diff #26776)

I'd call this %within_allocation or something like that, to prevent confusion with the inbounds attribute (which is not what we're testing here).

This revision is now accepted and ready to land.Jun 3 2015, 6:01 PM
This revision was automatically updated to reflect the committed changes.