zahiraam updated this revision to Diff 387387.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113107/new/
https://reviews.llvm.org/D113107
Files:
clang/lib/Basic/Targets/X86.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/CodeGen/X86/Float16-aritmetic.c
clang/test/CodeGen/X86/Float16-complex.c
clang/test/CodeGen/X86/avx512fp16-complex.c
clang/test/Sema/Float16.c
clang/test/Sema/conversion-target-dep.c
clang/test/SemaCXX/Float16.cpp
Index: clang/test/SemaCXX/Float16.cpp
===================================================================
--- clang/test/SemaCXX/Float16.cpp
+++ clang/test/SemaCXX/Float16.cpp
@@ -1,18 +1,8 @@
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s
-// RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s -DHAVE
-// RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s -DHAVE
-// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s -DHAVE
+// RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s
-#ifdef HAVE
// expected-no-diagnostics
-#endif // HAVE
-
-#ifndef HAVE
-// expected-error@+2{{_Float16 is not supported on this target}}
-#endif // !HAVE
_Float16 f;
-
-#ifndef HAVE
-// expected-error@+2{{invalid suffix 'F16' on floating constant}}
-#endif // !HAVE
const auto g = 1.1F16;
Index: clang/test/Sema/conversion-target-dep.c
===================================================================
--- clang/test/Sema/conversion-target-dep.c
+++ clang/test/Sema/conversion-target-dep.c
@@ -6,7 +6,7 @@
long double ld;
double d;
-_Float16 f16; // x86-error {{_Float16 is not supported on this target}}
+_Float16 f16;
int main() {
ld = d; // x86-warning {{implicit conversion increases floating-point precision: 'double' to 'long double'}}
Index: clang/test/Sema/Float16.c
===================================================================
--- clang/test/Sema/Float16.c
+++ clang/test/Sema/Float16.c
@@ -1,18 +1,11 @@
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s
-// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc -target-feature +avx512fp16 %s -DHAVE
-// RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s -DHAVE
-// RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s -DHAVE
-// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s -DHAVE
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc -target-feature +avx512fp16 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s
-#ifndef HAVE
-// expected-error@+2{{_Float16 is not supported on this target}}
-#endif // HAVE
-_Float16 f;
-
-#ifdef HAVE
_Complex _Float16 a;
void builtin_complex() {
_Float16 a = 0;
(void)__builtin_complex(a, a); // expected-error {{'_Complex _Float16' is invalid}}
}
-#endif
Index: clang/test/CodeGen/X86/Float16-complex.c
===================================================================
--- clang/test/CodeGen/X86/Float16-complex.c
+++ clang/test/CodeGen/X86/Float16-complex.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown -target-feature +avx512fp16 -o - | FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown -o - | FileCheck %s --check-prefixes=X86
_Float16 _Complex add_half_rr(_Float16 a, _Float16 b) {
// X86-LABEL: @add_half_rr(
Index: clang/test/CodeGen/X86/Float16-aritmetic.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/X86/Float16-aritmetic.c
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm \
+// RUN: < %s | FileCheck %s --check-prefixes=CHECK
+
+_Float16 add1(_Float16 a, _Float16 b) {
+ // CHECK-LABEL: define {{.*}} half @add1
+ // CHECK: alloca half
+ // CHECK: alloca half
+ // CHECK: store half {{.*}}, half*
+ // CHECK: store half {{.*}}, half*
+ // CHECK: load half, half*
+ // CHECK: fpext half {{.*}} to float
+ // CHECK: load half, half* {{.*}}
+ // CHECK: fpext half {{.*}} to float
+ // CHECK: fadd float {{.*}}, {{.*}}
+ // CHECK: fptrunc float {{.*}} to half
+ // CHECK: ret half
+ return a + b;
+}
+
+_Float16 add2(_Float16 a, _Float16 b, _Float16 c) {
+ // CHECK-LABEL: define dso_local half @add2
+ // CHECK: alloca half
+ // CHECK: alloca half
+ // CHECK: alloca half
+ // CHECK: load half, half* {{.*}}
+ // CHECK: fpext half {{.*}} to float
+ // CHECK: load half, half* {{.*}}
+ // CHECK: fpext half {{.*}} to float
+ // CHECK: fadd float {{.*}}, {{.*}}
+ // CHECK: load half, half* {{.*}}
+ // CHECK: fpext half {{.*}} to float
+ // CHECK: fadd float {{.*}}, {{.*}}
+ // CHECK: fptrunc float {{.*}} to half
+ // CHECK: ret half
+ return a
++ b + c;
+}
+
+_Float16 div(_Float16 a, _Float16 b) {
+ // CHECK-LABEL: define dso_local half @div
+ // CHECK: alloca half
+ // CHECK: alloca half
+ // CHECK: store half {{.*}}, half*
+ // CHECK: store half {{.*}}, half*
+ // CHECK: load half, half* {{.*}}
+ // CHECK: fpext half {{.*}} to float
+ // CHECK: load half, half* {{.*}}
+ // CHECK: fpext half {{.*}} to float
+ // CHECK: fdiv float {{.*}}, {{.*}}
+ // CHECK: fptrunc float {{.*}} to half
+ // CHECK: ret half
+ return a / b;
+}
+
+_Float16 mul(_Float16 a, _Float16 b) {
+ // CHECK-LABEL: define dso_local half @mul
+ // CHECK: alloca half
+ // CHECK: alloca half
+ // CHECK: store half {{.*}}, half*
+ // CHECK: store half {{.*}}, half*
+ // CHECK: load half, half* {{.*}}
+ // CHECK: fpext half {{.*}} to float
+ // CHECK: load half, half* {{.*}}
+ // CHECK: fpext half {{.*}} to float
+ // CHECK: fmul float {{.*}}, {{.*}}
+ // CHECK: fptrunc float {{.*}} to half
+ // CHECK: ret half
+ return a * b;
+}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -775,7 +775,12 @@
assert(!Ty.isNull() && "UsualUnaryConversions - missing type");
// Half FP have to be promoted to float unless it is natively supported
- if (Ty->isHalfType() && !getLangOpts().NativeHalfType)
+ const llvm::Triple &TT = getASTContext().getTargetInfo().getTriple();
+ bool iSFloat16Allowed =
+ Ty->isFloat16Type() &&
+ !getASTContext().getTargetInfo().hasFeature("avx512fp16") &&
+ (TT.isX32() || TT.isX86());
+ if ((Ty->isHalfType()|| iSFloat16Allowed) && !getLangOpts().NativeHalfType)
return ImpCastExprToType(Res.get(), Context.FloatTy, CK_FloatingCast);
// Try to perform integral promotions if the object has a theoretically
Index: clang/lib/CodeGen/CGExprScalar.cpp
===================================================================
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -1306,7 +1306,13 @@
llvm::Type *DstTy = ConvertType(DstType);
// Cast from half through float if half isn't a native type.
- if (SrcType->isHalfType() && !CGF.getContext().getLangOpts().NativeHalfType) {
+ const llvm::Triple &TT = CGF.getContext().getTargetInfo().getTriple();
+ bool iSFloat16Allowed =
+ SrcType->isFloat16Type() &&
+ !CGF.getContext().getTargetInfo().hasFeature("avx512fp16") &&
+ (TT.isX32() || TT.isX86());
+ if ((SrcType->isHalfType() || iSFloat16Allowed) &&
+ !CGF.getContext().getLangOpts().NativeHalfType) {
// Cast to FP using the intrinsic if the half type itself isn't supported.
if (DstTy->isFloatingPointTy()) {
if (CGF.getContext().getTargetInfo().useFP16ConversionIntrinsics())
@@ -1432,7 +1438,12 @@
Loc);
// Cast to half through float if half isn't a native type.
- if (DstType->isHalfType() && !CGF.getContext().getLangOpts().NativeHalfType) {
+ iSFloat16Allowed =
+ DstType->isFloat16Type() &&
+ !CGF.getContext().getTargetInfo().hasFeature("avx512fp16") &&
+ (TT.isX32() || TT.isX86());
+ if ((DstType->isHalfType() || iSFloat16Allowed) &&
+ !CGF.getContext().getLangOpts().NativeHalfType) {
// Make sure we cast in a single step if from another FP type.
if (SrcTy->isFloatingPointTy()) {
// Use the intrinsic if the half type itself isn't supported
Index: clang/lib/Basic/Targets/X86.cpp
===================================================================
--- clang/lib/Basic/Targets/X86.cpp
+++ clang/lib/Basic/Targets/X86.cpp
@@ -239,7 +239,6 @@
HasAVX512ER = true;
} else if (Feature == "+avx512fp16") {
HasAVX512FP16 = true;
- HasFloat16 = true;
} else if (Feature == "+avx512pf") {
HasAVX512PF = true;
} else if (Feature == "+avx512dq") {
@@ -367,7 +366,9 @@
.Default(NoXOP);
XOPLevel = std::max(XOPLevel, XLevel);
}
-
+ // Turn on _float16 for x86 (feature sse+)
+ if (SSELevel >= NoSSE)
+ HasFloat16 = true;
// LLVM doesn't have a separate switch for fpmath, so only accept it if it
// matches the selected sse level.
if ((FPMath == FP_SSE && SSELevel < SSE1) ||
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits