summaryrefslogtreecommitdiff
path: root/unittests/VMCore/InstructionsTest.cpp
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2012-04-16 16:28:59 +0000
committerDuncan Sands <baldrick@free.fr>2012-04-16 16:28:59 +0000
commit8883c43ddc13e5f92ba8dfe00f2116a153a570d5 (patch)
tree40b5bad6be11275bb56cb7f227d1e4ee6544718d /unittests/VMCore/InstructionsTest.cpp
parent9e67db4af13abb967cae5858502207a43d26bf84 (diff)
downloadllvm-8883c43ddc13e5f92ba8dfe00f2116a153a570d5.tar.gz
llvm-8883c43ddc13e5f92ba8dfe00f2116a153a570d5.tar.bz2
llvm-8883c43ddc13e5f92ba8dfe00f2116a153a570d5.tar.xz
Make it possible to indicate relaxed floating point requirements at the IR level
through the use of 'fpmath' metadata. Currently this only provides a 'fpaccuracy' value, which may be a number in ULPs or the keyword 'fast', however the intent is that this will be extended with additional information about NaN's, infinities etc later. No optimizations have been hooked up to this so far. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154822 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/VMCore/InstructionsTest.cpp')
-rw-r--r--unittests/VMCore/InstructionsTest.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/unittests/VMCore/InstructionsTest.cpp b/unittests/VMCore/InstructionsTest.cpp
index 218a9a08c4..9c0cb4409f 100644
--- a/unittests/VMCore/InstructionsTest.cpp
+++ b/unittests/VMCore/InstructionsTest.cpp
@@ -12,8 +12,11 @@
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/LLVMContext.h"
+#include "llvm/Operator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Analysis/ValueTracking.h"
+#include "llvm/Support/MDBuilder.h"
+#include "llvm/Support/IRBuilder.h"
#include "llvm/Target/TargetData.h"
#include "gtest/gtest.h"
@@ -226,5 +229,27 @@ TEST(InstructionsTest, VectorGep) {
delete PtrVecB;
}
+TEST(InstructionsTest, FPMathOperator) {
+ LLVMContext &Context = getGlobalContext();
+ IRBuilder<> Builder(Context);
+ MDBuilder MDHelper(Context);
+ Instruction *I = Builder.CreatePHI(Builder.getDoubleTy(), 0);
+ MDNode *MD1 = MDHelper.createFPMath(1.0);
+ MDNode *MDF = MDHelper.createFastFPMath();
+ Value *V1 = Builder.CreateFAdd(I, I, "", MD1);
+ Value *VF = Builder.CreateFAdd(I, I, "", MDF);
+ EXPECT_TRUE(isa<FPMathOperator>(V1));
+ EXPECT_TRUE(isa<FPMathOperator>(VF));
+ FPMathOperator *O1 = cast<FPMathOperator>(V1);
+ FPMathOperator *OF = cast<FPMathOperator>(VF);
+ EXPECT_FALSE(O1->isFastFPAccuracy());
+ EXPECT_TRUE(OF->isFastFPAccuracy());
+ EXPECT_EQ(O1->getFPAccuracy(), 1.0);
+ EXPECT_GT(OF->getFPAccuracy(), 999.0);
+ delete V1;
+ delete VF;
+ delete I;
+}
+
} // end anonymous namespace
} // end namespace llvm