[PATCH] D29570: Fix the samplepgo indirect call promotion bug: we should not promote a direct call.
Dehao Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 6 15:32:34 PST 2017
danielcdh updated this revision to Diff 87326.
danielcdh added a comment.
update
https://reviews.llvm.org/D29570
Files:
include/llvm/Analysis/IndirectCallSiteVisitor.h
include/llvm/IR/CallSite.h
lib/Transforms/IPO/SampleProfile.cpp
test/Transforms/SampleProfile/Inputs/indirect-call.prof
test/Transforms/SampleProfile/indirect-call.ll
Index: test/Transforms/SampleProfile/indirect-call.ll
===================================================================
--- test/Transforms/SampleProfile/indirect-call.ll
+++ test/Transforms/SampleProfile/indirect-call.ll
@@ -47,6 +47,21 @@
ret i32 %x
}
+define void @foo_direct() !dbg !3 {
+ ret void
+}
+
+; CHECK-LABEL: @test_direct
+; We should not promote a direct call.
+define void @test_direct() !dbg !3 {
+; CHECK-NOT: icmp
+; CHECK: call
+ call void @foo_alias(), !dbg !5
+ ret void
+}
+
+ at foo_alias = alias void (), void ()* @foo_direct
+
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2}
Index: test/Transforms/SampleProfile/Inputs/indirect-call.prof
===================================================================
--- test/Transforms/SampleProfile/Inputs/indirect-call.prof
+++ test/Transforms/SampleProfile/Inputs/indirect-call.prof
@@ -6,3 +6,6 @@
test_noinline:3000:0
5: foo_noinline:3000
1: 3000
+test_direct:3000:0
+ 5: foo_direct:3000
+ 1: 3000
Index: lib/Transforms/IPO/SampleProfile.cpp
===================================================================
--- lib/Transforms/IPO/SampleProfile.cpp
+++ lib/Transforms/IPO/SampleProfile.cpp
@@ -634,7 +634,8 @@
InlineFunctionInfo IFI(nullptr, ACT ? &GetAssumptionCache : nullptr);
Function *CalledFunction = CallSite(I).getCalledFunction();
Instruction *DI = I;
- if (!CalledFunction && !PromotedInsns.count(I)) {
+ if (!CalledFunction && !PromotedInsns.count(I) &&
+ CallSite(I).isIndirectCall()) {
auto CalleeFunctionName = findCalleeFunctionSamples(*I)->getName();
const char *Reason = "Callee function not available";
CalledFunction = F.getParent()->getFunction(CalleeFunctionName);
Index: include/llvm/IR/CallSite.h
===================================================================
--- include/llvm/IR/CallSite.h
+++ include/llvm/IR/CallSite.h
@@ -111,6 +111,20 @@
return dyn_cast<FunTy>(getCalledValue());
}
+ /// Returns true if the callsite is an indirect call
+ bool isIndirectCall() const {
+ Value *V = getCalledValue();
+ if (!V)
+ return false;
+ if (isa<FunTy>(V) || isa<Constant>(V))
+ return false;
+ if (CallInst *CI = dyn_cast<CallInst>(getInstruction())) {
+ if (CI->isInlineAsm())
+ return false;
+ }
+ return true;
+ }
+
/// setCalledFunction - Set the callee to the specified value.
///
void setCalledFunction(Value *V) {
Index: include/llvm/Analysis/IndirectCallSiteVisitor.h
===================================================================
--- include/llvm/Analysis/IndirectCallSiteVisitor.h
+++ include/llvm/Analysis/IndirectCallSiteVisitor.h
@@ -21,16 +21,8 @@
PGOIndirectCallSiteVisitor() {}
void visitCallSite(CallSite CS) {
- if (CS.getCalledFunction() || !CS.getCalledValue())
- return;
- Instruction *I = CS.getInstruction();
- if (CallInst *CI = dyn_cast<CallInst>(I)) {
- if (CI->isInlineAsm())
- return;
- }
- if (isa<Constant>(CS.getCalledValue()))
- return;
- IndirectCallInsts.push_back(I);
+ if (CS.isIndirectCall())
+ IndirectCallInsts.push_back(CS.getInstruction());
}
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29570.87326.patch
Type: text/x-patch
Size: 3199 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170206/45242177/attachment.bin>
More information about the llvm-commits
mailing list