From 4b896dd613b1d85ee1b261ee470cb72fab24c282 Mon Sep 17 00:00:00 2001 From: Michael Ilseman Date: Thu, 29 Nov 2012 21:25:12 +0000 Subject: [PATCH] copyFastMathFlags utility and test case git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168943 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Instruction.h | 3 +++ lib/VMCore/Instruction.cpp | 6 ++++++ unittests/VMCore/IRBuilderTest.cpp | 9 +++++++++ 3 files changed, 18 insertions(+) diff --git a/include/llvm/Instruction.h b/include/llvm/Instruction.h index 2c1d41c705b..0f717ad9ddd 100644 --- a/include/llvm/Instruction.h +++ b/include/llvm/Instruction.h @@ -227,6 +227,9 @@ public: /// these flats. FastMathFlags getFastMathFlags() const; + /// Copy I's fast-math flags + void copyFastMathFlags(const Instruction *I); + private: /// hasMetadataHashEntry - Return true if we have an entry in the on-the-side /// metadata hash. diff --git a/lib/VMCore/Instruction.cpp b/lib/VMCore/Instruction.cpp index d93c1d7a22c..7b73e770fb3 100644 --- a/lib/VMCore/Instruction.cpp +++ b/lib/VMCore/Instruction.cpp @@ -177,6 +177,12 @@ FastMathFlags Instruction::getFastMathFlags() const { return cast(this)->getFastMathFlags(); } +/// Copy I's fast-math flags +void Instruction::copyFastMathFlags(const Instruction *I) { + setFastMathFlags(I->getFastMathFlags()); +} + + const char *Instruction::getOpcodeName(unsigned OpCode) { switch (OpCode) { // Terminators diff --git a/unittests/VMCore/IRBuilderTest.cpp b/unittests/VMCore/IRBuilderTest.cpp index 8a22b104ba6..665cfb3f138 100644 --- a/unittests/VMCore/IRBuilderTest.cpp +++ b/unittests/VMCore/IRBuilderTest.cpp @@ -164,6 +164,15 @@ TEST_F(IRBuilderTest, FastMathFlags) { FDiv = cast(F); EXPECT_TRUE(FDiv->hasAllowReciprocal()); + Builder.clearFastMathFlags(); + + F = Builder.CreateFDiv(F, F); + ASSERT_TRUE(isa(F)); + FDiv = cast(F); + EXPECT_FALSE(FDiv->getFastMathFlags().any()); + FDiv->copyFastMathFlags(FAdd); + EXPECT_TRUE(FDiv->hasNoNaNs()); + } }