This is an archive of the discontinued LLVM Phabricator instance.

POC: Add `elementtype` attribute requirement on atomic memory intrinsics.
Needs ReviewPublic

Authored by anna on Jun 15 2022, 11:08 AM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

LLVM officially supports Garbage Collection environments.
Such environments must be able to detect type of accessed object.
With opaque pointers the only possible way for memory intrinsics is
elementtype argument attribute. This patch adds the support in the
form of LangRef, verifier and pass updates.

Diff Detail

Event Timeline

dantrushin created this revision.Jun 15 2022, 11:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 15 2022, 11:08 AM
Herald added a subscriber: jdoerfert. · View Herald Transcript
dantrushin requested review of this revision.Jun 15 2022, 11:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 15 2022, 11:08 AM

Not familiar with GC requirements, but this at least sounds plausible to me (maybe @reames can confirm?) However, I think that if we go down this line, we should probably go all in: Drop the element_size argument from the intrinsics and make elementtype required by the IR verifier, and adjust lowering to perform copies in the correct type.

dantrushin retitled this revision from [LangRef] Document `elementtype` attribute requirement on atomic memory intrinsics. to [Draft][LangRef] Document `elementtype` attribute requirement on atomic memory intrinsics..Jun 15 2022, 12:24 PM

I don't understand the motivation here. Clearly, such an environment could tag the operations this way, and probably should. However, why does that need to be in the LangRef as a requirement? Is the idea to disallow some particular transform in tree that can't meet this?

The optimizer can insert new atomic memcpy/memmove calls, e.g loop-idiom-recognize would do that. Currently, when loop-idiom-recognize inserts such a call it doesn't tag it with the element type, which makes it an incorrect transform for us.

If we document the requirement in the langref we can a) add a verification rule to catch these situations, b) fix such transforms upstream. I think we can restrict this requirement to functions that have a GC strategy specified.

Idea is being able to push something like these though upstream:
https://reviews.llvm.org/D125690
https://reviews.llvm.org/D127892
From our downstream point of view they look reasonable, but we've encountered upstream resistance on first (so most likely will see it on second as well if we do it unconditionally)

anna commandeered this revision.Sep 6 2023, 8:16 AM
anna added a reviewer: dantrushin.
anna added a subscriber: anna.

Thanks @dantrushin for the patch. We have now had nasty miscompiles in practice (lowering memory intrinsics to regular loops and miss adding barriers for GC) and would like to make progress with this patch.

As a first step, we plan to document in the LangRef that functions having GCStrategy specified needs to have elementtype attribute set for the src and dest arguments for the atomic intrinsics. Also, introducing the API to record the elementtype (https://reviews.llvm.org/D125690).
The next step would be to have the verification rule for this and to teach passes/utilities about this: LoopIdiomRecognize and LowerMemIntrinsics.cpp (utility API for atomic mem intrinsics).

Once both of these have baked in, we can then remove the elementsize argument altogether from the atomic mem intrinsics since they can be inferred from the elementtype and remove the GCStrategy requirement as well. This also allows non-GC users of atomic memory intrinsics enough time to react to the change.

This perhaps deserves an RFC on the mailing list.

anna updated this revision to Diff 556274.Sep 8 2023, 9:18 AM

This is a POC of most of the changes for the RFC to follow. The change will be split into LangRef + API as one change, Verifier + pass updates as another change.

anna retitled this revision from [Draft][LangRef] Document `elementtype` attribute requirement on atomic memory intrinsics. to Add `elementtype` attribute requirement on atomic memory intrinsics..Sep 8 2023, 9:19 AM
anna edited the summary of this revision. (Show Details)
anna retitled this revision from Add `elementtype` attribute requirement on atomic memory intrinsics. to POC: Add `elementtype` attribute requirement on atomic memory intrinsics..Sep 8 2023, 9:22 AM
anna removed a reviewer: dantrushin.
anna added a subscriber: dantrushin.