[PATCH] D120395: [X86] Prohibit arithmatic operations on type `__bfloat16`
Phoebe Wang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 25 00:03:31 PST 2022
pengfei updated this revision to Diff 411334.
pengfei added a comment.
Disscussed with GCC folks. We think it's better to use the same way as D120411 <https://reviews.llvm.org/D120411> that replacing it with short int.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D120395/new/
https://reviews.llvm.org/D120395
Files:
clang/lib/Headers/avx512bf16intrin.h
clang/lib/Headers/avx512vlbf16intrin.h
clang/test/CodeGen/X86/avx512bf16-builtins.c
clang/test/CodeGen/X86/avx512bf16-error.c
clang/test/CodeGen/X86/avx512vlbf16-builtins.c
llvm/docs/LangRef.rst
Index: llvm/docs/LangRef.rst
===================================================================
--- llvm/docs/LangRef.rst
+++ llvm/docs/LangRef.rst
@@ -3369,8 +3369,8 @@
* - ``bfloat``
- 16-bit "brain" floating-point value (7-bit significand). Provides the
same number of exponent bits as ``float``, so that it matches its dynamic
- range, but with greatly reduced precision. Used in Intel's AVX-512 BF16
- extensions and Arm's ARMv8.6-A extensions, among others.
+ range, but with greatly reduced precision. Used in Arm's ARMv8.6-A
+ extensions, among others.
* - ``float``
- 32-bit floating-point value
Index: clang/test/CodeGen/X86/avx512vlbf16-builtins.c
===================================================================
--- clang/test/CodeGen/X86/avx512vlbf16-builtins.c
+++ clang/test/CodeGen/X86/avx512vlbf16-builtins.c
@@ -162,7 +162,7 @@
return _mm256_mask_dpbf16_ps(D, U, A, B);
}
-__bfloat16 test_mm_cvtness_sbh(float A) {
+unsigned short test_mm_cvtness_sbh(float A) {
// CHECK-LABEL: @test_mm_cvtness_sbh
// CHECK: @llvm.x86.avx512bf16.mask.cvtneps2bf16.128
// CHECK: ret i16 %{{.*}}
Index: clang/test/CodeGen/X86/avx512bf16-error.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/X86/avx512bf16-error.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -ffreestanding -triple x86_64-linux-pc %s
+
+// expected-error at +1 3 {{unknown type name '__bfloat16'}}
+__bfloat16 foo(__bfloat16 a, __bfloat16 b) {
+ return a + b;
+}
+
+#include <immintrin.h>
+
+// expected-warning at +2 3 {{'__bfloat16' is deprecated: use unsigned short instead}}
+// expected-note@* 3 {{'__bfloat16' has been explicitly marked deprecated here}}
+__bfloat16 bar(__bfloat16 a, __bfloat16 b) {
+ return a + b;
+}
Index: clang/test/CodeGen/X86/avx512bf16-builtins.c
===================================================================
--- clang/test/CodeGen/X86/avx512bf16-builtins.c
+++ clang/test/CodeGen/X86/avx512bf16-builtins.c
@@ -4,7 +4,7 @@
#include <immintrin.h>
-float test_mm_cvtsbh_ss(__bfloat16 A) {
+float test_mm_cvtsbh_ss(unsigned short A) {
// CHECK-LABEL: @test_mm_cvtsbh_ss
// CHECK: zext i16 %{{.*}} to i32
// CHECK: shl i32 %{{.*}}, 16
Index: clang/lib/Headers/avx512vlbf16intrin.h
===================================================================
--- clang/lib/Headers/avx512vlbf16intrin.h
+++ clang/lib/Headers/avx512vlbf16intrin.h
@@ -413,7 +413,8 @@
/// A float data.
/// \returns A bf16 data whose sign field and exponent field keep unchanged,
/// and fraction field is truncated to 7 bits.
-static __inline__ __bfloat16 __DEFAULT_FN_ATTRS128 _mm_cvtness_sbh(float __A) {
+static __inline__ unsigned short __DEFAULT_FN_ATTRS128
+_mm_cvtness_sbh(float __A) {
__v4sf __V = {__A, 0, 0, 0};
__v8hi __R = __builtin_ia32_cvtneps2bf16_128_mask(
(__v4sf)__V, (__v8hi)_mm_undefined_si128(), (__mmask8)-1);
Index: clang/lib/Headers/avx512bf16intrin.h
===================================================================
--- clang/lib/Headers/avx512bf16intrin.h
+++ clang/lib/Headers/avx512bf16intrin.h
@@ -15,7 +15,8 @@
typedef short __m512bh __attribute__((__vector_size__(64), __aligned__(64)));
typedef short __m256bh __attribute__((__vector_size__(32), __aligned__(32)));
-typedef unsigned short __bfloat16;
+typedef unsigned short __bfloat16
+ __attribute__((deprecated("use unsigned short instead")));
#define __DEFAULT_FN_ATTRS512 \
__attribute__((__always_inline__, __nodebug__, __target__("avx512bf16"), \
@@ -33,7 +34,7 @@
/// A bfloat data.
/// \returns A float data whose sign field and exponent field keep unchanged,
/// and fraction field is extended to 23 bits.
-static __inline__ float __DEFAULT_FN_ATTRS _mm_cvtsbh_ss(__bfloat16 __A) {
+static __inline__ float __DEFAULT_FN_ATTRS _mm_cvtsbh_ss(unsigned short __A) {
return __builtin_ia32_cvtsbf162ss_32(__A);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120395.411334.patch
Type: text/x-patch
Size: 3982 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220225/a7d17de7/attachment-0001.bin>
More information about the cfe-commits
mailing list