Page MenuHomePhabricator

[WIP] Expose functions to determine pointer properties (Align & Deref)
Needs ReviewPublic

Authored by jdoerfert on Thu, Aug 22, 2:07 PM.

Details

Summary
NOTE: This is a prototype to show an alternative to the two solutionssketched in http://lists.llvm.org/pipermail/llvm-dev/2019-August/134680.html .

In this patch Value::getPointerDereferenceableBytes and
Value::getPointerAlignment are extracted into more powerful versions
living alongside isDereferenceableAndAlignedPointer in
Analysis/Loads.h. The functions have also been enriched wrt. GEP
support and unified wrt. value kinds they can unpack. Thus, the only
"new" logic is concerned with GEP handling everything else is
copied/moved from other places.

NOTE: One caveat is that at least one use site (ConstantFold.cpp) does not have access to the analysis library in which the functions now live.
NOTE: Changes to downstream code should be mechanical, I used: %s/\(\w\+\)->getPointerAlignment(/getPointerAlignment(\1, /
NOTE: Not all affected tests have been updated but only one to show how the improved GEP logic affects alignment.

Event Timeline

jdoerfert created this revision.Thu, Aug 22, 2:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptThu, Aug 22, 2:07 PM
jdoerfert retitled this revision from [WIP] Expose functions to determine pointer properties (Align & Deref) NOTE: This is a prototype to show an alternative to the two solutions sketched in http://lists.llvm.org/pipermail/llvm-dev/2019-August/134680.html . to [WIP] Expose functions to determine pointer properties (Align & Deref).Thu, Aug 22, 2:08 PM
jdoerfert edited the summary of this revision. (Show Details)

Update tests and fix errors

joerg added a subscriber: joerg.Mon, Aug 26, 10:17 AM

At least for freestanding environments, it would be useful to separate nonnull completely from deferencable. GCC has a separate flag for it, which might also be a reasonable idea.

At least for freestanding environments, it would be useful to separate nonnull completely from deferencable. GCC has a separate flag for it, which might also be a reasonable idea.

If you set the function attribute accordingly that should already work, e.g., null will be considered any other pointer.

Can we remove the CanBeNull argument from getPointerDereferenceableBytes()? It looks like it's currently unused. Or are you planning to use it somewhere?

llvm/include/llvm/Analysis/Loads.h
82

Maybe describe what it means if IsKnownDeref is false, in a little more detail?

Can we remove the CanBeNull argument from getPointerDereferenceableBytes()? It looks like it's currently unused. Or are you planning to use it somewhere?

This is a good question. For now, there are no users but there is a situation where we could use it: When we derive dereferenceable in the Attributor we also derive nonnull separately, if we would return false for CanBeNull we could update the nonnull attribute directly. Maybe there are other use cases, e.g., use flow information to rule out NULL, but I fail to see where we would exploit those.

For sure I have to describe better what all the combinations of return values would mean.

jdoerfert updated this revision to Diff 217574.Tue, Aug 27, 9:13 PM

Improve comment

@reames Would you be OK with this?

lebedev.ri added inline comments.Sat, Aug 31, 4:27 AM
llvm/test/CodeGen/PowerPC/noPermuteFormasking.ll
94

I think you want to first regenerate check-lines in trunk.