[PGO] Avoid instrumenting constants at value sites
authorBetul Buyukkurt <betulb@codeaurora.org>
Thu, 31 Mar 2016 18:41:34 +0000 (18:41 +0000)
committerBetul Buyukkurt <betulb@codeaurora.org>
Thu, 31 Mar 2016 18:41:34 +0000 (18:41 +0000)
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.

llvm-svn: 265037

clang/lib/CodeGen/CodeGenPGO.cpp
clang/test/Profile/c-avoid-direct-call.c [new file with mode: 0644]

index e5993f5..7e89492 100644 (file)
@@ -755,6 +755,9 @@ void CodeGenPGO::valueProfile(CGBuilderTy &Builder, uint32_t ValueKind,
   if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock())
     return;
 
+  if (isa<llvm::Constant>(ValuePtr))
+    return;
+
   bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr();
   if (InstrumentValueSites && RegionCounterMap) {
     auto BuilderInsertPoint = Builder.saveIP();
diff --git a/clang/test/Profile/c-avoid-direct-call.c b/clang/test/Profile/c-avoid-direct-call.c
new file mode 100644 (file)
index 0000000..cd02e71
--- /dev/null
@@ -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
+  foo(21);
+  return 0;
+}