diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2015-12-14 21:59:03 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2015-12-14 21:59:03 +0000 |
| commit | fa54acedd1fd1183143c0a7f4b77554fd8cdb1ec (patch) | |
| tree | 6e7cbff67fd8ec8795d8a0cb7a4e3f1d00a92302 /llvm/unittests | |
| parent | 46642ffeebde1743980735e96303140f5f1a7b8b (diff) | |
| download | bcm5719-llvm-fa54acedd1fd1183143c0a7f4b77554fd8cdb1ec.tar.gz bcm5719-llvm-fa54acedd1fd1183143c0a7f4b77554fd8cdb1ec.zip | |
add fast-math-flags to 'call' instructions (PR21290)
This patch adds optional fast-math-flags (the same that apply to fmul/fadd/fsub/fdiv/frem/fcmp)
to call instructions in IR. Follow-up patches would use these flags in LibCallSimplifier, add
support to clang, and extend FMF to the DAG for calls.
Motivating example:
%y = fmul fast float %x, %x
%z = tail call float @sqrtf(float %y)
We'd like to be able to optimize sqrt(x*x) into fabs(x). We do this today using a function-wide
attribute for unsafe-math, but we really want to trigger on the instructions themselves:
%z = tail call fast float @sqrtf(float %y)
because in an LTO build it's possible that calls with fast semantics have been inlined into a
function with non-fast semantics.
The code changes and tests are based on the recent commits that added "notail":
http://reviews.llvm.org/rL252368
and added FMF to fcmp:
http://reviews.llvm.org/rL241901
Differential Revision: http://reviews.llvm.org/D14707
llvm-svn: 255555
Diffstat (limited to 'llvm/unittests')
| -rw-r--r-- | llvm/unittests/IR/IRBuilderTest.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/llvm/unittests/IR/IRBuilderTest.cpp b/llvm/unittests/IR/IRBuilderTest.cpp index 0c602ed2b78..e0da018d7bf 100644 --- a/llvm/unittests/IR/IRBuilderTest.cpp +++ b/llvm/unittests/IR/IRBuilderTest.cpp @@ -131,7 +131,7 @@ TEST_F(IRBuilderTest, GetIntTy) { TEST_F(IRBuilderTest, FastMathFlags) { IRBuilder<> Builder(BB); Value *F, *FC; - Instruction *FDiv, *FAdd, *FCmp; + Instruction *FDiv, *FAdd, *FCmp, *FCall; F = Builder.CreateLoad(GV); F = Builder.CreateFAdd(F, F); @@ -207,6 +207,26 @@ TEST_F(IRBuilderTest, FastMathFlags) { EXPECT_TRUE(FCmp->hasAllowReciprocal()); Builder.clearFastMathFlags(); + + // Test a call with FMF. + auto CalleeTy = FunctionType::get(Type::getFloatTy(Ctx), + /*isVarArg=*/false); + auto Callee = + Function::Create(CalleeTy, Function::ExternalLinkage, "", M.get()); + + FCall = Builder.CreateCall(Callee, None); + EXPECT_FALSE(FCall->hasNoNaNs()); + + FMF.clear(); + FMF.setNoNaNs(); + Builder.SetFastMathFlags(FMF); + + FCall = Builder.CreateCall(Callee, 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. F = Builder.CreateFDiv(F, F); |

