diff options
| author | Cameron McInally <cameron.mcinally@nyu.edu> | 2019-06-07 18:59:51 +0000 |
|---|---|---|
| committer | Cameron McInally <cameron.mcinally@nyu.edu> | 2019-06-07 18:59:51 +0000 |
| commit | ef57e50bd2b8151e06a459432838610c172d0512 (patch) | |
| tree | f2e646eabb868a3052ba39223a1089cfd442b8e7 | |
| parent | 9fa6538f3b6b6b67eac369e5359bd729a0cc96a9 (diff) | |
| download | bcm5719-llvm-ef57e50bd2b8151e06a459432838610c172d0512.tar.gz bcm5719-llvm-ef57e50bd2b8151e06a459432838610c172d0512.zip | |
[IR] Add UnaryOperator::CreateFNegFMF(...)
Differential Revision: https://reviews.llvm.org/D62705
llvm-svn: 362828
| -rw-r--r-- | llvm/include/llvm/IR/InstrTypes.h | 16 | ||||
| -rw-r--r-- | llvm/unittests/IR/InstructionsTest.cpp | 18 |
2 files changed, 33 insertions, 1 deletions
diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h index 237929f5e60..ca419b50da6 100644 --- a/llvm/include/llvm/IR/InstrTypes.h +++ b/llvm/include/llvm/IR/InstrTypes.h @@ -154,6 +154,20 @@ public: } #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 @@ public: 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, diff --git a/llvm/unittests/IR/InstructionsTest.cpp b/llvm/unittests/IR/InstructionsTest.cpp index 70d51e5fc6d..7edd3a98bfb 100644 --- a/llvm/unittests/IR/InstructionsTest.cpp +++ b/llvm/unittests/IR/InstructionsTest.cpp @@ -1081,5 +1081,23 @@ TEST(InstructionsTest, PhiIsNotFPMathOperator) { 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 |

