Index: test/CodeGen/fast-math.c
===================================================================
--- test/CodeGen/fast-math.c	(revision 0)
+++ test/CodeGen/fast-math.c	(revision 0)
@@ -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
+}
Index: test/CodeGen/finite-math.c
===================================================================
--- test/CodeGen/finite-math.c	(revision 0)
+++ test/CodeGen/finite-math.c	(revision 0)
@@ -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
+}
Index: lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- lib/CodeGen/CodeGenFunction.cpp	(revision 168943)
+++ lib/CodeGen/CodeGenFunction.cpp	(working copy)
@@ -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() {
