Skip to content

Commit d3e85b9

Browse files
committedSep 13, 2016
AMDGPU: Fix target options fp32/64-denormals
Fix target options for fp32/64-denormals so that +fp64-denormals is set if fp64 is supported -fp32-denormals if fp32 denormals is not supported, or -cl-denorms-are-zero is set +fp32-denormals if fp32 denormals is supported and -cl-denorms-are-zero is not set If target feature fp32/64-denormals is explicitly set, they will override default options and options deduced from -cl-denorms-are-zero. Differential Revision: https://reviews.llvm.org/D24512 llvm-svn: 281357
1 parent 1f9ddf4 commit d3e85b9

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed
 

‎clang/lib/Basic/Targets.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,7 @@ class AMDGPUTargetInfo final : public TargetInfo {
19651965
bool hasFP64:1;
19661966
bool hasFMAF:1;
19671967
bool hasLDEXPF:1;
1968-
bool hasDenormSupport:1;
1968+
bool hasFullSpeedFP32Denorms:1;
19691969

19701970
static bool isAMDGCN(const llvm::Triple &TT) {
19711971
return TT.getArch() == llvm::Triple::amdgcn;
@@ -1978,14 +1978,12 @@ class AMDGPUTargetInfo final : public TargetInfo {
19781978
hasFP64(false),
19791979
hasFMAF(false),
19801980
hasLDEXPF(false),
1981-
hasDenormSupport(false){
1981+
hasFullSpeedFP32Denorms(false){
19821982
if (getTriple().getArch() == llvm::Triple::amdgcn) {
19831983
hasFP64 = true;
19841984
hasFMAF = true;
19851985
hasLDEXPF = true;
19861986
}
1987-
if (Opts.CPU == "fiji")
1988-
hasDenormSupport = true;
19891987

19901988
resetDataLayout(getTriple().getArch() == llvm::Triple::amdgcn ?
19911989
DataLayoutStringSI : DataLayoutStringR600);
@@ -2040,8 +2038,6 @@ class AMDGPUTargetInfo final : public TargetInfo {
20402038

20412039
void adjustTargetOptions(const CodeGenOptions &CGOpts,
20422040
TargetOptions &TargetOpts) const override {
2043-
if (!hasDenormSupport)
2044-
return;
20452041
bool hasFP32Denormals = false;
20462042
bool hasFP64Denormals = false;
20472043
for (auto &I : TargetOpts.FeaturesAsWritten) {
@@ -2051,11 +2047,11 @@ class AMDGPUTargetInfo final : public TargetInfo {
20512047
hasFP64Denormals = true;
20522048
}
20532049
if (!hasFP32Denormals)
2054-
TargetOpts.Features.push_back((Twine(CGOpts.FlushDenorm ? '-' : '+') +
2055-
Twine("fp32-denormals")).str());
2050+
TargetOpts.Features.push_back((Twine(hasFullSpeedFP32Denorms &&
2051+
!CGOpts.FlushDenorm ? '+' : '-') + Twine("fp32-denormals")).str());
2052+
// Always do not flush fp64 denorms.
20562053
if (!hasFP64Denormals && hasFP64)
2057-
TargetOpts.Features.push_back((Twine(CGOpts.FlushDenorm ? '-' : '+') +
2058-
Twine("fp64-denormals")).str());
2054+
TargetOpts.Features.push_back("+fp64-denormals");
20592055
}
20602056

20612057
ArrayRef<Builtin::Info> getTargetBuiltins() const override {
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
// RUN: %clang_cc1 -S -cl-denorms-are-zero -o - %s 2>&1
22
// RUN: %clang_cc1 -emit-llvm -cl-denorms-are-zero -o - -triple amdgcn--amdhsa -target-cpu fiji %s | FileCheck %s
33
// RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn--amdhsa -target-cpu fiji %s | FileCheck %s --check-prefix=CHECK-DENORM
4+
// RUN: %clang_cc1 -emit-llvm -target-feature +fp32-denormals -target-feature -fp64-denormals -cl-denorms-are-zero -o - -triple amdgcn--amdhsa -target-cpu fiji %s | FileCheck --check-prefix=CHECK-FEATURE %s
45

56
// For non-amdgcn targets, this test just checks that the -cl-denorms-are-zero argument is accepted
67
// by clang. This option is currently a no-op, which is allowed by the
78
// OpenCL specification.
89

10+
// For amdgcn target cpu fiji, fp32 should be flushed since fiji does not support fp32 denormals, unless +fp32-denormals is
11+
// explicitly set. amdgcn target always do not flush fp64 denormals.
12+
913
// CHECK-DENORM-LABEL: define void @f()
10-
// CHECK-DENORM: attributes #{{[0-9]*}} = {{{[^}]*}} "target-features"="{{[^"]*}}+fp32-denormals,+fp64-denormals{{[^"]*}}"
14+
// CHECK-DENORM: attributes #{{[0-9]*}} = {{{[^}]*}} "target-features"="{{[^"]*}}+fp64-denormals,{{[^"]*}}-fp32-denormals{{[^"]*}}"
1115
// CHECK-LABEL: define void @f()
12-
// CHECK-NOT: attributes #{{[0-9]*}} = {{{[^}]*}} "target-features"="{{[^"]*}}+fp32-denormals,+fp64-denormals{{[^"]*}}"
16+
// CHECK: attributes #{{[0-9]*}} = {{{[^}]*}} "target-features"="{{[^"]*}}+fp64-denormals,{{[^"]*}}-fp32-denormals{{[^"]*}}"
17+
// CHECK-FEATURE-LABEL: define void @f()
18+
// CHECK-FEATURE: attributes #{{[0-9]*}} = {{{[^}]*}} "target-features"="{{[^"]*}}+fp32-denormals,{{[^"]*}}-fp64-denormals{{[^"]*}}"
1319
void f() {}

0 commit comments

Comments
 (0)
Please sign in to comment.