llvm.org GIT mirror llvm / 0f0b06d
[IRBuilder] Add CreateFNegFMF(...) to the IRBuilder Differential Revision: https://reviews.llvm.org/D62521 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362947 91177308-0d34-0410-b5e6-96231b3b80d8 Cameron McInally a month ago
2 changed file(s) with 24 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
13711371 return Insert(BinaryOperator::CreateNot(V), Name);
13721372 }
13731373
1374 /// Copy fast-math-flags from an instruction rather than using the builder's
1375 /// default FMF.
1376 Value *CreateFNegFMF(Value *V, Instruction *FMFSource,
1377 const Twine &Name = "") {
1378 if (auto *VC = dyn_cast(V))
1379 return Insert(Folder.CreateFNeg(VC), Name);
1380 // TODO: This should return UnaryOperator::CreateFNeg(...) once we are
1381 // confident that they are optimized sufficiently.
1382 return Insert(setFPAttrs(BinaryOperator::CreateFNeg(V), nullptr,
1383 FMFSource->getFastMathFlags()),
1384 Name);
1385 }
1386
13741387 Value *CreateUnOp(Instruction::UnaryOps Opc,
13751388 Value *V, const Twine &Name = "",
13761389 MDNode *FPMathTag = nullptr) {
205205 IRBuilder Builder(BB);
206206 Value *V = Builder.CreateLoad(GV->getValueType(), GV);
207207
208 // Test CreateUnOp
208 // Test CreateUnOp(X)
209209 Value *U = Builder.CreateUnOp(Instruction::FNeg, V);
210210 ASSERT_TRUE(isa(U));
211211 ASSERT_TRUE(isa(U));
212212 ASSERT_TRUE(isa(U));
213213 ASSERT_FALSE(isa(U));
214
215 // Test CreateFNegFMF(X)
216 Instruction *I = cast(V);
217 I->setHasNoSignedZeros(true);
218 I->setHasNoNaNs(true);
219 Value *VFMF = Builder.CreateFNegFMF(V, I);
220 Instruction *IFMF = cast(VFMF);
221 EXPECT_TRUE(IFMF->hasNoSignedZeros());
222 EXPECT_TRUE(IFMF->hasNoNaNs());
223 EXPECT_FALSE(IFMF->hasAllowReassoc());
214224 }
215225
216226 TEST_F(IRBuilderTest, FastMathFlags) {