llvm-project/clang/lib/Frontend
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
..
Rewrite [CMake] Use #cmakedefine01 for CLANG_ENABLE_(ARCMT|OBJC_REWRITER|STATIC_ANALYZER) 2017-10-18 05:21:17 +00:00
ASTConsumers.cpp Handle -ast-dump-all when passed as the only option. 2017-06-15 00:00:08 +00:00
ASTMerge.cpp Teach ASTReader how to read only the Preprocessor state from an AST file, not the ASTContext state. 2017-06-29 23:23:46 +00:00
ASTUnit.cpp [clang] Add PPCallbacks list to preprocessor when building a preacompiled preamble. 2017-12-15 11:27:51 +00:00
CMakeLists.txt Moved code hanlding precompiled preamble out of the ASTUnit. 2017-06-21 10:24:58 +00:00
CacheTokens.cpp Fix the build with MSVC 2013 after r283856 2016-10-11 17:24:09 +00:00
ChainedDiagnosticConsumer.cpp
ChainedIncludesSource.cpp Teach ASTReader how to read only the Preprocessor state from an AST file, not the ASTContext state. 2017-06-29 23:23:46 +00:00
CodeGenOptions.cpp revert SVN r265702, r265640 2016-04-08 16:52:00 +00:00
CompilerInstance.cpp Driver: hoist the `wchar_t` handling to the driver 2017-10-06 23:09:55 +00:00
CompilerInvocation.cpp [Driver, CodeGen] pass through and apply -fassociative-math 2017-12-16 16:11:17 +00:00
CreateInvocationFromCommandLine.cpp Use vfs::FileSystem in ASTUnit when creating CompilerInvocation. 2017-06-28 15:06:34 +00:00
DependencyFile.cpp Revert r316193. 2017-10-20 00:25:07 +00:00
DependencyGraph.cpp
DiagnosticRenderer.cpp Revert "Revert "[NFC] Refactor DiagnosticRenderer to use FullSourceLoc"" 2017-06-27 09:50:38 +00:00
FrontendAction.cpp Use the VFS from the CompilerInvocation by default 2017-09-12 16:54:53 +00:00
FrontendActions.cpp Allow to store precompiled preambles in memory. 2017-11-16 16:25:01 +00:00
FrontendOptions.cpp Move functionality for handling module maps as inputs from the -emit-module 2017-04-28 01:49:42 +00:00
HeaderIncludeGen.cpp [Frontend] StringRefize and fix bad indentation. 2016-05-27 12:52:19 +00:00
InitHeaderSearch.cpp Revert "Add /System/Library/PrivateFrameworks as a header search path." 2017-10-02 18:22:19 +00:00
InitPreprocessor.cpp Revert 320391: Certain targets are failing, pulling back to diagnose. 2017-12-11 18:14:51 +00:00
LangStandards.cpp Don't accept -std= values that would switch us to a different source language. 2017-04-26 23:44:33 +00:00
LayoutOverrideSource.cpp Annotate dump() methods with LLVM_DUMP_METHOD, addressing Richard Smith r259192 post commit comment. 2016-01-29 19:38:18 +00:00
LogDiagnosticPrinter.cpp Replace double negation of !FileID.isInvalid() with FileID.isValid(). 2015-10-03 10:46:20 +00:00
ModuleDependencyCollector.cpp fix trivial typos; NFC 2017-07-01 08:46:43 +00:00
MultiplexConsumer.cpp Generalize "static data member instantiated" notification to cover variable templates too. 2017-12-05 01:31:47 +00:00
PCHContainerOperations.cpp Bitcode: Decouple block info block state from reader. 2016-11-08 04:17:11 +00:00
PrecompiledPreamble.cpp [clang] Add PPCallbacks list to preprocessor when building a preacompiled preamble. 2017-12-15 11:27:51 +00:00
PrintPreprocessedOutput.cpp Don't print end-of-directive tokens in -E output 2017-10-16 23:07:15 +00:00
SerializedDiagnosticPrinter.cpp Revert "Revert "[NFC] Refactor DiagnosticRenderer to use FullSourceLoc"" 2017-06-27 09:50:38 +00:00
SerializedDiagnosticReader.cpp [Frontend] Verify that the bitstream is not empty before reading 2017-07-07 10:25:12 +00:00
TestModuleFileExtension.cpp Fix for LLVM Bitcode API change (to use std::shared_ptr) 2017-01-04 22:36:43 +00:00
TestModuleFileExtension.h Module file extensions: pass a Sema through to the extension writer. 2015-12-08 22:43:32 +00:00
TextDiagnostic.cpp [clang] buildFixItInsertionLine should use Hints of the same FID and LineNo 2017-07-12 16:25:40 +00:00
TextDiagnosticBuffer.cpp [TextDiagnosticBuffer] Fix diagnostic note emission order 2017-12-16 01:40:19 +00:00
TextDiagnosticPrinter.cpp Revert "Revert "[NFC] Refactor DiagnosticRenderer to use FullSourceLoc"" 2017-06-27 09:50:38 +00:00
VerifyDiagnosticConsumer.cpp [VerifyDiagnosticConsumer] support -verify=<prefixes> 2017-12-16 02:23:22 +00:00