This is an archive of the discontinued LLVM Phabricator instance.

[SCEV] recognize llvm.annotation intrinsic
ClosedPublic

Authored by shchenz on Jun 15 2022, 1:40 AM.

Details

Summary

We use this intrinsic in our codes. With this intrinsic, the consecutive store can not be recognized in SLP vectorizer.

Diff Detail

Event Timeline

shchenz created this revision.Jun 15 2022, 1:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 15 2022, 1:40 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
shchenz requested review of this revision.Jun 15 2022, 1:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 15 2022, 1:40 AM
nikic added a comment.Jun 15 2022, 2:13 AM

Previous attempt: https://reviews.llvm.org/D102344

The semantics of this intrinsics as specified by LangRef really leave something to be desired. In particular it's not clear to me whether it is okay to replace the llvm.annotation result with its argument during middle-end optimization, because that's what this SCEV change will ultimately lead to (at least in some cases).

Previous attempt: https://reviews.llvm.org/D102344

The semantics of this intrinsics as specified by LangRef really leave something to be desired. In particular it's not clear to me whether it is okay to replace the llvm.annotation result with its argument during middle-end optimization, because that's what this SCEV change will ultimately lead to (at least in some cases).

From the conclusion of patch D102344, I am thinking there was already an agreement that replacing the llvm.annotation result with its argument during middle-end optimization is valid according to LLVM language reference.

I will ping the patch D102344, thanks for pointing out this patch.

nikic added a comment.Jun 15 2022, 3:48 AM

Previous attempt: https://reviews.llvm.org/D102344

The semantics of this intrinsics as specified by LangRef really leave something to be desired. In particular it's not clear to me whether it is okay to replace the llvm.annotation result with its argument during middle-end optimization, because that's what this SCEV change will ultimately lead to (at least in some cases).

From the conclusion of patch D102344, I am thinking there was already an agreement that replacing the llvm.annotation result with its argument during middle-end optimization is valid according to LLVM language reference.

I would like a LangRef patch to make the wording more explicit. I assume the semantics here are that it's always legal to replace llvm.annotation return value with its argument, but it's preferred not to do the replacement? Otherwise we could just mark the argument as returned.

shchenz updated this revision to Diff 440904.Jun 29 2022, 2:26 AM

address @nikic comment:

  • explicitly doc the behavior for annotation intrinsics
  • handle llvm.ptr.annotation too
shchenz updated this revision to Diff 440910.Jun 29 2022, 2:36 AM

I would like a LangRef patch to make the wording more explicit. I assume the semantics here are that it's always legal to replace llvm.annotation return value with its argument, but it's preferred not to do the replacement? Otherwise we could just mark the argument as returned.

I guess it's like metadata but for instructions: Not necessary for semantic correctness, but adds additional information that might be useful, even if just a comment. Its design is unfortunate to have an influence on optimization.

Like D102344, I am ok to greenlight this patch if @nikic is.

llvm/docs/LangRef.rst
23616–23622

This sounds like they are removed immediately (even by analyses?), but its just that it is semantically correct to do so while losing some information such as debug info.

Could you use wording such as "transformations preserve annotations on a best-effort basis but are allowed to replace them with their first argument without breaking semantics and are completely dropped during instruction selection"?

shchenz updated this revision to Diff 441579.Jun 30 2022, 8:06 PM
shchenz marked an inline comment as done.

address @Meinersbur comments

llvm/docs/LangRef.rst
23616–23622

Thanks. Updated.

nikic added inline comments.Jul 1 2022, 12:00 AM
llvm/docs/LangRef.rst
23580

"and they are"?

llvm/lib/Analysis/ScalarEvolution.cpp
7822

Please also add these to getOperandsToCreate() (probably after a rebase).

shchenz updated this revision to Diff 441635.Jul 1 2022, 1:38 AM
shchenz marked an inline comment as done.

address @nikic comments

nikic accepted this revision.Jul 1 2022, 5:13 AM

LGTM

This revision is now accepted and ready to land.Jul 1 2022, 5:13 AM
This revision was landed with ongoing or failed builds.Jul 3 2022, 6:22 PM
This revision was automatically updated to reflect the committed changes.