This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Enable CR bits support for Power8 and above.
ClosedPublic

Authored by amyk on Apr 19 2022, 8:09 PM.

Details

Summary

This patch turns on support for CR bit accesses for Power8 and above. The reason why CR bits are turned
on as the default for Power8 and above is that because later architectures make use of builtins and
instructions that require CR bit accesses (such as the use of setbc in the vector string isolate predicate
and bcd builtins on Power10).

This patch also adds the clang portion to allow for turning on CR bits in the front end if the user so desires to.

Diff Detail

Event Timeline

amyk created this revision.Apr 19 2022, 8:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 19 2022, 8:09 PM
amyk requested review of this revision.Apr 19 2022, 8:09 PM

This patch turns on support for CR bit accesses for Power8 and above. The reason why CR bits are turned on as the default for Power8 and above is that because later architectures make use of builtins and instructions that require CR bit accesses (such as the use of setbc in the vector string isolate predicate and bcd builtins on Power10).

Maybe we also can add some comments in docs/ClangCommandLineReference.rst to explicitly say that -mcrbits will be default to on when PowerPC arch is no smaller than 8. I believe some cr-bit operations also exist on Power7 or even Power6?

clang/lib/Basic/Targets/PPC.cpp
520

If we set the +crbits by the arch name, do we still need the customization (Turn on crbits for O2 and above) in computeFSAdditions()?

clang/test/Driver/ppc-crbits.cpp
51

Do we need some cases for AIX?

amyk updated this revision to Diff 425417.Apr 26 2022, 10:35 PM

Address review comments of adding documentation to clang/docs/ClangCommandLineReference.rst and adding AIX checks to clang/test/Driver/ppc-crbits.cpp.

amyk marked an inline comment as done.Apr 26 2022, 10:36 PM
amyk added inline comments.
clang/lib/Basic/Targets/PPC.cpp
520

Yeah, that's a good point. I looked into this previously, and it appears that addition of -mcrbits inside computeFSAdditions() may still be necessary.

In particular, we have test cases that test pre-POWER8 with optimizations on (or, if no optimization level is provided, then -O2 is assumed the default). In these cases, much of the code changes if the customization inside computeFSAdditions() is removed because we would no longer be using crbits pre-P8.

clang/test/Driver/ppc-crbits.cpp
51

Thanks, I've added some.

shchenz accepted this revision as: shchenz.Apr 26 2022, 11:44 PM

LGTM. Thanks for fixing.

clang/lib/Basic/Targets/PPC.cpp
520

hmm, OK, then we still have the same issue that this patch fixes for pre-POWER8. I'm ok with leaving it for now as IMO Power7/Power6 should not be major versions for PowerPC.

This revision is now accepted and ready to land.Apr 26 2022, 11:44 PM
nemanjai added inline comments.Apr 27 2022, 2:42 AM
clang/lib/Basic/Targets/PPC.cpp
520

Up until Power8, the only instructions we had that require crbits were CR-logicals (which existed since the POWER architecture - i.e. before PowerPC). In Power8, we added BCD instructions that also require crbits. So that's why we turn it on for Power8 and up.

nemanjai added inline comments.Apr 27 2022, 7:23 AM
clang/docs/ClangCommandLineReference.rst
3578
... is the default for POWER8 and above as well as for all other CPUs when optimization is applied (-O2 and above).

But please check if it is also applied at -O1 and correct that statement accordingly.

llvm/test/CodeGen/PowerPC/fast-isel-fcmp-nan.ll
5

Why do we not emit the VSX instructions here any longer? How are crbits related?

shchenz added inline comments.Apr 27 2022, 6:13 PM
clang/lib/Basic/Targets/PPC.cpp
520

Fail enough.

shchenz added inline comments.Apr 27 2022, 7:31 PM
clang/lib/Basic/Targets/PPC.cpp
520

haha, I mean fair....

This revision was landed with ongoing or failed builds.May 2 2022, 10:06 AM
This revision was automatically updated to reflect the committed changes.
amyk marked an inline comment as done.
amyk added inline comments.May 2 2022, 10:10 AM
llvm/test/CodeGen/PowerPC/fast-isel-fcmp-nan.ll
5

Nemanja and I discussed this outside of the revision. This test case is ran with FastISel by default.

It looks like for fcmp ULT/UEQ/UGT/OLE/ONE/OGE, we're not able to find a compare predicate, so we don't use FastIISel for these changed test cases.
With my patch (turning on CR bits), we end up matching to fcmpu in the td patterns, but when CR bits are not present, we match to the VSX instructions in PPCISelDAGToDAG.
This should be something we investigate at a later date.