Convert "denormal-fp-math" and "denormal-fp-math-f32" into a first class denormal_fpenv attribute. Previously the query for the effective denormal mode involved two string attribute queries with parsing. I'm introducing more uses of this, so it makes sense to convert this to a more efficient encoding. The old representation was also awkward since it was split across two separate attributes. The new encoding just stores the default and float modes as bitfields, largely avoiding the need to consider if the other mode is set. The syntax in the common cases looks like this: `denormal_fpenv(preservesign,preservesign)` `denormal_fpenv(float: preservesign,preservesign)` `denormal_fpenv(dynamic,dynamic float: preservesign,preservesign)` I wasn't sure about reusing the float type name instead of adding a new keyword. It's parsed as a type but only accepts float. I'm also debating switching the name to subnormal to match the current preferred IEEE terminology (also used by nofpclass and other contexts). This has a behavior change when using the command flag debug options to set the denormal mode. The behavior of the flag ignored functions with an explicit attribute set, per the default and f32 version. Now that these are one attribute, the flag logic can't distinguish which of the two components were explicitly set on the function. Only one test appeared to rely on this behavior, so I just avoided using the flags in it. This also does not perform all the code cleanups this enables. In particular the attributor handling could be cleaned up. I also guessed at how to support this in MLIR. I followed MemoryEffects as a reference; it appears bitfields are expanded into arguments to attributes, so the representation there is a bit uglier with the 2 2-element fields flattened into 4 arguments.
74 lines
2.3 KiB
Plaintext
74 lines
2.3 KiB
Plaintext
// Check that when we link a bitcode module into a file using
|
|
// -mlink-builtin-bitcode, we apply the same attributes to the functions in that
|
|
// bitcode module as we apply to functions we generate.
|
|
//
|
|
// In particular, we check that ftz and unsafe-math are propagated into the
|
|
// bitcode library as appropriate.
|
|
|
|
// Build the bitcode library. This is not built in CUDA mode, otherwise it
|
|
// might have incompatible attributes. This mirrors how libdevice is built.
|
|
// RUN: %clang_cc1 -x c++ -fconvergent-functions -emit-llvm-bc -DLIB \
|
|
// RUN: %s -o %t.bc -triple nvptx-unknown-unknown
|
|
|
|
// RUN: %clang_cc1 -x cuda %s -emit-llvm -mlink-builtin-bitcode %t.bc -o - \
|
|
// RUN: -fcuda-is-device -triple nvptx-unknown-unknown \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=NOFTZ
|
|
|
|
// RUN: %clang_cc1 -x cuda %s -emit-llvm -mlink-builtin-bitcode %t.bc \
|
|
// RUN: -fdenormal-fp-math-f32=preserve-sign -o - \
|
|
// RUN: -fcuda-is-device -triple nvptx-unknown-unknown \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=FTZ
|
|
|
|
// RUN: %clang_cc1 -x cuda %s -emit-llvm -mlink-builtin-bitcode %t.bc \
|
|
// RUN: -fdenormal-fp-math-f32=preserve-sign -o - \
|
|
// RUN: -fcuda-is-device -funsafe-math-optimizations -triple nvptx-unknown-unknown \
|
|
// RUN: | FileCheck %s --check-prefix=CHECK
|
|
|
|
#ifndef LIB
|
|
#include "Inputs/cuda.h"
|
|
#endif
|
|
|
|
// Wrap everything in extern "C" so we don't have to worry about name mangling
|
|
// in the IR.
|
|
extern "C" {
|
|
#ifdef LIB
|
|
|
|
// This function is defined in the library and only declared in the main
|
|
// compilation.
|
|
void lib_fn() {}
|
|
|
|
#else
|
|
|
|
__device__ void lib_fn();
|
|
__global__ void kernel() { lib_fn(); }
|
|
|
|
#endif
|
|
}
|
|
|
|
// The kernel and lib function should have the same attributes.
|
|
// CHECK: define{{.*}} void @kernel() [[kattr:#[0-9]+]]
|
|
// CHECK: define internal void @lib_fn() [[fattr:#[0-9]+]]
|
|
|
|
// FIXME: These -NOT checks do not work as intended and do not check on the same
|
|
// line.
|
|
|
|
// Check the attribute list for kernel.
|
|
// NOFTZ-NOT: denormal_fpenv
|
|
|
|
// CHECK: attributes [[kattr]] = {
|
|
|
|
// CHECK-SAME: convergent
|
|
// CHECK-SAME: norecurse
|
|
|
|
// FTZ-SAME: denormal_fpenv(float: preservesign)
|
|
|
|
// CHECK-SAME: "no-trapping-math"="true"
|
|
|
|
// Check the attribute list for lib_fn.
|
|
// CHECK: attributes [[fattr]] = {
|
|
|
|
// CHECK-SAME: convergent
|
|
// CHECK-NOT: norecurse
|
|
|
|
// CHECK-SAME: "no-trapping-math"="true"
|