copyFastMathFlags utility and test case

llvm-svn: 168943
This commit is contained in:
Michael Ilseman 2012-11-29 21:25:12 +00:00
parent 03bb500052
commit 05d3bf77a1
3 changed files with 18 additions and 0 deletions

View File

@ -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.

View File

@ -177,6 +177,12 @@ FastMathFlags Instruction::getFastMathFlags() const {
return cast<FPMathOperator>(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

View File

@ -164,6 +164,15 @@ TEST_F(IRBuilderTest, FastMathFlags) {
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->getFastMathFlags().any());
FDiv->copyFastMathFlags(FAdd);
EXPECT_TRUE(FDiv->hasNoNaNs());
}
}