From b3c5043dccee58dfaed33d07a10db9b2158b59f8 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Wed, 28 Mar 2012 10:26:39 -0700 Subject: [PATCH] Don't enable llvm's UnsafeFPMath option when --opt=fast-math is supplied. This was causing functions like round() to fail on SSE2, since it has code that does: x += 0x1.0p23f; x -= 0x1.0p23f; which was in turn being undesirably optimized away. Fixes issue #211. --- ispc.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ispc.cpp b/ispc.cpp index 050f8a11..25bec209 100644 --- a/ispc.cpp +++ b/ispc.cpp @@ -355,8 +355,15 @@ Target::GetTargetMachine() const { #if defined(LLVM_3_1svn) std::string featuresString = attributes; llvm::TargetOptions options; +#if 0 + // This was breaking e.g. round() on SSE2, where the code we want to + // run wants to do: + // x += 0x1.0p23f; + // x -= 0x1.0p23f; + // But then LLVM was optimizing this away... if (g->opt.fastMath == true) options.UnsafeFPMath = 1; +#endif llvm::TargetMachine *targetMachine = target->createTargetMachine(triple, cpu, featuresString, options, relocModel);