Commit 1b4f99d6 authored by Tom Stellard's avatar Tom Stellard
Browse files

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

------------------------------------------------------------------------

llvm-svn: 206066
parent 330ff7f9
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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

+1 −1
Original line number Diff line number Diff line
@@ -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;
+4 −0
Original line number Diff line number Diff line
@@ -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);
}
+13 −10
Original line number Diff line number Diff line
@@ -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,
  // 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.
+0 −7
Original line number Diff line number Diff line
@@ -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)) {
Loading