diff options
| author | Michael Ilseman <milseman@apple.com> | 2012-11-28 21:17:34 +0000 |
|---|---|---|
| committer | Michael Ilseman <milseman@apple.com> | 2012-11-28 21:17:34 +0000 |
| commit | 018530268dd5a29902c6a0f72fd25c61431eb2bd (patch) | |
| tree | ef3be1dcadca24c627c68a6aca975dcd78c47218 /llvm/unittests/VMCore/IRBuilderTest.cpp | |
| parent | be6871db58cbe9ba62b6dc01ce5b00e5ddcba465 (diff) | |
| download | bcm5719-llvm-018530268dd5a29902c6a0f72fd25c61431eb2bd.tar.gz bcm5719-llvm-018530268dd5a29902c6a0f72fd25c61431eb2bd.zip | |
Fast-math: IRBuilder test for creating instructions with fast-math flags
llvm-svn: 168814
Diffstat (limited to 'llvm/unittests/VMCore/IRBuilderTest.cpp')
| -rw-r--r-- | llvm/unittests/VMCore/IRBuilderTest.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/llvm/unittests/VMCore/IRBuilderTest.cpp b/llvm/unittests/VMCore/IRBuilderTest.cpp index 9f26936df47..0f3e48d76c3 100644 --- a/llvm/unittests/VMCore/IRBuilderTest.cpp +++ b/llvm/unittests/VMCore/IRBuilderTest.cpp @@ -31,6 +31,8 @@ protected: /*isVarArg=*/false); F = Function::Create(FTy, Function::ExternalLinkage, "", M.get()); BB = BasicBlock::Create(getGlobalContext(), "", F); + GV = new GlobalVariable(Type::getFloatTy(getGlobalContext()), true, + GlobalValue::ExternalLinkage); } virtual void TearDown() { @@ -41,6 +43,7 @@ protected: OwningPtr<Module> M; Function *F; BasicBlock *BB; + GlobalVariable *GV; }; TEST_F(IRBuilderTest, Lifetime) { @@ -108,4 +111,59 @@ TEST_F(IRBuilderTest, GetIntTy) { EXPECT_EQ(IntPtrTy, IntegerType::get(getGlobalContext(), IntPtrBitSize)); } +TEST_F(IRBuilderTest, FastMathFlags) { + IRBuilder<> Builder(BB); + Value *F; + Instruction *FDiv, *FAdd; + + F = Builder.CreateLoad(GV); + F = Builder.CreateFAdd(F, F); + + EXPECT_FALSE(Builder.GetFastMathFlags().any()); + ASSERT_TRUE(isa<Instruction>(F)); + FAdd = cast<Instruction>(F); + EXPECT_FALSE(FAdd->hasNoNaNs()); + + FastMathFlags FMF; + Builder.SetFastMathFlags(FMF); + + F = Builder.CreateFAdd(F, F); + EXPECT_FALSE(Builder.GetFastMathFlags().any()); + + FMF.UnsafeAlgebra = true; + Builder.SetFastMathFlags(FMF); + + F = Builder.CreateFAdd(F, F); + EXPECT_TRUE(Builder.GetFastMathFlags().any()); + ASSERT_TRUE(isa<Instruction>(F)); + FAdd = cast<Instruction>(F); + EXPECT_TRUE(FAdd->hasNoNaNs()); + + F = Builder.CreateFDiv(F, F); + EXPECT_TRUE(Builder.GetFastMathFlags().any()); + EXPECT_TRUE(Builder.GetFastMathFlags().UnsafeAlgebra); + ASSERT_TRUE(isa<Instruction>(F)); + FDiv = cast<Instruction>(F); + EXPECT_TRUE(FDiv->hasAllowReciprocal()); + + Builder.ClearFastMathFlags(); + + F = Builder.CreateFDiv(F, F); + ASSERT_TRUE(isa<Instruction>(F)); + FDiv = cast<Instruction>(F); + EXPECT_FALSE(FDiv->hasAllowReciprocal()); + + FMF.clear(); + FMF.AllowReciprocal = true; + Builder.SetFastMathFlags(FMF); + + F = Builder.CreateFDiv(F, F); + EXPECT_TRUE(Builder.GetFastMathFlags().any()); + EXPECT_TRUE(Builder.GetFastMathFlags().AllowReciprocal); + ASSERT_TRUE(isa<Instruction>(F)); + FDiv = cast<Instruction>(F); + EXPECT_TRUE(FDiv->hasAllowReciprocal()); + +} + } |

