This is an archive of the discontinued LLVM Phabricator instance.

[AssumeBundles] adapt Assumption cache to assume bundles
ClosedPublic

Authored by Tyker on Apr 3 2020, 8:05 AM.

Details

Summary

change assumption cache to store an assume along with an index to the operand bundle containing the knowledge.

Diff Detail

Event Timeline

Tyker created this revision.Apr 3 2020, 8:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2020, 8:05 AM

How does this work with multiple occurrences of a value in an assume?


change assumption cache to store an assume along with an index to the operand bundle containg the knoledge.

Two typos in the commit message

llvm/lib/Analysis/AssumptionCache.cpp
86

Clang format the above please.

llvm/lib/Transforms/Utils/InlineFunction.cpp
1846

Can you make this a variable, hard to read and interpret this way.

Tyker updated this revision to Diff 255141.Apr 5 2020, 5:31 AM

make cache invalidation invalidate no more than needed.
addressed comments.

Tyker marked 2 inline comments as done.Apr 5 2020, 5:32 AM

How does this work with multiple occurrences of a value in an assume?


change assumption cache to store an assume along with an index to the operand bundle containg the knoledge.

Two typos in the commit message

These are still open :)

Tyker edited the summary of this revision. (Show Details)Apr 5 2020, 11:21 AM
Tyker added a comment.Apr 5 2020, 11:23 AM

How does this work with multiple occurrences of a value in an assume?

the cache will contain multiple element with the same assume but a different index.

One more conceptual question and small nits.

llvm/lib/Analysis/AssumptionCache.cpp
60

I usually prefer a struct instead of a pair but this is local only so I guess it's ok. Feel free to use the ResultElem or something similar to improve readability here and at the use site below. (AV.first will then become something meaningful on first glance.)

171

Could you explain the need for the above logic please? Is is strictly related to the index extension or a general improvement?

(Nit: Use a continue to reduce indention and simplify the code)

Tyker updated this revision to Diff 256760.Apr 11 2020, 3:32 AM
Tyker marked an inline comment as done.

replaced std::pair<Value *, unsigned> with ResultElem

Tyker marked an inline comment as done.Apr 11 2020, 3:39 AM
Tyker added inline comments.
llvm/lib/Analysis/AssumptionCache.cpp
171

the AffectedValues map can associate multiple assumes with a single value this is true before and after the patch although i am not sure it is reachable before the patch.

here is an example of when this change matters:

call void @llvm.assume(i1 true) ["nonnull"(i32* %P)] ; called A
call void @llvm.assume(i1 true) ["align"(i32* %P, i32 4)] ; called B

with both A and B in cache both A and B will be in the AffectedValues for %P.

without this change if unregisterAssumption is called on A, all assumption of P will be invalidate even the one in B, however B will still be in the AssumeHandles (the list of all assumes in the function).
with this change if unregisterAssumption is called on A, A will be removed (set to null) for the assumptions on V and B will not be affected.

this is not strictly related only to AssumeBundles. but it makes a difference in a situtation which is rare if possible without assume bundles.

Note: that having a nullptr in assumption is already possible since Value* are stored in WeakTrackingVH so it can be set to null if it is removed.

jdoerfert accepted this revision.Apr 11 2020, 4:20 PM

LGTM, see below for some additional style changes and documentation you should apply before committing.

llvm/lib/Analysis/AssumptionCache.cpp
171

OK. I expected this to be a improvement not strictly related to assume bundles but I wasn't sure. You explanation makes sense to me.


Before you commit maybe replace AVI != ..end() with the opposite condition and a continue.
Add a message to the assert please.

This revision is now accepted and ready to land.Apr 11 2020, 4:20 PM
This revision was automatically updated to reflect the committed changes.