From cdeb7d57a4867c28e3e6a8c391cba6f13c781fa6 Mon Sep 17 00:00:00 2001 From: Michael Ilseman Date: Tue, 4 Dec 2012 00:36:06 +0000 Subject: Have clang use LLVM IR's fast-math flags when in FastMath or FiniteMathOnly modes. Test cases included. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169191 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenFunction.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/CodeGen/CodeGenFunction.cpp') diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 3d7a978258..c441403fb3 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -22,6 +22,7 @@ #include "clang/AST/DeclCXX.h" #include "clang/AST/StmtCXX.h" #include "clang/Frontend/CodeGenOptions.h" +#include "llvm/Operator.h" #include "llvm/Intrinsics.h" #include "llvm/MDBuilder.h" #include "llvm/DataLayout.h" @@ -46,6 +47,15 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext) TerminateHandler(0), TrapBB(0) { if (!suppressNewContext) CGM.getCXXABI().getMangleContext().startNewFunction(); + + llvm::FastMathFlags FMF; + if (CGM.getLangOpts().FastMath) + FMF.UnsafeAlgebra = true; + if (CGM.getLangOpts().FiniteMathOnly) { + FMF.NoNaNs = true; + FMF.NoInfs = true; + } + Builder.SetFastMathFlags(FMF); } CodeGenFunction::~CodeGenFunction() { -- cgit v1.2.3-18-g5258