diff options
| author | Tom Stellard <thomas.stellard@amd.com> | 2014-04-11 20:31:22 +0000 |
|---|---|---|
| committer | Tom Stellard <thomas.stellard@amd.com> | 2014-04-11 20:31:22 +0000 |
| commit | fcc3bc0951c492ee3d36c58bb61453ecf3f25fd1 (patch) | |
| tree | 6b1fac39fca86d7a78855cee1c25e194b2d15132 | |
| parent | dce55aa1d529e1a07f41241c6a54b9570e0cec64 (diff) | |
| download | clang-fcc3bc0951c492ee3d36c58bb61453ecf3f25fd1.tar.gz clang-fcc3bc0951c492ee3d36c58bb61453ecf3f25fd1.tar.bz2 clang-fcc3bc0951c492ee3d36c58bb61453ecf3f25fd1.tar.xz | |
Merging r204742:
------------------------------------------------------------------------
r204742 | benny.kra | 2014-03-25 14:02:07 -0400 (Tue, 25 Mar 2014) | 10 lines
Fix an logic error in the clang driver preventing crtfastmath.o from linking when -Ofast is used without -ffast-math
In gcc using -Ofast forces linking of crtfastmath.o.
In the current clang crtfastmath.o is only linked when -ffast-math/-funsafe-math-optimizations passed. It can lead to performance issues, when using only -Ofast without explicit -ffast-math (I faced with it).
My patch fixes inconsistency with gcc behaviour and also introduces few tests on it.
Patch by Zinovy Nis!
Differential Revision: http://llvm-reviews.chandlerc.com/D3114
------------------------------------------------------------------------
git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_34@206066 91177308-0d34-0410-b5e6-96231b3b80d8
| -rw-r--r-- | include/clang/Driver/Driver.h | 4 | ||||
| -rw-r--r-- | include/clang/Driver/ToolChain.h | 2 | ||||
| -rw-r--r-- | lib/Driver/Driver.cpp | 4 | ||||
| -rw-r--r-- | lib/Driver/ToolChain.cpp | 23 | ||||
| -rw-r--r-- | lib/Driver/Tools.cpp | 7 | ||||
| -rw-r--r-- | test/Driver/linux-ld.c | 23 |
6 files changed, 44 insertions, 19 deletions
diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h index 867444ea4e..73c8086093 100644 --- a/include/clang/Driver/Driver.h +++ b/include/clang/Driver/Driver.h @@ -415,6 +415,10 @@ public: bool &HadExtra); }; +/// \return True if the last defined optimization level is -Ofast. +/// And False otherwise. +bool isOptimizationLevelFast(const llvm::opt::ArgList &Args); + } // end namespace driver } // end namespace clang diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h index 84e0b55ba5..c212a83322 100644 --- a/include/clang/Driver/ToolChain.h +++ b/include/clang/Driver/ToolChain.h @@ -303,7 +303,7 @@ public: /// AddFastMathRuntimeIfAvailable - If a runtime library exists that sets /// global flags for unsafe floating point math, add it and return true. /// - /// This checks for presence of the -ffast-math or -funsafe-math flags. + /// This checks for presence of the -Ofast, -ffast-math or -funsafe-math flags. virtual bool AddFastMathRuntimeIfAvailable(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 0c7a8717f8..c23aeff055 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -2059,3 +2059,7 @@ std::pair<unsigned, unsigned> Driver::getIncludeExcludeOptionFlagMasks() const { return std::make_pair(IncludedFlagsBitmask, ExcludedFlagsBitmask); } + +bool clang::driver::isOptimizationLevelFast(const llvm::opt::ArgList &Args) { + return Args.hasFlag(options::OPT_Ofast, options::OPT_O_Group, false); +} diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp index efd3945b3d..36aae33ec8 100644 --- a/lib/Driver/ToolChain.cpp +++ b/lib/Driver/ToolChain.cpp @@ -430,16 +430,19 @@ void ToolChain::AddCCKextLibArgs(const ArgList &Args, bool ToolChain::AddFastMathRuntimeIfAvailable(const ArgList &Args, ArgStringList &CmdArgs) const { - // Check if -ffast-math or -funsafe-math is enabled. - Arg *A = Args.getLastArg(options::OPT_ffast_math, - options::OPT_fno_fast_math, - options::OPT_funsafe_math_optimizations, - options::OPT_fno_unsafe_math_optimizations); - - if (!A || A->getOption().getID() == options::OPT_fno_fast_math || - A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations) - return false; - + // Do not check for -fno-fast-math or -fno-unsafe-math when -Ofast passed + // (to keep the linker options consistent with gcc and clang itself). + if (!isOptimizationLevelFast(Args)) { + // Check if -ffast-math or -funsafe-math. + Arg *A = + Args.getLastArg(options::OPT_ffast_math, options::OPT_fno_fast_math, + options::OPT_funsafe_math_optimizations, + options::OPT_fno_unsafe_math_optimizations); + + if (!A || A->getOption().getID() == options::OPT_fno_fast_math || + A->getOption().getID() == options::OPT_fno_unsafe_math_optimizations) + return false; + } // If crtfastmath.o exists add it to the arguments. std::string Path = GetFilePath("crtfastmath.o"); if (Path == "crtfastmath.o") // Not found. diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 29713ed1b4..5093ae1015 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1995,13 +1995,6 @@ static void SplitDebugInfo(const ToolChain &TC, Compilation &C, C.addCommand(new Command(JA, T, Exec, StripArgs)); } -static bool isOptimizationLevelFast(const ArgList &Args) { - if (Arg *A = Args.getLastArg(options::OPT_O_Group)) - if (A->getOption().matches(options::OPT_Ofast)) - return true; - return false; -} - /// \brief Vectorize at all optimization levels greater than 1 except for -Oz. static bool shouldEnableVectorizerAtOLevel(const ArgList &Args) { if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { diff --git a/test/Driver/linux-ld.c b/test/Driver/linux-ld.c index 755fa04055..827afb3310 100644 --- a/test/Driver/linux-ld.c +++ b/test/Driver/linux-ld.c @@ -681,7 +681,7 @@ // CHECK-FSL-PPC64: "{{.*}}{{/|\\\\}}crtbegin.o" // CHECK-FSL-PPC64: "-L[[SYSROOT]]/usr/lib64/powerpc64-fsl-linux/4.6.2/../.." // -// Check that crtfastmath.o is linked with -ffast-math. +// Check that crtfastmath.o is linked with -ffast-math and with -Ofast. // RUN: %clang --target=x86_64-unknown-linux -### %s \ // RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-NOCRTFASTMATH %s @@ -691,9 +691,30 @@ // RUN: %clang --target=x86_64-unknown-linux -### %s -funsafe-math-optimizations\ // RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-CRTFASTMATH %s +// RUN: %clang --target=x86_64-unknown-linux -### %s -Ofast\ +// RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-CRTFASTMATH %s +// RUN: %clang --target=x86_64-unknown-linux -### %s -Ofast -O3\ +// RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-NOCRTFASTMATH %s +// RUN: %clang --target=x86_64-unknown-linux -### %s -O3 -Ofast\ +// RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-CRTFASTMATH %s // RUN: %clang --target=x86_64-unknown-linux -### %s -ffast-math -fno-fast-math \ // RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-NOCRTFASTMATH %s +// RUN: %clang --target=x86_64-unknown-linux -### %s -Ofast -fno-fast-math \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-CRTFASTMATH %s +// RUN: %clang --target=x86_64-unknown-linux -### %s -Ofast -fno-unsafe-math-optimizations \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-CRTFASTMATH %s +// RUN: %clang --target=x86_64-unknown-linux -### %s -fno-fast-math -Ofast \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-CRTFASTMATH %s +// RUN: %clang --target=x86_64-unknown-linux -### %s -fno-unsafe-math-optimizations -Ofast \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-CRTFASTMATH %s // We don't have crtfastmath.o in the i386 tree, use it to check that file // detection works. // RUN: %clang --target=i386-unknown-linux -### %s -ffast-math \ |
