This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] map hardware loop intrinsics to PowerPC pseudo instructions.
ClosedPublic

Authored by shchenz on Apr 8 2022, 12:53 AM.

Details

Summary

This is based on D122125. In D122125, we added a new post-isel pass to expand two new ctr loop pseudo instructions MTCTR8Pseudo and DecreaseCTR8Pseudo.

This patch maps hardware loop intrinsics loop_decrement and set_loop_iteration to the new PowerPC pseudo instructions, so that the hardware loop intrinsics will be expanded to normal cmp+branch form or ctrloop form based on the CTR register usage on MIR level.

We reuse legacy MTCTR8loop and update DecreaseCTR8Pseudo to DecreaseCTR8loop as well.

We still need another patch to remove the IR level CTR clobber check codes in PPCTargetTransformInfo.cpp

Diff Detail

Event Timeline

shchenz created this revision.Apr 8 2022, 12:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 8 2022, 12:53 AM
shchenz requested review of this revision.Apr 8 2022, 12:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 8 2022, 12:53 AM

gentle ping

gentle ping

jsji resigned from this revision.Jun 2 2022, 7:52 AM
shchenz updated this revision to Diff 438560.Jun 20 2022, 10:51 PM
shchenz edited reviewers, added: lkail; removed: jsji.

rebase

gentle ping

lkail added a comment.EditedJul 13 2022, 12:31 AM

Some llc LLVM IR tests are expected to be added and better run with -stop-after=finalize-isel so that we can observe how PPCCTR pseudos are generated.

llvm/lib/Target/PowerPC/PPCCTRLoops.cpp
10

Can we make it in another NFC patch?

shchenz updated this revision to Diff 445729.Jul 19 2022, 1:45 AM

add some cases after ISEL

Some llc LLVM IR tests are expected to be added and better run with -stop-after=finalize-isel so that we can observe how PPCCTR pseudos are generated.

Thanks for review.

I added some cases to show the change after ISEL with/without this patch. However I think for this patch, the best way to verify the functionality is that there is no ctr loop regression after this patch. Before the change, if we generate MTCTRloop, we know that it must be a CTR loop. But after the patch, it is not the case, we may revert the CTR loop pseudos to normal cmp+branch loop.

In the coming change related to Hardware Loop pass(in PPCTargetTransformInfo.cpp), I assume we should be able to generate more CTR loops as now we have more accurate info about CTR clobbers after ISEL.

llvm/lib/Target/PowerPC/PPCCTRLoops.cpp
10

Hmm, for this case, we can not rename the pseudo instruction in another NFC patch. MTCTRloop can be selected in ISEL and if we recognize MTCTRloop instead of MTCTRPseudo here, we have to also make ISEL generate DecreaseCTRPseudo too. Otherwise this is not a valid CTR loop.

gentle ping.

lkail accepted this revision as: lkail.Jul 31 2022, 7:53 PM

LGTM as tests are added and conceptual MTCTRPseudo has been replaced by concrete MTCTRloop.

This revision is now accepted and ready to land.Jul 31 2022, 7:53 PM
This revision was landed with ongoing or failed builds.Aug 8 2022, 6:34 PM
This revision was automatically updated to reflect the committed changes.
chapuni added a subscriber: chapuni.Aug 8 2022, 7:42 PM
chapuni added inline comments.
llvm/lib/Target/PowerPC/PPCCTRLoops.cpp
347

Preheader lost all users with -Asserts, to cause warning.

shchenz marked an inline comment as done.Aug 8 2022, 9:38 PM
shchenz added inline comments.
llvm/lib/Target/PowerPC/PPCCTRLoops.cpp
347