[PATCH] D24512: AMDGPU: Fix target options fp32/64-denormals

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 13 09:33:28 PDT 2016


yaxunl created this revision.
yaxunl added reviewers: tstellarAMD, nhaustov, arsenm.
yaxunl added subscribers: cfe-commits, AMDGPU.
Herald added a subscriber: wdng.

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


https://reviews.llvm.org/D24512

Files:
  lib/Basic/Targets.cpp
  test/CodeGenOpenCL/denorms-are-zero.cl

Index: test/CodeGenOpenCL/denorms-are-zero.cl
===================================================================
--- test/CodeGenOpenCL/denorms-are-zero.cl
+++ test/CodeGenOpenCL/denorms-are-zero.cl
@@ -1,13 +1,19 @@
 // RUN: %clang_cc1 -S -cl-denorms-are-zero -o - %s 2>&1
 // RUN: %clang_cc1 -emit-llvm -cl-denorms-are-zero -o - -triple amdgcn--amdhsa -target-cpu fiji %s | FileCheck %s
 // RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn--amdhsa -target-cpu fiji %s | FileCheck %s --check-prefix=CHECK-DENORM
+// 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
 
 // For non-amdgcn targets, this test just checks that the -cl-denorms-are-zero argument is accepted
 // by clang.  This option is currently a no-op, which is allowed by the
 // OpenCL specification.
 
+// For amdgcn target cpu fiji, fp32 should be flushed since fiji does not support fp32 denormals, unless +fp32-denormals is
+// explicitly set. amdgcn target always do not flush fp64 denormals.
+
 // CHECK-DENORM-LABEL: define void @f()
-// CHECK-DENORM: attributes #{{[0-9]*}} = {{{[^}]*}} "target-features"="{{[^"]*}}+fp32-denormals,+fp64-denormals{{[^"]*}}"
+// CHECK-DENORM: attributes #{{[0-9]*}} = {{{[^}]*}} "target-features"="{{[^"]*}}+fp64-denormals,{{[^"]*}}-fp32-denormals{{[^"]*}}"
 // CHECK-LABEL: define void @f()
-// CHECK-NOT: attributes #{{[0-9]*}} = {{{[^}]*}} "target-features"="{{[^"]*}}+fp32-denormals,+fp64-denormals{{[^"]*}}"
+// CHECK: attributes #{{[0-9]*}} = {{{[^}]*}} "target-features"="{{[^"]*}}+fp64-denormals,{{[^"]*}}-fp32-denormals{{[^"]*}}"
+// CHECK-FEATURE-LABEL: define void @f()
+// CHECK-FEATURE: attributes #{{[0-9]*}} = {{{[^}]*}} "target-features"="{{[^"]*}}+fp32-denormals,{{[^"]*}}-fp64-denormals{{[^"]*}}"
 void f() {}
Index: lib/Basic/Targets.cpp
===================================================================
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -1959,7 +1959,7 @@
   bool hasFP64:1;
   bool hasFMAF:1;
   bool hasLDEXPF:1;
-  bool hasDenormSupport:1;
+  bool hasFP32DenormSupport:1;
 
   static bool isAMDGCN(const llvm::Triple &TT) {
     return TT.getArch() == llvm::Triple::amdgcn;
@@ -1972,14 +1972,12 @@
       hasFP64(false),
       hasFMAF(false),
       hasLDEXPF(false),
-      hasDenormSupport(false){
+      hasFP32DenormSupport(false){
     if (getTriple().getArch() == llvm::Triple::amdgcn) {
       hasFP64 = true;
       hasFMAF = true;
       hasLDEXPF = true;
     }
-    if (Opts.CPU == "fiji")
-      hasDenormSupport = true;
 
     resetDataLayout(getTriple().getArch() == llvm::Triple::amdgcn ?
                     DataLayoutStringSI : DataLayoutStringR600);
@@ -2034,8 +2032,6 @@
 
   void adjustTargetOptions(const CodeGenOptions &CGOpts,
                            TargetOptions &TargetOpts) const override {
-    if (!hasDenormSupport)
-      return;
     bool hasFP32Denormals = false;
     bool hasFP64Denormals = false;
     for (auto &I : TargetOpts.FeaturesAsWritten) {
@@ -2045,11 +2041,11 @@
         hasFP64Denormals = true;
     }
     if (!hasFP32Denormals)
-      TargetOpts.Features.push_back((Twine(CGOpts.FlushDenorm ? '-' : '+') +
-                                     Twine("fp32-denormals")).str());
+      TargetOpts.Features.push_back((Twine(hasFP32DenormSupport &&
+          !CGOpts.FlushDenorm ? '+' : '-') + Twine("fp32-denormals")).str());
+    // Always do not flush fp64 denorms.
     if (!hasFP64Denormals && hasFP64)
-      TargetOpts.Features.push_back((Twine(CGOpts.FlushDenorm ? '-' : '+') +
-                                     Twine("fp64-denormals")).str());
+      TargetOpts.Features.push_back("+fp64-denormals");
   }
 
   ArrayRef<Builtin::Info> getTargetBuiltins() const override {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24512.71183.patch
Type: text/x-patch
Size: 3845 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160913/24a04ffc/attachment.bin>


More information about the cfe-commits mailing list