Index: clang/lib/Driver/ToolChains/HIP.cpp =================================================================== --- clang/lib/Driver/ToolChains/HIP.cpp +++ clang/lib/Driver/ToolChains/HIP.cpp @@ -285,6 +285,7 @@ (void) GpuArch; assert(DeviceOffloadingKind == Action::OFK_HIP && "Only HIP offloading kinds are supported for GPUs."); + auto Kind = llvm::AMDGPU::parseArchAMDGCN(GpuArch); CC1Args.push_back("-target-cpu"); CC1Args.push_back(DriverArgs.MakeArgStringRef(GpuArch)); @@ -345,11 +346,14 @@ std::string GFXVersion = GpuArch.drop_front(3).str(); std::string ISAVerBC = "oclc_isa_version_" + GFXVersion + ".amdgcn.bc"; - llvm::StringRef FlushDenormalControlBC; - if (DriverArgs.hasArg(options::OPT_fcuda_flush_denormals_to_zero)) - FlushDenormalControlBC = "oclc_daz_opt_on.amdgcn.bc"; - else - FlushDenormalControlBC = "oclc_daz_opt_off.amdgcn.bc"; + bool FTZDAZ = DriverArgs.hasFlag( + options::OPT_fcuda_flush_denormals_to_zero, + options::OPT_fno_cuda_flush_denormals_to_zero, + getDefaultDenormsAreZeroForTarget(Kind)); + + std::string FlushDenormalControlBC = FTZDAZ ? + "oclc_daz_opt_on.amdgcn.bc" : + "oclc_daz_opt_off.amdgcn.bc"; llvm::StringRef WaveFrontSizeBC; if (stoi(GFXVersion) < 1000) @@ -359,7 +363,7 @@ BCLibs.append({"hip.amdgcn.bc", "ocml.amdgcn.bc", "ockl.amdgcn.bc", "oclc_finite_only_off.amdgcn.bc", - std::string(FlushDenormalControlBC), + FlushDenormalControlBC, "oclc_correctly_rounded_sqrt_on.amdgcn.bc", "oclc_unsafe_math_off.amdgcn.bc", ISAVerBC, std::string(WaveFrontSizeBC)}); Index: clang/test/Driver/hip-device-libs.hip =================================================================== --- clang/test/Driver/hip-device-libs.hip +++ clang/test/Driver/hip-device-libs.hip @@ -2,23 +2,94 @@ // REQUIRES: x86-registered-target // REQUIRES: amdgpu-registered-target -// Test flush-denormals-to-zero enabled uses oclc_daz_opt_on +// Test if if oclc_daz_opt_on or if oclc_daz_opt_off is linked depending on +// expected denormal mode. +// Test subtarget with flushing on by default. +// RUN: %clang -### -target x86_64-linux-gnu \ +// RUN: --cuda-gpu-arch=gfx803 \ +// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \ +// RUN: %S/Inputs/hip_multiple_inputs/b.hip \ +// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD + + +// Test subtarget with flushing off by ddefault. // RUN: %clang -### -target x86_64-linux-gnu \ // RUN: --cuda-gpu-arch=gfx900 \ // RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \ +// RUN: %S/Inputs/hip_multiple_inputs/b.hip \ +// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD + + +// Test explicit flag, opposite of target default. +// RUN: %clang -### -target x86_64-linux-gnu \ +// RUN: --cuda-gpu-arch=gfx900 \ // RUN: -fcuda-flush-denormals-to-zero \ +// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \ // RUN: %S/Inputs/hip_multiple_inputs/b.hip \ // RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD -// Test flush-denormals-to-zero disabled uses oclc_daz_opt_off +// Test explicit flag, opposite of target default. +// RUN: %clang -### -target x86_64-linux-gnu \ +// RUN: --cuda-gpu-arch=gfx803 \ +// RUN: -fno-cuda-flush-denormals-to-zero \ +// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \ +// RUN: %S/Inputs/hip_multiple_inputs/b.hip \ +// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD + + +// Test explicit flag, same as target default. // RUN: %clang -### -target x86_64-linux-gnu \ // RUN: --cuda-gpu-arch=gfx900 \ +// RUN: -fno-cuda-flush-denormals-to-zero \ // RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \ // RUN: %S/Inputs/hip_multiple_inputs/b.hip \ // RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD + +// Test explicit flag, same as target default. +// RUN: %clang -### -target x86_64-linux-gnu \ +// RUN: --cuda-gpu-arch=gfx803 \ +// RUN: -fcuda-flush-denormals-to-zero \ +// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \ +// RUN: %S/Inputs/hip_multiple_inputs/b.hip \ +// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD + + +// Test last flag wins, not flushing +// RUN: %clang -### -target x86_64-linux-gnu \ +// RUN: --cuda-gpu-arch=gfx803 \ +// RUN: -fcuda-flush-denormals-to-zero -fno-cuda-flush-denormals-to-zero \ +// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \ +// RUN: %S/Inputs/hip_multiple_inputs/b.hip \ +// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD + + +// RUN: %clang -### -target x86_64-linux-gnu \ +// RUN: --cuda-gpu-arch=gfx900 \ +// RUN: -fcuda-flush-denormals-to-zero -fno-cuda-flush-denormals-to-zero \ +// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \ +// RUN: %S/Inputs/hip_multiple_inputs/b.hip \ +// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,NOFLUSHD + + +// RUN: %clang -### -target x86_64-linux-gnu \ +// RUN: --cuda-gpu-arch=gfx900 \ +// RUN: -fno-cuda-flush-denormals-to-zero -fcuda-flush-denormals-to-zero \ +// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \ +// RUN: %S/Inputs/hip_multiple_inputs/b.hip \ +// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD + + +// RUN: %clang -### -target x86_64-linux-gnu \ +// RUN: --cuda-gpu-arch=gfx803 \ +// RUN: -fno-cuda-flush-denormals-to-zero -fcuda-flush-denormals-to-zero \ +// RUN: --hip-device-lib-path=%S/Inputs/hip_dev_lib \ +// RUN: %S/Inputs/hip_multiple_inputs/b.hip \ +// RUN: 2>&1 | FileCheck %s --check-prefixes=COM,FLUSHD + + // Test environment variable HIP_DEVICE_LIB_PATH // RUN: env HIP_DEVICE_LIB_PATH=%S/Inputs/hip_dev_lib \ @@ -33,4 +104,3 @@ // COM-SAME: "-mlink-builtin-bitcode" "{{.*}}ockl.amdgcn.bc" // FLUSHD-SAME: "-mlink-builtin-bitcode" "{{.*}}oclc_daz_opt_on.amdgcn.bc" // NOFLUSHD-SAME: "-mlink-builtin-bitcode" "{{.*}}oclc_daz_opt_off.amdgcn.bc" -