This is an archive of the discontinued LLVM Phabricator instance.

[SCEV]: Teach SCEV about llvm.annotation intrinsic
Needs RevisionPublic

Authored by etiotto on May 12 2021, 11:22 AM.

Details

Summary

As per the LLVM language reference (https://llvm.org/docs/LangRef.html), the llvm.annotation intrinsic as no effect on code generation and optimization and therefore can be safely replaced by its first argument. This patch 'teaches' SCEV the semantics of that builtin function.

Diff Detail

Event Timeline

etiotto created this revision.May 12 2021, 11:22 AM
etiotto requested review of this revision.May 12 2021, 11:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2021, 11:22 AM
etiotto edited the summary of this revision. (Show Details)May 12 2021, 11:23 AM

Macro testcase:

From the language reference:

they are ignored by code generation and optimization.

I agree that this means the annotation can be ignored. But it returning the first argument (as mentioned in the summary) is not sufficient to conclude that, e.g. it could have side effects.

etiotto added a comment.EditedMay 13 2021, 11:50 AM

Macro testcase:

From the language reference:

they are ignored by code generation and optimization.

I agree that this means the annotation can be ignored. But it returning the first argument (as mentioned in the summary) is not sufficient to conclude that, e.g. it could have side effects.

I can add a test sure, let's first come to a conclusion on the side-effects comment.

It is not clear to me what side-effects the llvm.annotation intrinsic would need to have. The current documentation states that the intrinsic function can be ignored by code gen and optimizations. That means I could move instructions past the intrinsic since the intrinsic can be ignored. If the intrinsics had side effects that optimization would be illegal, and it follows the intrinsic could not be ignored. Do I make any sense?

It is not clear to me what side-effects the llvm.annotation intrinsic would need to have. The current documentation states that the intrinsic function can be ignored by code gen and optimizations. That means I could move instructions past the intrinsic since the intrinsic can be ignored. If the intrinsics had side effects that optimization would be illegal, and it follows the intrinsic could not be ignored. Do I make any sense?

I am referring to the summary:

The llvm.annotation intrinsic returns the first argument passed to it.

As mentioned, this is not a sufficient condition to be just ignored. The summary should also mention that by the LLVM language reference, " are ignored by code generation and optimization."

Suggestion:

As by the LLVM language reference, the llvm.annotation intrinsic and no effect on code generation and optimization (https://llvm.org/docs/LangRef.html) and therefore can be safely replaced by its first argument. This patch 'teaches' SCEV the semantics of that builtin function.

etiotto edited the summary of this revision. (Show Details)May 17 2021, 6:58 AM

I am referring to the summary:

The llvm.annotation intrinsic returns the first argument passed to it.

As mentioned, this is not a sufficient condition to be just ignored. The summary should also mention that by the LLVM language reference, " are ignored by code generation and optimization."

Suggestion:

As by the LLVM language reference, the llvm.annotation intrinsic and no effect on code generation and optimization (https://llvm.org/docs/LangRef.html) and therefore can be safely replaced by its first argument. This patch 'teaches' SCEV the semantics of that builtin function.

Hey Michael, I understand now what you meant. Sure I have updated the description now.

reames requested changes to this revision.Nov 30 2021, 9:59 AM

Test case?

This revision now requires changes to proceed.Nov 30 2021, 9:59 AM
shchenz added subscribers: nikic, shchenz.EditedJun 15 2022, 2:29 AM

I have not noticed this patch, so I posted another patch D127835. Thanks for remind @nikic

Hi @etiotto , there is a small test case in D127835, can we move forward for this patch? I met some issue in SLP vectorizer because of this intrinsic. Thanks.

Herald added a project: Restricted Project. · View Herald TranscriptJun 15 2022, 2:29 AM