[PATCH] D62705: [IR] Add UnaryOperator::CreateFNegFMF(...)

Cameron McInally via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 30 14:21:21 PDT 2019


cameron.mcinally created this revision.
cameron.mcinally added reviewers: spatel, arsenm, craig.topper, andrew.w.kaylor, kpn.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

I'm not sure if InstructionsTest.cpp is the correct place for this test, but it seems like the best fit.


Repository:
  rL LLVM

https://reviews.llvm.org/D62705

Files:
  llvm/include/llvm/IR/InstrTypes.h
  llvm/unittests/IR/InstructionsTest.cpp


Index: llvm/unittests/IR/InstructionsTest.cpp
===================================================================
--- llvm/unittests/IR/InstructionsTest.cpp
+++ llvm/unittests/IR/InstructionsTest.cpp
@@ -1002,5 +1002,23 @@
   I->deleteValue();
 }
 
+TEST(InstructionsTest, FNegInstruction) {
+  LLVMContext Context;
+  Type *FltTy = Type::getFloatTy(Context);
+  Constant *One = ConstantFP::get(FltTy, 1.0);
+  BinaryOperator *FAdd = BinaryOperator::CreateFAdd(One, One);
+  FAdd->setHasNoNaNs(true);
+  UnaryOperator *FNeg = UnaryOperator::CreateFNegFMF(One, FAdd);
+  EXPECT_TRUE(FNeg->hasNoNaNs());
+  EXPECT_FALSE(FNeg->hasNoInfs());
+  EXPECT_FALSE(FNeg->hasNoSignedZeros());
+  EXPECT_FALSE(FNeg->hasAllowReciprocal());
+  EXPECT_FALSE(FNeg->hasAllowContract());
+  EXPECT_FALSE(FNeg->hasAllowReassoc());
+  EXPECT_FALSE(FNeg->hasApproxFunc());
+  FAdd->deleteValue();
+  FNeg->deleteValue();
+}
+
 } // end anonymous namespace
 } // end namespace llvm
Index: llvm/include/llvm/IR/InstrTypes.h
===================================================================
--- llvm/include/llvm/IR/InstrTypes.h
+++ llvm/include/llvm/IR/InstrTypes.h
@@ -154,6 +154,20 @@
   }
 #include "llvm/IR/Instruction.def"
 
+  static UnaryOperator *CreateWithCopiedFlags(UnaryOps Opc,
+                                              Value *V,
+                                              Instruction *CopyO,
+                                              const Twine &Name = "") {
+    UnaryOperator *UO = Create(Opc, V, Name);
+    UO->copyIRFlags(CopyO);
+    return UO;
+  }
+
+  static UnaryOperator *CreateFNegFMF(Value *Op, Instruction *FMFSource,
+                                      const Twine &Name = "") {
+    return CreateWithCopiedFlags(Instruction::FNeg, Op, FMFSource);
+  }
+
   UnaryOps getOpcode() const {
     return static_cast<UnaryOps>(Instruction::getOpcode());
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62705.202297.patch
Type: text/x-patch
Size: 1878 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190530/45aa6a64/attachment.bin>


More information about the llvm-commits mailing list