Page MenuHomePhabricator

D62521.diff
No OneTemporary

File Metadata

Created
Fri, Aug 23, 3:53 AM

D62521.diff

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) {

Event Timeline