[PATCH] D20991: Set machine block placement hot prob threshold for both static and runtime profile.
David Li via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 3 15:52:04 PDT 2016
davidxl added a comment.
The PGO related change is only half correct. In fact the trace successor probability threshold should be computed based on existing parameters misfetch cost and jump instruction cost.
In a diamond shaped CFG, the resulting succProb threshold is indeed 50% as the CFG is symmetric. For Triagular shaped CFG, the result will be very different because breaking topological order introduces more overhead compared with diamond shape case.
Given
A
/ |
B |
\ |
C
If Prob(A,B) is greater than Prob(A,C), A B C should always be the right order. However, if if Prob(A,B) is lower than P(A,C), we need to compare the cost of A B C vs A C B
For A B C, the cost is
Prob(A,C) * Misfetch_cost due to the taken branch from A to C
For A C B, the cost is
Prob(A, B) *Misfetch_cost // taken branch from A to B
+ Prob(A,B) * misfetch_cost // taken branch (unconditional) from B back to C
+ Prob(A,B) * jump_inst_cost // one more unconditional jump instruction is introduced
If jump instruction cost is assumed to be low (0), then Prob(A,C) needs to be >66% in order for A C B to be a better layout. If jump instr cost is the same as misfetch, we get 75% threshold.
We need to introduce a helper function to compute the threshold on the fly based on the CFG and parameter.
================
Comment at: lib/CodeGen/MachineBlockPlacement.cpp:120
@@ +119,3 @@
+static cl::opt<unsigned> StaticHotProb(
+ "static-hot-prob",
+ cl::desc("Hot branch probability when only static profile is available."),
----------------
hot-->likely
================
Comment at: lib/CodeGen/MachineBlockPlacement.cpp:125
@@ +124,3 @@
+static cl::opt<unsigned> ProfileHotProb(
+ "profile-hot-prob",
+ cl::desc("Hot branch probability when only runtime profile is available."),
----------------
hot --> likely
http://reviews.llvm.org/D20991
More information about the llvm-commits
mailing list