This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Add bf16 select handling
ClosedPublic

Authored by dmgreen on Aug 5 2022, 4:36 AM.

Details

Summary

A bfloat select operation will currently crash, but is allowed from C. This adds handling for the operation, turning it into a FCSELHrrr if fullfp16 is present, or converting it to a FCSELSrrr if not. The FCSELSrrr is created via using INSERT_SUBREG/EXTRACT_SUBREG to convert the bf16 to a f32 and using the f32 pattern for FCSELSrrr. (I originally attempted to do this via a tablegen pattern, but it appears that the nzcv glue is places onto the wrong node, causing it to be forgotten and incorrect scheduling to be emitted).

The FCSELSrrr can also be used for fp16 selects when +fullfp16 is not present, which helps avoid an unnecessary promotion to f32.

Diff Detail

Event Timeline

dmgreen created this revision.Aug 5 2022, 4:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2022, 4:36 AM
dmgreen requested review of this revision.Aug 5 2022, 4:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 5 2022, 4:36 AM
samtebbs accepted this revision.Aug 5 2022, 6:52 AM
This revision is now accepted and ready to land.Aug 5 2022, 6:52 AM
tschuett added inline comments.
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
8445

Did you say *b*f16 in the title?

dmgreen added inline comments.Aug 11 2022, 1:15 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
8445

Yep it is explained in the summary. The short version is that we are adding this for bf16, but can use the same method for f16 so save a few instructions. Or put another way we are adding lowering for f16 and re-using it for bf16.

This revision was landed with ongoing or failed builds.Aug 11 2022, 6:20 AM
This revision was automatically updated to reflect the committed changes.