[cfe-commits] r169191 - in /cfe/trunk: lib/CodeGen/CodeGenFunction.cpp test/CodeGen/fast-math.c test/CodeGen/finite-math.c

Michael Ilseman milseman at apple.com
Mon Dec 3 16:36:06 PST 2012


Author: milseman
Date: Mon Dec  3 18:36:06 2012
New Revision: 169191

URL: http://llvm.org/viewvc/llvm-project?rev=169191&view=rev
Log:
Have clang use LLVM IR's fast-math flags when in FastMath or FiniteMathOnly modes. Test cases included.

Added:
    cfe/trunk/test/CodeGen/fast-math.c
    cfe/trunk/test/CodeGen/finite-math.c
Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=169191&r1=169190&r2=169191&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Mon Dec  3 18:36:06 2012
@@ -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 @@
     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() {

Added: cfe/trunk/test/CodeGen/fast-math.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/fast-math.c?rev=169191&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/fast-math.c (added)
+++ cfe/trunk/test/CodeGen/fast-math.c Mon Dec  3 18:36:06 2012
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -ffast-math -emit-llvm -o - %s | FileCheck %s
+typedef unsigned cond_t;
+
+volatile float f0, f1, f2;
+
+void foo(void) {
+  // CHECK: define void @foo()
+
+  // CHECK: fadd fast
+  f0 = f1 + f2;
+
+  // CHECK: ret
+}

Added: cfe/trunk/test/CodeGen/finite-math.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/finite-math.c?rev=169191&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/finite-math.c (added)
+++ cfe/trunk/test/CodeGen/finite-math.c Mon Dec  3 18:36:06 2012
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -ffinite-math-only -emit-llvm -o - %s | FileCheck %s
+typedef unsigned cond_t;
+
+volatile float f0, f1, f2;
+
+void foo(void) {
+  // CHECK: define void @foo()
+
+  // CHECK: fadd nnan ninf
+  f0 = f1 + f2;
+
+  // CHECK: ret
+}





More information about the cfe-commits mailing list