[llvm] r266229 - [PGO] Remove redundant VP instrumentation

Betul Buyukkurt via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 13 11:52:19 PDT 2016


Author: betulb
Date: Wed Apr 13 13:52:19 2016
New Revision: 266229

URL: http://llvm.org/viewvc/llvm-project?rev=266229&view=rev
Log:
[PGO] Remove redundant VP instrumentation

LLVM optimization passes may reduce a profiled target expression
to a constant. Removing runtime calls at such instrumentation points
would help speedup the runtime of the instrumented program.


Added:
    llvm/trunk/test/Transforms/ADCE/delete-profiling-calls-to-constant.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/ADCE.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/ADCE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ADCE.cpp?rev=266229&r1=266228&r2=266229&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ADCE.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ADCE.cpp Wed Apr 13 13:52:19 2016
@@ -27,6 +27,7 @@
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/Pass.h"
+#include "llvm/ProfileData/InstrProf.h"
 #include "llvm/Transforms/Scalar.h"
 using namespace llvm;
 
@@ -61,6 +62,17 @@ static void collectLiveScopes(const DILo
     collectLiveScopes(*IA, AliveScopes);
 }
 
+// Check if this instruction is a runtime call for value profiling and
+// if it's instrumenting a constant.
+static bool isInstrumentsConstant(Instruction &I) {
+  if (CallInst *CI = dyn_cast<CallInst>(&I))
+    if (Function *Callee = CI->getCalledFunction())
+      if (Callee->getName().equals(getInstrProfValueProfFuncName()))
+        if (isa<Constant>(CI->getArgOperand(0)))
+          return true;
+  return false;
+}
+
 static bool aggressiveDCE(Function& F) {
   SmallPtrSet<Instruction*, 32> Alive;
   SmallVector<Instruction*, 128> Worklist;
@@ -68,6 +80,10 @@ static bool aggressiveDCE(Function& F) {
   // Collect the set of "root" instructions that are known live.
   for (Instruction &I : instructions(F)) {
     if (isa<TerminatorInst>(I) || I.isEHPad() || I.mayHaveSideEffects()) {
+      // Skip any value profile instrumentation calls if they are
+      // instrumenting constants.
+      if (isInstrumentsConstant(I))
+        continue;
       Alive.insert(&I);
       Worklist.push_back(&I);
     }

Added: llvm/trunk/test/Transforms/ADCE/delete-profiling-calls-to-constant.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ADCE/delete-profiling-calls-to-constant.ll?rev=266229&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/ADCE/delete-profiling-calls-to-constant.ll (added)
+++ llvm/trunk/test/Transforms/ADCE/delete-profiling-calls-to-constant.ll Wed Apr 13 13:52:19 2016
@@ -0,0 +1,19 @@
+; RUN: opt < %s -adce | FileCheck %s
+; RUN: opt < %s -passes=adce | FileCheck %s
+
+; Verify that a call to instrument a constant is deleted.
+
+ at __profc_foo = private global [1 x i64] zeroinitializer, section "__llvm_prf_cnts", align 8
+ at __profd_foo = private global { i64, i64, i64*, i8*, i8*, i32, [1 x i16] } { i64 6699318081062747564, i64 0, i64* getelementptr inbounds ([1 x i64], [1 x i64]* @__profc_foo, i32 0, i32 0), i8* bitcast (i32 ()* @foo to i8*), i8* null, i32 1, [1 x i16] [i16 1] }, section "__llvm_prf_data", align 8
+
+define i32 @foo() {
+; CHECK-NOT: __llvm_profile_instrument_target
+entry:
+  tail call void @__llvm_profile_instrument_target(i64 ptrtoint (i32 (i32)* @bar to i64), i8* bitcast ({ i64, i64, i64*, i8*, i8*, i32, [1 x i16] }* @__profd_foo to i8*), i32 0)
+  %call = tail call i32 @bar(i32 21)
+  ret i32 %call
+}
+
+declare i32 @bar(i32)
+
+declare void @__llvm_profile_instrument_target(i64, i8*, i32)




More information about the llvm-commits mailing list