llvm-project/clang/lib/Driver
Sanjay Patel cb8c009801 [Driver, CodeGen] pass through and apply -fassociative-math
There are 2 parts to getting the -fassociative-math command-line flag translated to LLVM FMF:

1. In the driver/frontend, we accept the flag and its 'no' inverse and deal with the 
   interactions with other flags like -ffast-math -fno-signed-zeros -fno-trapping-math. 
   This was mostly already done - we just need to translate the flag as a codegen option. 
   The test file is complicated because there are many potential combinations of flags here.
   Note that we are matching gcc's behavior that requires 'nsz' and no-trapping-math.

2. In codegen, we map the codegen option to FMF in the IR builder. This is simple code and 
   corresponding test.

For the motivating example from PR27372:

float foo(float a, float x) { return ((a + x) - x); }

$ ./clang -O2 27372.c -S -o - -ffast-math  -fno-associative-math -emit-llvm  | egrep 'fadd|fsub'
  %add = fadd nnan ninf nsz arcp contract float %0, %1
  %sub = fsub nnan ninf nsz arcp contract float %add, %2

So 'reassoc' is off as expected (and so is the new 'afn' but that's a different patch). 
This case now works as expected end-to-end although the underlying logic is still wrong:

$ ./clang  -O2 27372.c -S -o - -ffast-math  -fno-associative-math | grep xmm
	addss	%xmm1, %xmm0
	subss	%xmm1, %xmm0

We're not done because the case where 'reassoc' is set is ignored by optimizer passes. Example:

$ ./clang  -O2 27372.c -S -o - -fassociative-math -fno-signed-zeros -fno-trapping-math -emit-llvm  | grep fadd
  %add = fadd reassoc float %0, %1

$ ./clang -O2  27372.c -S -o - -fassociative-math -fno-signed-zeros -fno-trapping-math | grep xmm
	addss	%xmm1, %xmm0
	subss	%xmm1, %xmm0

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

llvm-svn: 320920
2017-12-16 16:11:17 +00:00
..
ToolChains [Driver, CodeGen] pass through and apply -fassociative-math 2017-12-16 16:11:17 +00:00
Action.cpp Fix MSVC "not all control paths return a value" warning 2016-10-28 10:09:35 +00:00
CMakeLists.txt Remove Bitrig: Clang Changes 2017-07-21 22:46:31 +00:00
Compilation.cpp [Driver] Make clang/cc conforms to UNIX standard 2017-11-10 01:32:47 +00:00
Distro.cpp [Driver] add initial support for alpine linux 2017-11-19 00:08:12 +00:00
Driver.cpp [AutoComplete] Use stronger sort predicate for autocomplete candidates to remove non-deterministic ordering 2017-11-20 18:49:14 +00:00
DriverOptions.cpp Revert "Revert r311552: [Bash-autocompletion] Add support for static analyzer flags" 2017-08-29 00:09:31 +00:00
InputInfo.h Add an Action* member to InputInfo. 2016-01-11 23:15:21 +00:00
Job.cpp Revert 320391: Certain targets are failing, pulling back to diagnose. 2017-12-11 18:14:51 +00:00
Multilib.cpp Multilib: add dump methods 2017-05-05 21:30:13 +00:00
Phases.cpp
SanitizerArgs.cpp Hardware-assisted AddressSanitizer (clang part). 2017-12-09 01:32:07 +00:00
Tool.cpp Rename the version of ConstructJob for multiple outputs to ConstructJobMultipleOutputs. 2016-11-03 15:41:50 +00:00
ToolChain.cpp [driver] Set the 'simulator' environment for Darwin when compiling for 2017-12-07 19:04:10 +00:00
Types.cpp [Driver][OpenMP] Update actions builder to create unbundling action when necessary. 2016-10-27 18:00:51 +00:00
XRayArgs.cpp [XRay][clang] Introduce -fxray-always-emit-customevents 2017-11-30 00:04:54 +00:00