[clang] af9ee33 - [HIP] fix long double size

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 14 18:58:23 PDT 2022


Author: Yaxun (Sam) Liu
Date: 2022-06-14T21:57:56-04:00
New Revision: af9ee3357cec931af68a3a0bb83e82de977caa37

URL: https://github.com/llvm/llvm-project/commit/af9ee3357cec931af68a3a0bb83e82de977caa37
DIFF: https://github.com/llvm/llvm-project/commit/af9ee3357cec931af68a3a0bb83e82de977caa37.diff

LOG: [HIP] fix long double size

For amdgpu target long double type is the same as double type.
The width and align of long double type was incorrectly
overridden when copying aux target properties, which
caused assertion in codegen when emitting global
variables with long double type.

This patch fix that by saving and restoring width
and align of long double type.

Reviewed by: Artem Belevich

Differential Revision: https://reviews.llvm.org/D127771

Fixes: SWDEV-335515

Added: 
    clang/test/CodeGenCUDA/long-double.cu

Modified: 
    clang/lib/Basic/Targets/AMDGPU.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Targets/AMDGPU.cpp b/clang/lib/Basic/Targets/AMDGPU.cpp
index a1edc0d53ecba..66e9a22ca1ebb 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -462,9 +462,13 @@ void AMDGPUTargetInfo::setAuxTarget(const TargetInfo *Aux) {
   // supported by AMDGPU. Therefore keep its own format for these two types.
   auto SaveLongDoubleFormat = LongDoubleFormat;
   auto SaveFloat128Format = Float128Format;
+  auto SaveLongDoubleWidth = LongDoubleWidth;
+  auto SaveLongDoubleAlign = LongDoubleAlign;
   copyAuxTarget(Aux);
   LongDoubleFormat = SaveLongDoubleFormat;
   Float128Format = SaveFloat128Format;
+  LongDoubleWidth = SaveLongDoubleWidth;
+  LongDoubleAlign = SaveLongDoubleAlign;
   // For certain builtin types support on the host target, claim they are
   // support to pass the compilation of the host code during the device-side
   // compilation.

diff  --git a/clang/test/CodeGenCUDA/long-double.cu b/clang/test/CodeGenCUDA/long-double.cu
new file mode 100644
index 0000000000000..454a93ce5f6b6
--- /dev/null
+++ b/clang/test/CodeGenCUDA/long-double.cu
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx906 \
+// RUN:   -aux-triple x86_64-unknown-gnu-linux -fcuda-is-device \
+// RUN:   -emit-llvm -o - -x hip %s 2>&1 | FileCheck %s
+
+// RUN: %clang_cc1 -triple nvptx \
+// RUN:   -aux-triple x86_64-unknown-gnu-linux -fcuda-is-device \
+// RUN:   -emit-llvm -o - %s 2>&1 | FileCheck %s
+
+// CHECK: @_ZN15infinity_helperIeE5valueE = {{.*}} double 0x47EFFFFFD586B834, align 8
+// CHECK: @size = {{.*}} i32 8
+
+#include "Inputs/cuda.h"
+
+template <class> struct infinity_helper {};
+template <> struct infinity_helper<long double> { static constexpr long double value = 3.4028234e38L; };
+constexpr long double infinity_helper<long double>::value;
+__device__ int size = sizeof(long double);


        


More information about the cfe-commits mailing list