Author: betulb Date: Thu Mar 31 13:41:34 2016 New Revision: 265037 URL: http://llvm.org/viewvc/llvm-project?rev=265037&view=rev Log: [PGO] Avoid instrumenting constants at value sites
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. Added: cfe/trunk/test/Profile/c-avoid-direct-call.c Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=265037&r1=265036&r2=265037&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Thu Mar 31 13:41:34 2016 @@ -755,6 +755,9 @@ void CodeGenPGO::valueProfile(CGBuilderT if (!ValuePtr || !ValueSite || !Builder.GetInsertBlock()) return; + if (isa<llvm::Constant>(ValuePtr)) + return; + bool InstrumentValueSites = CGM.getCodeGenOpts().hasProfileClangInstr(); if (InstrumentValueSites && RegionCounterMap) { auto BuilderInsertPoint = Builder.saveIP(); Added: cfe/trunk/test/Profile/c-avoid-direct-call.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/c-avoid-direct-call.c?rev=265037&view=auto ============================================================================== --- cfe/trunk/test/Profile/c-avoid-direct-call.c (added) +++ cfe/trunk/test/Profile/c-avoid-direct-call.c Thu Mar 31 13:41:34 2016 @@ -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; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits