[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
Sun Feb 5 15:32:08 PST 2017


danielcdh created this revision.

Checking CS.getCalledFunction() == nullptr does not necessary indicate indirect call. We also need to check if CS.getCalledValue() is not a constant.


https://reviews.llvm.org/D29570

Files:
  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
@@ -45,6 +45,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
@@ -632,9 +632,11 @@
     }
     for (auto I : CIS) {
       InlineFunctionInfo IFI(nullptr, ACT ? &GetAssumptionCache : nullptr);
-      Function *CalledFunction = CallSite(I).getCalledFunction();
+      CallSite CS(I);
+      Function *CalledFunction = CS.getCalledFunction();
       Instruction *DI = I;
-      if (!CalledFunction && !PromotedInsns.count(I)) {
+      if (!CalledFunction && !PromotedInsns.count(I) && CS.getCalledValue() &&
+          !isa<Constant>(CS.getCalledValue())) {
         auto CalleeFunctionName = findCalleeFunctionSamples(*I)->getName();
         const char *Reason = "Callee function not available";
         CalledFunction = F.getParent()->getFunction(CalleeFunctionName);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29570.87171.patch
Type: text/x-patch
Size: 1890 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170205/8c927c04/attachment.bin>


More information about the llvm-commits mailing list