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

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 7 11:57:36 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL362828: [IR] Add UnaryOperator::CreateFNegFMF(...) (authored by mcinally, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D62705?vs=202297&id=203589#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62705/new/

https://reviews.llvm.org/D62705

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


Index: llvm/trunk/include/llvm/IR/InstrTypes.h
===================================================================
--- llvm/trunk/include/llvm/IR/InstrTypes.h
+++ llvm/trunk/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, Name);
+  }
+
   UnaryOps getOpcode() const {
     return static_cast<UnaryOps>(Instruction::getOpcode());
   }
@@ -269,7 +283,7 @@
   static BinaryOperator *CreateFNegFMF(Value *Op, Instruction *FMFSource,
                                        const Twine &Name = "") {
     Value *Zero = ConstantFP::getNegativeZero(Op->getType());
-    return CreateWithCopiedFlags(Instruction::FSub, Zero, Op, FMFSource);
+    return CreateWithCopiedFlags(Instruction::FSub, Zero, Op, FMFSource, Name);
   }
 
   static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
Index: llvm/trunk/unittests/IR/InstructionsTest.cpp
===================================================================
--- llvm/trunk/unittests/IR/InstructionsTest.cpp
+++ llvm/trunk/unittests/IR/InstructionsTest.cpp
@@ -1081,5 +1081,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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62705.203589.patch
Type: text/x-patch
Size: 2380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190607/3a15a597/attachment.bin>


More information about the llvm-commits mailing list