Skip to content

Commit 4bc7e6c

Browse files
author
GYT
committed
Add passed and missed opt-remarks to PartiallyInlineLibCalls
1 parent ff0f1dd commit 4bc7e6c

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ static bool optimizeSQRT(CallInst *Call, Function *CalledFunc,
5656
// dst = phi(v0, v1)
5757
//
5858

59+
ORE->emit([&]() {
60+
return OptimizationRemark(DEBUG_TYPE, "SqrtPartiallyInlined",
61+
Call->getDebugLoc(), &CurrBB)
62+
<< "Partially inlined call to sqrt function despite having to use "
63+
"errno for error handling: target has fast sqrt instruction";
64+
});
65+
ORE->emit([&]() {
66+
return OptimizationRemarkMissed(DEBUG_TYPE, "BranchInserted",
67+
Call->getDebugLoc(), &CurrBB)
68+
<< "Branch to library sqrt fn had to be inserted to satisfy the "
69+
"current target's requirement for math functions to set errno on "
70+
"invalid inputs";
71+
});
72+
5973
Type *Ty = Call->getType();
6074
IRBuilder<> Builder(Call->getNextNode());
6175

@@ -125,18 +139,35 @@ static bool runPartiallyInlineLibCalls(Function &F, TargetLibraryInfo *TLI,
125139
if (!Call || !(CalledFunc = Call->getCalledFunction()))
126140
continue;
127141

128-
if (Call->isNoBuiltin() || Call->isStrictFP())
129-
continue;
130-
131-
if (Call->isMustTailCall())
132-
continue;
133-
134142
// Skip if function either has local linkage or is not a known library
135143
// function.
136144
LibFunc LF;
137145
if (CalledFunc->hasLocalLinkage() ||
138146
!TLI->getLibFunc(*CalledFunc, LF) || !TLI->has(LF))
139147
continue;
148+
if (Call->isNoBuiltin())
149+
continue;
150+
if (Call->isStrictFP()) {
151+
ORE->emit([&]() {
152+
return OptimizationRemarkMissed(DEBUG_TYPE, "StrictFloat",
153+
Call->getDebugLoc(), &*CurrBB)
154+
<< "Could not consider library function for partial inlining:"
155+
" strict FP exception behavior is active";
156+
});
157+
continue;
158+
}
159+
// Partially inlining a libcall that has the musttail attribute leads to
160+
// broken LLVM IR, triggering an assertion in the IR verifier.
161+
// Work around that by forgoing this optimization for musttail calls.
162+
if (Call->isMustTailCall()) {
163+
ORE->emit([&]() {
164+
return OptimizationRemarkMissed(DEBUG_TYPE, "MustTailCall",
165+
Call->getDebugLoc(), &*CurrBB)
166+
<< "Could not consider library function for partial inlining:"
167+
" must tail call";
168+
});
169+
continue;
170+
}
140171

141172
switch (LF) {
142173
case LibFunc_sqrtf:

llvm/test/Transforms/PartiallyInlineLibCalls/X86/good-prototype.ll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
2+
; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu -pass-remarks=partially-inline-libcalls \
3+
; RUN: -pass-remarks-missed=partially-inline-libcalls 2>%t < %s | FileCheck %s
4+
; RUN: cat %t | FileCheck %s -check-prefix=CHECK-REMARK
35

46
define float @f(float %val) {
57
; CHECK-LABEL: @f(
8+
; CHECK-REMARK: Partially inlined call to sqrt function despite having to use errno for error handling: target has fast sqrt instruction
9+
; CHECK-REMARK: Branch to library sqrt fn had to be inserted to satisfy the current target's requirement for math functions to set errno on invalid inputs
610
; CHECK-NEXT: entry:
711
; CHECK-NEXT: [[RES:%.*]] = tail call float @sqrtf(float [[VAL:%.*]]) #[[READNONE:.*]]
812
; CHECK-NEXT: [[TMP0:%.*]] = fcmp oge float [[VAL]], 0.000000e+00

llvm/test/Transforms/PartiallyInlineLibCalls/X86/musttail.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
2+
; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu -pass-remarks-missed=partially-inline-libcalls 2>%t < %s | FileCheck %s
3+
; RUN: cat %t | FileCheck %s -check-prefix=CHECK-REMARK
34

45
define double @foo(double %x) {
56
; CHECK-LABEL: @foo(
7+
; CHECK-REMARK: Could not consider library function for partial inlining: must tail call
68
; CHECK-NEXT: [[R:%.*]] = musttail call double @sqrt(double [[X:%.*]])
79
; CHECK-NEXT: ret double [[R]]
810
;

llvm/test/Transforms/PartiallyInlineLibCalls/strictfp.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
1+
; RUN: opt -S -passes=partially-inline-libcalls -mtriple=x86_64-unknown-linux-gnu -pass-remarks-missed=partially-inline-libcalls 2>%t < %s | FileCheck %s
2+
; RUN: cat %t | FileCheck %s -check-prefix=CHECK-REMARK
23

34
define float @f(float %val) strictfp {
45
; CHECK-LABEL: @f
6+
; CHECK-REMARK: Could not consider library function for partial inlining: strict FP exception behavior is active
57
; CHECK: call{{.*}}@sqrtf
68
; CHECK-NOT: call{{.*}}@sqrtf
79
%res = tail call float @sqrtf(float %val) strictfp

0 commit comments

Comments
 (0)