This is an archive of the discontinued LLVM Phabricator instance.

[WIP] Expose functions to determine pointer properties (Align & Deref)
Changes PlannedPublic

Authored by jdoerfert on Aug 22 2019, 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.Aug 22 2019, 2:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 22 2019, 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).Aug 22 2019, 2:08 PM
jdoerfert edited the summary of this revision. (Show Details)

Update tests and fix errors

joerg added a subscriber: joerg.Aug 26 2019, 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.Aug 27 2019, 9:13 PM

Improve comment

@reames Would you be OK with this?

lebedev.ri added inline comments.Aug 31 2019, 4:27 AM
llvm/test/CodeGen/PowerPC/noPermuteFormasking.ll
94 ↗(On Diff #217574)

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

Can this diff be simplified?
There's a lot of changes there.

What's the status here?

jdoerfert planned changes to this revision.Apr 4 2020, 8:34 AM

@lebedev.ri There were some concerns and I first have to reevaluate how to address them and achieve value in the move. Long story short, this is halted for now.

sanjoy resigned from this revision.Jan 29 2022, 5:40 PM
lebedev.ri resigned from this revision.Jan 12 2023, 4:57 PM

This review may be stuck/dead, consider abandoning if no longer relevant.
Removing myself as reviewer in attempt to clean dashboard.