diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h index 7fe04f2a091a..e133e6d80932 100644 --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -1529,8 +1529,11 @@ public: CallInst *CreateCall(Value *Callee, ArrayRef Args = None, ArrayRef 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(CI)) + CI = cast(AddFPMathAttributes(CI, FPMathTag, FMF)); + return Insert(CI, Name); } CallInst *CreateCall(Value *Callee, ArrayRef Args, diff --git a/llvm/unittests/IR/IRBuilderTest.cpp b/llvm/unittests/IR/IRBuilderTest.cpp index e0da018d7bfe..82565ccaebcf 100644 --- a/llvm/unittests/IR/IRBuilderTest.cpp +++ b/llvm/unittests/IR/IRBuilderTest.cpp @@ -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.