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.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
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.
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))? |
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.
I'm deferring to Sanjoy because I don't understand the context of the patch. Sanjoy, can you comment?
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). |