copyFastMathFlags utility and test case
authorMichael Ilseman <milseman@apple.com>
Thu, 29 Nov 2012 21:25:12 +0000 (21:25 +0000)
committerMichael Ilseman <milseman@apple.com>
Thu, 29 Nov 2012 21:25:12 +0000 (21:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168943 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Instruction.h
lib/VMCore/Instruction.cpp
unittests/VMCore/IRBuilderTest.cpp

index 2c1d41c705b92b1a100f2b030353e47800a93c16..0f717ad9ddde96031ce6a2fed32359b48f8b3a6f 100644 (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.
index d93c1d7a22c04b26ca75d53265a89b8597429558..7b73e770fb3dbfe6fce6009b2a32b62a95b0f835 100644 (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
index 8a22b104ba63bc625904302c118980659a0e7679..665cfb3f138dc2ed38f7713e8c0b4943488b7fe5 100644 (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());
+
 }
 
 }