[llvm] r313658 - Handle profile mismatch correctly for SamplePGO.
Dehao Chen via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 19 11:26:54 PDT 2017
Author: dehao
Date: Tue Sep 19 11:26:54 2017
New Revision: 313658
URL: http://llvm.org/viewvc/llvm-project?rev=313658&view=rev
Log:
Handle profile mismatch correctly for SamplePGO.
Summary: Fix the bug when promoted call return type mismatches with the promoted function, we should not try to inline it. Otherwise it may lead to compiler crash.
Reviewers: davidxl, tejohnson, eraman
Reviewed By: tejohnson
Subscribers: llvm-commits, sanjoy
Differential Revision: https://reviews.llvm.org/D38018
Modified:
llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp
llvm/trunk/test/Transforms/SampleProfile/Inputs/indirect-call.prof
llvm/trunk/test/Transforms/SampleProfile/indirect-call.ll
Modified: llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp?rev=313658&r1=313657&r2=313658&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/SampleProfile.cpp Tue Sep 19 11:26:54 2017
@@ -720,7 +720,7 @@ bool SampleProfileLoader::inlineHotFunct
continue;
Instruction *DI = I;
if (!CalledFunction && !PromotedInsns.count(I) &&
- CallSite(I).isIndirectCall())
+ CallSite(I).isIndirectCall()) {
for (const auto *FS : findIndirectCallFunctionSamples(*I)) {
auto CalleeFunctionName = FS->getName();
// If it is a recursive call, we do not inline it as it could bloat
@@ -751,12 +751,17 @@ bool SampleProfileLoader::inlineHotFunct
continue;
}
}
+ // If there is profile mismatch, we should not attempt to inline DI.
+ if (!isa<CallInst>(DI) && !isa<InvokeInst>(DI))
+ continue;
+ }
if (!CalledFunction || !CalledFunction->getSubprogram()) {
findCalleeFunctionSamples(*I)->findImportedFunctions(
ImportGUIDs, F.getParent(),
Samples->getTotalSamples() * SampleProfileHotThreshold / 100);
continue;
}
+ assert(isa<CallInst>(DI) || isa<InvokeInst>(DI));
CallSite CS(DI);
DebugLoc DLoc = I->getDebugLoc();
BasicBlock *BB = I->getParent();
Modified: llvm/trunk/test/Transforms/SampleProfile/Inputs/indirect-call.prof
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SampleProfile/Inputs/indirect-call.prof?rev=313658&r1=313657&r2=313658&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SampleProfile/Inputs/indirect-call.prof (original)
+++ llvm/trunk/test/Transforms/SampleProfile/Inputs/indirect-call.prof Tue Sep 19 11:26:54 2017
@@ -20,3 +20,6 @@ test_inline_strip_conflict:3000:0
test_norecursive_inline:3000:0
1: test_norecursive_inline:3000
20: 3000
+test_noinline_bitcast:3000:0
+ 1: foo_direct_i32:3000
+ 1: 3000
Modified: llvm/trunk/test/Transforms/SampleProfile/indirect-call.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SampleProfile/indirect-call.ll?rev=313658&r1=313657&r2=313658&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SampleProfile/indirect-call.ll (original)
+++ llvm/trunk/test/Transforms/SampleProfile/indirect-call.ll Tue Sep 19 11:26:54 2017
@@ -69,6 +69,19 @@ define void @test_noinline(void ()*) !db
ret void
}
+; CHECK-LABEL: @test_noinline_bitcast
+; If the indirect call has been promoted to a direct call with bitcast,
+; do not inline it.
+define float @test_noinline_bitcast(float ()*) !dbg !26 {
+ %2 = alloca float ()*
+ store float ()* %0, float ()** %2
+; CHECK: icmp
+; CHECK: call
+ %3 = load float ()*, float ()** %2
+ %4 = call float %3(), !dbg !27
+ ret float %4
+}
+
; CHECK-LABEL: @test_norecursive_inline
; If the indirect call target is the caller, we should not promote it.
define void @test_norecursive_inline() !dbg !24 {
@@ -114,6 +127,10 @@ define void @foo_direct() !dbg !21 {
ret void
}
+define i32 @foo_direct_i32() !dbg !28 {
+ ret i32 0;
+}
+
; CHECK-LABEL: @test_direct
; We should not promote a direct call.
define void @test_direct() !dbg !22 {
@@ -155,3 +172,6 @@ define void @test_direct() !dbg !22 {
!23 = !DILocation(line: 23, scope: !22)
!24 = distinct !DISubprogram(name: "test_norecursive_inline", scope: !1, file: !1, line: 12, unit: !0)
!25 = !DILocation(line: 13, scope: !24)
+!26 = distinct !DISubprogram(name: "test_noinline_bitcast", scope: !1, file: !1, line: 12, unit: !0)
+!27 = !DILocation(line: 13, scope: !26)
+!28 = distinct !DISubprogram(name: "foo_direct_i32", scope: !1, file: !1, line: 11, unit: !0)
More information about the llvm-commits
mailing list