This is an archive of the discontinued LLVM Phabricator instance.

[Statepoint] Use default attributes for some GC intrinsics
ClosedPublic

Authored by nikic on Oct 28 2022, 2:27 AM.

Details

Summary

This adds the default intrinsic attributes (nosync, nofree, nocallback, willreturn) to the gc.result, gc.relocate, gc.pointer.base and gc.pointer.offset intrinsics. As far as I understand, all of these are supposed to be pure. Some quotes from LangRef:

A gc.result is modeled as a ‘readnone’ pure function. It has no side effects since it is just a projection of the return value of the previous call represented by the gc.statepoint.

A gc.relocate is modeled as a readnone pure function. It has no side effects since it is just a way to extract information about work done during the actual call modeled by the gc.statepoint.

Having willreturn in particular will be important to avoid optimization regressions in the future.

Diff Detail

Event Timeline

nikic created this revision.Oct 28 2022, 2:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 28 2022, 2:27 AM
nikic requested review of this revision.Oct 28 2022, 2:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 28 2022, 2:27 AM
mkazantsev added subscribers: anna, apilipenko.

I'm not sure about nosync. I'd rather expect that gc.relocate does communicate with other threads. @apilipenko @anna WDYT?

willreturn definitely looks fine, nocallback not sure what is it (not in https://llvm.org/docs/LangRef.html?), nofree must be fine... But nosync is less than obvious for me, I'd rather expect it not to be present at least in gc.relocate.

anna added a comment.EditedNov 2 2022, 6:38 AM

Most attributes added here look right to me for the proposed intrinsics (and cannot be added for gc.statepoint). What is nocallback ?

The nosync is a bit tricky.
nosync from langref:

This function attribute indicates that the function does not communicate (synchronize) with another thread through memory or other well-defined means.

gc.relocates are a way to make sure that past a gc.statepoint, we do not use the original pointers, we use the relocated pointers. There is no ordering requirement w.r.t. other threads (that is already provided for through the statepoint intrinsic).
So, nosync looks right as well.

reames added a comment.Nov 2 2022, 7:53 AM

Just to comment, gc.result, and gc.relocate are explicitly projections from the result tuple. They're basically weirdly spelled extractvalues from an implicit tuple tied together by the token result. So, nosync is definitely correct for them.

nikic added a comment.Nov 7 2022, 12:32 AM

For nocallback, see https://github.com/llvm/llvm-project/issues/58683. There are open questions about the semantics, but as far as intrinsics are concerned, it means that it will not call any functions visible to LLVM. This is probably a problem for gc.statepoint, but as @reames mentions, the gc.result/gc.relocate intrinsics are just projections, so it should be fine there.

nikic updated this revision to Diff 473650.Nov 7 2022, 6:36 AM

Rebase to resolve a test conflict

apilipenko accepted this revision.Nov 7 2022, 10:03 PM

Looks good to me.

This revision is now accepted and ready to land.Nov 7 2022, 10:03 PM
This revision was automatically updated to reflect the committed changes.