[PATCH] D62521: [IRBuilder] Add CreateFNegFMF(...) to the IRBuilder

Cameron McInally via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 31 06:48:06 PDT 2019


cameron.mcinally updated this revision to Diff 202426.
cameron.mcinally added a comment.

Have IRBuilder::CreateFNegFMF(...) return a BinaryOperator as discussed...


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62521/new/

https://reviews.llvm.org/D62521

Files:
  llvm/include/llvm/IR/IRBuilder.h
  llvm/unittests/IR/IRBuilderTest.cpp


Index: llvm/unittests/IR/IRBuilderTest.cpp
===================================================================
--- llvm/unittests/IR/IRBuilderTest.cpp
+++ llvm/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) {
Index: llvm/include/llvm/IR/IRBuilder.h
===================================================================
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -1372,6 +1372,17 @@
     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);
+   return Insert(setFPAttrs(BinaryOperator::CreateFNeg(V), nullptr,
+                            FMFSource->getFastMathFlags()),
+                 Name);
+  }
+
   Value *CreateUnOp(Instruction::UnaryOps Opc,
                     Value *V, const Twine &Name = "",
                     MDNode *FPMathTag = nullptr) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62521.202426.patch
Type: text/x-patch
Size: 1843 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190531/ea61d4ec/attachment.bin>


More information about the llvm-commits mailing list