This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Always allow the __bf16 type
ClosedPublic

Authored by dmgreen on Aug 2 2022, 2:14 AM.

Details

Summary

We would like to make the ACLE NEON and SVE intrinsics more useable by gating them on the target, not by ifdef preprocessor macros. See #56480. In order to do this the types they use need to be available. This patches makes __bf16 always available under AArch64, bringing it in-line with GCC https://godbolt.org/z/sfWWv74Mj. In subsequent patches the NEON bfloat16x8_t and SVE svbfloat16_t types (along with bfloat16_t used in arm_sve.h) will be made unconditional too.

Diff Detail

Event Timeline

dmgreen created this revision.Aug 2 2022, 2:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2022, 2:14 AM
dmgreen requested review of this revision.Aug 2 2022, 2:14 AM

What actually happens if you try this? Normally I'd expect that if a thing is forbidden in the front end it's because otherwise it would lead to a codegen crash or something similar. But this patch is only removing the restriction, and not adding any support. Is that part already done, and bf16 operations will get automatically converted into some libcall that already exists, in the absence of any better approach?

Matt added a subscriber: Matt.Aug 2 2022, 9:54 AM

It can only be used to pass values around. The tests in arm-bfloat.cpp shows that you can declare variables but not perform any of the operations in that test. arm-bf16-forbidden-ops.cpp shows it can't be cast. arm-bf16-params-returns.c shows it can be passed through args and rets. And this shows that working as expected in the backend: https://godbolt.org/z/oxzh1PWe9. The idea is that you can't do a huge amount with them, and what you can do can be handled without any special instructions.

(I do know that there are a few areas where they currently do not work but should, like ternary operations: https://godbolt.org/z/v8Mx3EPW7. I hope to fix that but it's an orthogonal issue as it happens with the feature).

That leaves the intrinsics, which are currently part of arm_neon.h. The arm_neon.h file is more difficult to deal with, I'm starting with arm_sve.h. The bfloat16 intrinsics in arm_neon.h are currently behind an #ifdef guard, so cannot be used. Once that changes it will work more like this GCC example, where they are defined but using them in a function without bf16 available will give an error: https://godbolt.org/z/13vfecjx1

simon_tatham accepted this revision.Aug 3 2022, 3:02 AM

Ah, yes, I misread what the test changes were about – I didn't notice that you'd only just introduced the scalar error context, and thought you were enabling all those operations in at least one situation, rather than changing the form of the check that they were unconditionally disabled.

Right, so the effect is that you can talk about the type, put it in struct fields, query its size and alignment, and if you really must, declare variables of the type that you never do anything with. That all sounds safe enough :-)

In that case, LGTM.

This revision is now accepted and ready to land.Aug 3 2022, 3:02 AM
This revision was landed with ongoing or failed builds.Aug 4 2022, 10:35 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2022, 10:35 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript