llvm.org GIT mirror llvm / 4c0eaab
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). git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_28@113265 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 9 years ago
3 changed file(s) with 38 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
11381138 Arg->getOperand(0)->getType()->isFloatTy()) {
11391139 Function *Callee = Call->getCalledFunction();
11401140 Module *M = CI.getParent()->getParent()->getParent();
1141 Constant* SqrtfFunc = M->getOrInsertFunction("sqrtf",
1141 Constant *SqrtfFunc = M->getOrInsertFunction("sqrtf",
11421142 Callee->getAttributes(),
11431143 Builder->getFloatTy(),
11441144 Builder->getFloatTy(),
11461146 CallInst *ret = CallInst::Create(SqrtfFunc, Arg->getOperand(0),
11471147 "sqrtfcall");
11481148 ret->setAttributes(Callee->getAttributes());
1149
1150
1151 // Remove the old Call. With -fmath-errno, it won't get marked readnone.
1152 Call->replaceAllUsesWith(UndefValue::get(Call->getType()));
1153 EraseInstFromFunction(*Call);
11491154 return ret;
11501155 }
11511156 }
+0
-16
test/Transforms/InstCombine/2010-07-19-sqrt.ll less more
None ; RUN: opt -S -instcombine %s | FileCheck %s
1
2 define float @foo(float %x) nounwind readnone ssp {
3 entry:
4 ; CHECK-NOT: fpext
5 ; CHECK-NOT: sqrt(
6 ; CHECK: sqrtf(
7 ; CHECK-NOT: fptrunc
8 %conv = fpext float %x to double ; [#uses=1]
9 %call = tail call double @sqrt(double %conv) nounwind ; [#uses=1]
10 %conv1 = fptrunc double %call to float ; [#uses=1]
11 ; CHECK: ret float
12 ret float %conv1
13 }
14
15 declare double @sqrt(double) readnone
0 ; RUN: opt -S -instcombine %s | FileCheck %s
1
2 define float @test1(float %x) nounwind readnone ssp {
3 entry:
4 ; CHECK: @test1
5 ; CHECK-NOT: fpext
6 ; CHECK-NOT: sqrt(
7 ; CHECK: sqrtf(
8 ; CHECK-NOT: fptrunc
9 %conv = fpext float %x to double ; [#uses=1]
10 %call = tail call double @sqrt(double %conv) readnone nounwind ; [#uses=1]
11 %conv1 = fptrunc double %call to float ; [#uses=1]
12 ; CHECK: ret float
13 ret float %conv1
14 }
15
16 declare double @sqrt(double)
17
18 ; PR8096
19 define float @test2(float %x) nounwind readnone ssp {
20 entry:
21 ; CHECK: @test2
22 ; CHECK-NOT: fpext
23 ; CHECK-NOT: sqrt(
24 ; CHECK: sqrtf(
25 ; CHECK-NOT: fptrunc
26 %conv = fpext float %x to double ; [#uses=1]
27 %call = tail call double @sqrt(double %conv) nounwind ; [#uses=1]
28 %conv1 = fptrunc double %call to float ; [#uses=1]
29 ; CHECK: ret float
30 ret float %conv1
31 }