From 8030b810ded6a9573c0e105f05da83956e9842b2 Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Mon, 16 Apr 2012 17:24:31 +0000 Subject: [PATCH] Generate fpmath metadata when -ffast-math. Note that no optimizations are hooked up to this yet. llvm-svn: 154835 --- clang/lib/CodeGen/CodeGenFunction.cpp | 7 ++++++- clang/test/CodeGen/2012-04-16-FastMath.c | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGen/2012-04-16-FastMath.c diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 9cbba0665471..f4b483b51584 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -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/clang/test/CodeGen/2012-04-16-FastMath.c b/clang/test/CodeGen/2012-04-16-FastMath.c new file mode 100644 index 000000000000..d7c3d9a2d63d --- /dev/null +++ b/clang/test/CodeGen/2012-04-16-FastMath.c @@ -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"}