add FMF for CreateCall variant
authorSanjay Patel <spatel@rotateright.com>
Thu, 31 Dec 2015 15:39:34 +0000 (15:39 +0000)
committerSanjay Patel <spatel@rotateright.com>
Thu, 31 Dec 2015 15:39:34 +0000 (15:39 +0000)
The version with OpBundles was missed in:
http://reviews.llvm.org/rL255555

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256674 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 7fe04f2..e133e6d 100644 (file)
@@ -1529,8 +1529,11 @@ public:
 
   CallInst *CreateCall(Value *Callee, ArrayRef<Value *> Args = None,
                        ArrayRef<OperandBundleDef> OpBundles = None,
-                       const Twine &Name = "") {
-    return Insert(CallInst::Create(Callee, Args, OpBundles), Name);
+                       const Twine &Name = "", MDNode *FPMathTag = nullptr) {
+    CallInst *CI = CallInst::Create(Callee, Args, OpBundles);
+    if (isa<FPMathOperator>(CI))
+      CI = cast<CallInst>(AddFPMathAttributes(CI, FPMathTag, FMF));
+    return Insert(CI, Name);
   }
 
   CallInst *CreateCall(Value *Callee, ArrayRef<Value *> Args,
index e0da018..82565cc 100644 (file)
@@ -217,6 +217,11 @@ TEST_F(IRBuilderTest, FastMathFlags) {
   FCall = Builder.CreateCall(Callee, None);
   EXPECT_FALSE(FCall->hasNoNaNs());
 
+  Value *V = 
+      Function::Create(CalleeTy, Function::ExternalLinkage, "", M.get());
+  FCall = Builder.CreateCall(V, None);
+  EXPECT_FALSE(FCall->hasNoNaNs());
+
   FMF.clear();
   FMF.setNoNaNs();
   Builder.SetFastMathFlags(FMF);
@@ -226,6 +231,11 @@ TEST_F(IRBuilderTest, FastMathFlags) {
   EXPECT_TRUE(Builder.getFastMathFlags().NoNaNs);
   EXPECT_TRUE(FCall->hasNoNaNs());
 
+  FCall = Builder.CreateCall(V, None);
+  EXPECT_TRUE(Builder.getFastMathFlags().any());
+  EXPECT_TRUE(Builder.getFastMathFlags().NoNaNs);
+  EXPECT_TRUE(FCall->hasNoNaNs());
+
   Builder.clearFastMathFlags();
 
   // To test a copy, make sure that a '0' and a '1' change state.