[PATCH] D80315: Fix CC1 command line options mapping into fast-math flags.

Michele Scandale via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 20 10:54:50 PDT 2020


michele.scandale created this revision.
michele.scandale added reviewers: rjmccall, mibintc, Anastasia.
Herald added subscribers: cfe-commits, jvesely.
Herald added a project: clang.
michele.scandale marked an inline comment as done.
michele.scandale added inline comments.
michele.scandale marked 2 inline comments as done.


================
Comment at: clang/test/CodeGen/libcalls.c:11-21
+  // CHECK-FAST: call reassoc nsz arcp afn float @llvm.sqrt.f32(float
   float l0 = sqrtf(a0);
 
   // CHECK-YES: call double @sqrt
   // CHECK-NO: call double @llvm.sqrt.f64(double
-  // CHECK-FAST: call double @llvm.sqrt.f64(double
+  // CHECK-FAST: call reassoc nsz arcp afn double @llvm.sqrt.f64(double
   double l1 = sqrt(a1);
----------------
For CUDA the default FP contract mode is `fast`, therefore the `contract` FMF is emitted.


================
Comment at: clang/test/CodeGenCUDA/builtins-amdgcn.cu:13
 // CHECK-LABEL: @_Z12test_ds_fmaxf(
-// CHECK: call float @llvm.amdgcn.ds.fmax(float addrspace(3)* @_ZZ12test_ds_fmaxfE6shared, float %{{[^,]*}}, i32 0, i32 0, i1 false)
+// CHECK: call contract float @llvm.amdgcn.ds.fmax(float addrspace(3)* @_ZZ12test_ds_fmaxfE6shared, float %{{[^,]*}}, i32 0, i32 0, i1 false)
 __global__
----------------
For CUDA the default FP contract mode is `fast`, therefore the `contract` FMF is emitted.


================
Comment at: clang/test/CodeGenOpenCL/relaxed-fpmath.cl:14
   // FINITE: fdiv nnan ninf float
-  // UNSAFE: fdiv nnan nsz float
+  // UNSAFE: fdiv reassoc nsz arcp afn float
   // MAD: fdiv float
----------------
This change is based on the following:
* `-cl-fast-relaxed-math` = `-cl-unsafe-math-optimizations` + `-cl-finite-math-only` 
* the GCC option `-funsafe-math-optimizations` and `-cl-unsafe-math-optimizations` are described with very similar wording and from the GCC description states explicitly mention that no signed zeros, reassociation and reciprocals are enabled, but there is no mention to assuming that NaNs do not exist.

See https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/clBuildProgram.html and https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html


This fixes the mapping between CC1 command line options to the
properties in `LangOptions` describing the floating point optimizations
configuration.
The default fast-math flags for the IR builder are now derived from such
properties to avoid inconsistencies.
Finally some of the `CodeGenOptions` floating point optimizations
properties have been removed since they are now exist in `LangOptions`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80315

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/builtins-nvptx-ptx60.cu
  clang/test/CodeGen/complex-math.c
  clang/test/CodeGen/fp-options-to-fast-math-flags.c
  clang/test/CodeGen/libcalls.c
  clang/test/CodeGenCUDA/builtins-amdgcn.cu
  clang/test/CodeGenOpenCL/relaxed-fpmath.cl

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80315.265301.patch
Type: text/x-patch
Size: 24837 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200520/86d803b3/attachment-0001.bin>


More information about the cfe-commits mailing list