diff options
author | Bill Wendling <isanbard@gmail.com> | 2010-09-07 20:14:32 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2010-09-07 20:14:32 +0000 |
commit | 75e5c50b37dbf24b251cd07940225b41e510ab58 (patch) | |
tree | 39e4406f3e46593f57526ee62c3abce662c373b6 | |
parent | 0b8abab7e0a879c5208fd2930df1e50054563635 (diff) | |
download | llvm-75e5c50b37dbf24b251cd07940225b41e510ab58.zip llvm-75e5c50b37dbf24b251cd07940225b41e510ab58.tar.gz llvm-75e5c50b37dbf24b251cd07940225b41e510ab58.tar.bz2 |
Approved by Chris:
$ svn merge -c 113257 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r113257 into '.':
A test/Transforms/InstCombine/sqrt.ll
D test/Transforms/InstCombine/2010-07-19-sqrt.ll
Renaming test.
$ svn merge -c 113260 https://llvm.org/svn/llvm-project/llvm/trunk
--- Merging r113260 into '.':
U test/Transforms/InstCombine/sqrt.ll
U lib/Transforms/InstCombine/InstCombineCasts.cpp
Log:
Fix a serious performance regression introduced by r108687 on linux:
turning (fptrunc (sqrt (fpext x))) -> (sqrtf x) is great, but we have
to delete the original sqrt as well. Not doing so causes us to do
two sqrt's when building with -fmath-errno (the default on linux).
llvm-svn: 113265
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 7 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/2010-07-19-sqrt.ll | 16 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/sqrt.ll | 32 |
3 files changed, 38 insertions, 17 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 6c2477d..79a9b09 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1139,7 +1139,7 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &CI) { Arg->getOperand(0)->getType()->isFloatTy()) { Function *Callee = Call->getCalledFunction(); Module *M = CI.getParent()->getParent()->getParent(); - Constant* SqrtfFunc = M->getOrInsertFunction("sqrtf", + Constant *SqrtfFunc = M->getOrInsertFunction("sqrtf", Callee->getAttributes(), Builder->getFloatTy(), Builder->getFloatTy(), @@ -1147,6 +1147,11 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &CI) { CallInst *ret = CallInst::Create(SqrtfFunc, Arg->getOperand(0), "sqrtfcall"); ret->setAttributes(Callee->getAttributes()); + + + // Remove the old Call. With -fmath-errno, it won't get marked readnone. + Call->replaceAllUsesWith(UndefValue::get(Call->getType())); + EraseInstFromFunction(*Call); return ret; } } diff --git a/llvm/test/Transforms/InstCombine/2010-07-19-sqrt.ll b/llvm/test/Transforms/InstCombine/2010-07-19-sqrt.ll deleted file mode 100644 index 6505382..0000000 --- a/llvm/test/Transforms/InstCombine/2010-07-19-sqrt.ll +++ /dev/null @@ -1,16 +0,0 @@ -; RUN: opt -S -instcombine %s | FileCheck %s - -define float @foo(float %x) nounwind readnone ssp { -entry: -; CHECK-NOT: fpext -; CHECK-NOT: sqrt( -; CHECK: sqrtf( -; CHECK-NOT: fptrunc - %conv = fpext float %x to double ; <double> [#uses=1] - %call = tail call double @sqrt(double %conv) nounwind ; <double> [#uses=1] - %conv1 = fptrunc double %call to float ; <float> [#uses=1] -; CHECK: ret float - ret float %conv1 -} - -declare double @sqrt(double) readnone diff --git a/llvm/test/Transforms/InstCombine/sqrt.ll b/llvm/test/Transforms/InstCombine/sqrt.ll new file mode 100644 index 0000000..69e511b --- /dev/null +++ b/llvm/test/Transforms/InstCombine/sqrt.ll @@ -0,0 +1,32 @@ +; RUN: opt -S -instcombine %s | FileCheck %s + +define float @test1(float %x) nounwind readnone ssp { +entry: +; CHECK: @test1 +; CHECK-NOT: fpext +; CHECK-NOT: sqrt( +; CHECK: sqrtf( +; CHECK-NOT: fptrunc + %conv = fpext float %x to double ; <double> [#uses=1] + %call = tail call double @sqrt(double %conv) readnone nounwind ; <double> [#uses=1] + %conv1 = fptrunc double %call to float ; <float> [#uses=1] +; CHECK: ret float + ret float %conv1 +} + +declare double @sqrt(double) + +; PR8096 +define float @test2(float %x) nounwind readnone ssp { +entry: +; CHECK: @test2 +; CHECK-NOT: fpext +; CHECK-NOT: sqrt( +; CHECK: sqrtf( +; CHECK-NOT: fptrunc + %conv = fpext float %x to double ; <double> [#uses=1] + %call = tail call double @sqrt(double %conv) nounwind ; <double> [#uses=1] + %conv1 = fptrunc double %call to float ; <float> [#uses=1] +; CHECK: ret float + ret float %conv1 +} |