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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265037
91177308-0d34-0410-b5e6-
96231b3b80d8
if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock())
return;
+ if (isa<llvm::Constant>(ValuePtr))
+ return;
+
bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr();
if (InstrumentValueSites && RegionCounterMap) {
auto BuilderInsertPoint = Builder.saveIP();
--- /dev/null
+// 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;
+}