llvm.org GIT mirror llvm / be91353
[IR] Add UnaryOperator::CreateFNegFMF(...) Differential Revision: https://reviews.llvm.org/D62705 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362828 91177308-0d34-0410-b5e6-96231b3b80d8 Cameron McInally a month ago
2 changed file(s) with 33 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
153153 }
154154 #include "llvm/IR/Instruction.def"
155155
156 static UnaryOperator *CreateWithCopiedFlags(UnaryOps Opc,
157 Value *V,
158 Instruction *CopyO,
159 const Twine &Name = "") {
160 UnaryOperator *UO = Create(Opc, V, Name);
161 UO->copyIRFlags(CopyO);
162 return UO;
163 }
164
165 static UnaryOperator *CreateFNegFMF(Value *Op, Instruction *FMFSource,
166 const Twine &Name = "") {
167 return CreateWithCopiedFlags(Instruction::FNeg, Op, FMFSource, Name);
168 }
169
156170 UnaryOps getOpcode() const {
157171 return static_cast(Instruction::getOpcode());
158172 }
268282 static BinaryOperator *CreateFNegFMF(Value *Op, Instruction *FMFSource,
269283 const Twine &Name = "") {
270284 Value *Zero = ConstantFP::getNegativeZero(Op->getType());
271 return CreateWithCopiedFlags(Instruction::FSub, Zero, Op, FMFSource);
285 return CreateWithCopiedFlags(Instruction::FSub, Zero, Op, FMFSource, Name);
272286 }
273287
274288 static BinaryOperator *CreateNSW(BinaryOps Opc, Value *V1, Value *V2,
10801080 I->deleteValue();
10811081 }
10821082
1083 TEST(InstructionsTest, FNegInstruction) {
1084 LLVMContext Context;
1085 Type *FltTy = Type::getFloatTy(Context);
1086 Constant *One = ConstantFP::get(FltTy, 1.0);
1087 BinaryOperator *FAdd = BinaryOperator::CreateFAdd(One, One);
1088 FAdd->setHasNoNaNs(true);
1089 UnaryOperator *FNeg = UnaryOperator::CreateFNegFMF(One, FAdd);
1090 EXPECT_TRUE(FNeg->hasNoNaNs());
1091 EXPECT_FALSE(FNeg->hasNoInfs());
1092 EXPECT_FALSE(FNeg->hasNoSignedZeros());
1093 EXPECT_FALSE(FNeg->hasAllowReciprocal());
1094 EXPECT_FALSE(FNeg->hasAllowContract());
1095 EXPECT_FALSE(FNeg->hasAllowReassoc());
1096 EXPECT_FALSE(FNeg->hasApproxFunc());
1097 FAdd->deleteValue();
1098 FNeg->deleteValue();
1099 }
1100
10831101 } // end anonymous namespace
10841102 } // end namespace llvm