llvm.org GIT mirror llvm / 5a486ec
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266229 91177308-0d34-0410-b5e6-96231b3b80d8 Betul Buyukkurt 3 years ago
2 changed file(s) with 35 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
2626 #include "llvm/IR/Instructions.h"
2727 #include "llvm/IR/IntrinsicInst.h"
2828 #include "llvm/Pass.h"
29 #include "llvm/ProfileData/InstrProf.h"
2930 #include "llvm/Transforms/Scalar.h"
3031 using namespace llvm;
3132
6061 collectLiveScopes(*IA, AliveScopes);
6162 }
6263
64 // Check if this instruction is a runtime call for value profiling and
65 // if it's instrumenting a constant.
66 static bool isInstrumentsConstant(Instruction &I) {
67 if (CallInst *CI = dyn_cast(&I))
68 if (Function *Callee = CI->getCalledFunction())
69 if (Callee->getName().equals(getInstrProfValueProfFuncName()))
70 if (isa(CI->getArgOperand(0)))
71 return true;
72 return false;
73 }
74
6375 static bool aggressiveDCE(Function& F) {
6476 SmallPtrSet Alive;
6577 SmallVector Worklist;
6779 // Collect the set of "root" instructions that are known live.
6880 for (Instruction &I : instructions(F)) {
6981 if (isa(I) || I.isEHPad() || I.mayHaveSideEffects()) {
82 // Skip any value profile instrumentation calls if they are
83 // instrumenting constants.
84 if (isInstrumentsConstant(I))
85 continue;
7086 Alive.insert(&I);
7187 Worklist.push_back(&I);
7288 }
0 ; RUN: opt < %s -adce | FileCheck %s
1 ; RUN: opt < %s -passes=adce | FileCheck %s
2
3 ; Verify that a call to instrument a constant is deleted.
4
5 @__profc_foo = private global [1 x i64] zeroinitializer, section "__llvm_prf_cnts", align 8
6 @__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
7
8 define i32 @foo() {
9 ; CHECK-NOT: __llvm_profile_instrument_target
10 entry:
11 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)
12 %call = tail call i32 @bar(i32 21)
13 ret i32 %call
14 }
15
16 declare i32 @bar(i32)
17
18 declare void @__llvm_profile_instrument_target(i64, i8*, i32)