[PATCH] D29569: Fix the bug of samplepgo indirect call promption when type casting of the return value is needed.

Dehao Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 5 14:45:40 PST 2017


danielcdh created this revision.

When type casting of the return value is needed, promoteIndirectCall will return the type casting instruction instead of the direct call. This patch changed to return the direct call instruction instead.


https://reviews.llvm.org/D29569

Files:
  lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
  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
@@ -12,16 +12,16 @@
 
 ; CHECK-LABEL: @test_inline
 ; If the indirect call is promoted and inlined in profile, we should promote and inline it.
-define void @test_inline(void ()*) !dbg !3 {
-  %2 = alloca void ()*
-  store void ()* %0, void ()** %2
-  %3 = load void ()*, void ()** %2
+define void @test_inline(i64* (i32*)*, i32* %x) !dbg !3 {
+  %2 = alloca i64* (i32*)*
+  store i64* (i32*)* %0, i64* (i32*)** %2
+  %3 = load i64* (i32*)*, i64* (i32*)** %2
 ; CHECK: icmp {{.*}} @foo_inline
 ; CHECK: if.true.direct_targ:
 ; CHECK-NOT: call
 ; CHECK: if.false.orig_indirect:
 ; CHECK: call
-  call void %3(), !dbg !5
+  call i64* %3(i32* %x), !dbg !5
   ret void
 }
 
@@ -37,8 +37,10 @@
   ret void
 }
 
-define void @foo_inline() !dbg !3 {
-  ret void
+ at x = global i32 0, align 4
+
+define i32* @foo_inline(i32* %x) !dbg !3 {
+  ret i32* %x
 }
 
 define i32 @foo_noinline(i32 %x) !dbg !3 {
Index: lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
===================================================================
--- lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
+++ lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
@@ -558,7 +558,13 @@
       BB->getContext(), "pgo-icall-prom", *BB->getParent(), Inst->getDebugLoc(),
       Twine("Promote indirect call to ") + DirectCallee->getName() +
           " with count " + Twine(Count) + " out of " + Twine(TotalCount));
-  return NewInst;
+
+  while (NewInst && NewInst->getParent() == DirectCallBB)
+    if (isa<CallInst>(NewInst))
+      return NewInst;
+    else
+      NewInst = NewInst->getPrevNode();
+  return nullptr;
 }
 
 // Promote indirect-call to conditional direct-call for one callsite.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29569.87169.patch
Type: text/x-patch
Size: 1902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170205/c56ff9c6/attachment.bin>


More information about the llvm-commits mailing list