[PATCH] D62521: [IRBuilder] Add CreateFNegFMF(...) to the IRBuilder
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 10 08:04:29 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL362947: [IRBuilder] Add CreateFNegFMF(...) to the IRBuilder (authored by mcinally, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D62521?vs=202426&id=203827#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D62521/new/
https://reviews.llvm.org/D62521
Files:
llvm/trunk/include/llvm/IR/IRBuilder.h
llvm/trunk/unittests/IR/IRBuilderTest.cpp
Index: llvm/trunk/include/llvm/IR/IRBuilder.h
===================================================================
--- llvm/trunk/include/llvm/IR/IRBuilder.h
+++ llvm/trunk/include/llvm/IR/IRBuilder.h
@@ -1372,6 +1372,19 @@
return Insert(BinaryOperator::CreateNot(V), Name);
}
+ /// Copy fast-math-flags from an instruction rather than using the builder's
+ /// default FMF.
+ Value *CreateFNegFMF(Value *V, Instruction *FMFSource,
+ const Twine &Name = "") {
+ if (auto *VC = dyn_cast<Constant>(V))
+ return Insert(Folder.CreateFNeg(VC), Name);
+ // TODO: This should return UnaryOperator::CreateFNeg(...) once we are
+ // confident that they are optimized sufficiently.
+ return Insert(setFPAttrs(BinaryOperator::CreateFNeg(V), nullptr,
+ FMFSource->getFastMathFlags()),
+ Name);
+ }
+
Value *CreateUnOp(Instruction::UnaryOps Opc,
Value *V, const Twine &Name = "",
MDNode *FPMathTag = nullptr) {
Index: llvm/trunk/unittests/IR/IRBuilderTest.cpp
===================================================================
--- llvm/trunk/unittests/IR/IRBuilderTest.cpp
+++ llvm/trunk/unittests/IR/IRBuilderTest.cpp
@@ -206,12 +206,22 @@
IRBuilder<NoFolder> Builder(BB);
Value *V = Builder.CreateLoad(GV->getValueType(), GV);
- // Test CreateUnOp
+ // Test CreateUnOp(X)
Value *U = Builder.CreateUnOp(Instruction::FNeg, V);
ASSERT_TRUE(isa<Instruction>(U));
ASSERT_TRUE(isa<FPMathOperator>(U));
ASSERT_TRUE(isa<UnaryOperator>(U));
ASSERT_FALSE(isa<BinaryOperator>(U));
+
+ // Test CreateFNegFMF(X)
+ Instruction *I = cast<Instruction>(V);
+ I->setHasNoSignedZeros(true);
+ I->setHasNoNaNs(true);
+ Value *VFMF = Builder.CreateFNegFMF(V, I);
+ Instruction *IFMF = cast<Instruction>(VFMF);
+ EXPECT_TRUE(IFMF->hasNoSignedZeros());
+ EXPECT_TRUE(IFMF->hasNoNaNs());
+ EXPECT_FALSE(IFMF->hasAllowReassoc());
}
TEST_F(IRBuilderTest, FastMathFlags) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62521.203827.patch
Type: text/x-patch
Size: 2009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190610/3058a3e1/attachment.bin>
More information about the llvm-commits
mailing list