[PATCH] D18636: [PGO] Avoid instrumenting constants at value sites

Betul Buyukkurt via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 30 19:53:19 PDT 2016


betulb created this revision.
betulb added reviewers: davidxl, bogner.
betulb added subscribers: llvm-commits, cfe-commits.
betulb set the repository for this revision to rL LLVM.
betulb changed the visibility of this Differential Revision from "Public (No Login Required)" to "All Users".

Value profiling should not profile constants and/or constant expressions when they appear as callees in call instructions. Constant expressions form when a direct callee has bitcasts or inttoptr(ptrtint (callee)) nests surrounding it. Value profiling should avoid instrumenting such cases. Mostly NFC.


Repository:
  rL LLVM

http://reviews.llvm.org/D18636

Files:
  lib/CodeGen/CodeGenPGO.cpp
  test/Profile/c-avoid-direct-call.c

Index: test/Profile/c-avoid-direct-call.c
===================================================================
--- /dev/null
+++ test/Profile/c-avoid-direct-call.c
@@ -0,0 +1,11 @@
+// Check the value profiling instrinsics emitted by instrumentation.
+
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-avoid-direct-call.c %s -o - -emit-llvm -fprofile-instrument=clang -mllvm -enable-value-profiling | FileCheck %s
+
+void foo();
+
+int main(void) {
+// CHECK-NOT: call void @__llvm_profile_instrument_target(i64 ptrtoint (void (...)* @foo to i64), i8* bitcast ({{.*}}* @__profd_main to i8*), i32 0)
+  foo(21);
+  return 0;
+}
Index: lib/CodeGen/CodeGenPGO.cpp
===================================================================
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -755,6 +755,9 @@
   if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock())
     return;
 
+  if (dyn_cast<llvm::Constant>(ValuePtr))
+    return;
+
   bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr();
   if (InstrumentValueSites && RegionCounterMap) {
     auto BuilderInsertPoint = Builder.saveIP();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18636.52169.patch
Type: text/x-patch
Size: 1141 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160331/a5ab5c5d/attachment.bin>


More information about the cfe-commits mailing list