Skip to content

Commit 75e5c50

Browse files
committed
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
1 parent 0b8abab commit 75e5c50

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,14 +1139,19 @@ Instruction *InstCombiner::visitFPTrunc(FPTruncInst &CI) {
11391139
Arg->getOperand(0)->getType()->isFloatTy()) {
11401140
Function *Callee = Call->getCalledFunction();
11411141
Module *M = CI.getParent()->getParent()->getParent();
1142-
Constant* SqrtfFunc = M->getOrInsertFunction("sqrtf",
1142+
Constant *SqrtfFunc = M->getOrInsertFunction("sqrtf",
11431143
Callee->getAttributes(),
11441144
Builder->getFloatTy(),
11451145
Builder->getFloatTy(),
11461146
NULL);
11471147
CallInst *ret = CallInst::Create(SqrtfFunc, Arg->getOperand(0),
11481148
"sqrtfcall");
11491149
ret->setAttributes(Callee->getAttributes());
1150+
1151+
1152+
// Remove the old Call. With -fmath-errno, it won't get marked readnone.
1153+
Call->replaceAllUsesWith(UndefValue::get(Call->getType()));
1154+
EraseInstFromFunction(*Call);
11501155
return ret;
11511156
}
11521157
}

llvm/test/Transforms/InstCombine/2010-07-19-sqrt.ll

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: opt -S -instcombine %s | FileCheck %s
2+
3+
define float @test1(float %x) nounwind readnone ssp {
4+
entry:
5+
; CHECK: @test1
6+
; CHECK-NOT: fpext
7+
; CHECK-NOT: sqrt(
8+
; CHECK: sqrtf(
9+
; CHECK-NOT: fptrunc
10+
%conv = fpext float %x to double ; <double> [#uses=1]
11+
%call = tail call double @sqrt(double %conv) readnone nounwind ; <double> [#uses=1]
12+
%conv1 = fptrunc double %call to float ; <float> [#uses=1]
13+
; CHECK: ret float
14+
ret float %conv1
15+
}
16+
17+
declare double @sqrt(double)
18+
19+
; PR8096
20+
define float @test2(float %x) nounwind readnone ssp {
21+
entry:
22+
; CHECK: @test2
23+
; CHECK-NOT: fpext
24+
; CHECK-NOT: sqrt(
25+
; CHECK: sqrtf(
26+
; CHECK-NOT: fptrunc
27+
%conv = fpext float %x to double ; <double> [#uses=1]
28+
%call = tail call double @sqrt(double %conv) nounwind ; <double> [#uses=1]
29+
%conv1 = fptrunc double %call to float ; <float> [#uses=1]
30+
; CHECK: ret float
31+
ret float %conv1
32+
}

0 commit comments

Comments
 (0)