]> granicus.if.org Git - clang/commitdiff
Generate fpmath metadata when -ffast-math. Note that no optimizations are hooked
authorDuncan Sands <baldrick@free.fr>
Mon, 16 Apr 2012 17:24:31 +0000 (17:24 +0000)
committerDuncan Sands <baldrick@free.fr>
Mon, 16 Apr 2012 17:24:31 +0000 (17:24 +0000)
up to this yet.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154835 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenFunction.cpp
test/CodeGen/2012-04-16-FastMath.c [new file with mode: 0644]

index 9cbba06654714273c6cdbfc11926f9bc0ab15746..f4b483b51584f97ca4d38b4fc7f82c78c494a1ac 100644 (file)
@@ -22,8 +22,9 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/Frontend/CodeGenOptions.h"
-#include "llvm/Target/TargetData.h"
 #include "llvm/Intrinsics.h"
+#include "llvm/Support/MDBuilder.h"
+#include "llvm/Target/TargetData.h"
 using namespace clang;
 using namespace CodeGen;
 
@@ -41,6 +42,10 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm)
     TerminateHandler(0), TrapBB(0) {
 
   CatchUndefined = getContext().getLangOpts().CatchUndefined;
+  if (getContext().getLangOpts().FastMath) {
+    llvm::MDBuilder MDHelper(Builder.getContext());
+    Builder.SetDefaultFPMathTag(MDHelper.createFastFPMath());
+  }
   CGM.getCXXABI().getMangleContext().startNewFunction();
 }
 
diff --git a/test/CodeGen/2012-04-16-FastMath.c b/test/CodeGen/2012-04-16-FastMath.c
new file mode 100644 (file)
index 0000000..d7c3d9a
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -ffast-math -emit-llvm -o - | FileCheck %s
+
+double add(double x, double y) {
+// CHECK: @add
+  return x + y;
+// CHECK: fadd double %{{.}}, %{{.}}, !fpmath !0
+}
+// CHECK: !0 = metadata !{metadata !"fast"}