mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
700b4d043d
Currently the pass updates branch weights in the IR if the function has any PGO info (entry frequency is set). However we could still have regions of the CFG that does not have branch weights collected (e.g. a cold region). In this case we'd use static estimates. Since static estimates for branches are determined independently, they are inconsistent. Updating them can "randomly" inflate block frequencies. I've run into this in a completely cold loop of h264ref from SPEC. -Rpass-with-hotness showed the loop to be completely cold during inlining (before JT) but completely hot during vectorization (after JT). The new testcase demonstrate the problem. We check array elements against 1, 2 and 3 in a loop. The check against 3 is the loop-exiting check. The block names should be self-explanatory. In this example, jump threading incorrectly updates the weight of the loop-exiting branch to 0, drastically inflating the frequency of the loop (in the range of billions). There is no run-time profile info for edges inside the loop, so branch probabilities are estimated. These are the resulting branch and block frequencies for the loop body: check_1 (16) (8) / | eq_1 | (8) \ | check_2 (16) (8) / | eq_2 | (8) \ | check_3 (16) (1) / | (loop exit) | (15) | (back edge) First we thread eq_1 -> check_2 to check_3. Frequencies are updated to remove the frequency of eq_1 from check_2 and then from the false edge leaving check_2. Changed frequencies are highlighted with * *: check_1 (16) (8) / | eq_1~ | (8) / | / check_2 (*8*) / (8) / | \ eq_2 | (*0*) \ \ | ` --- check_3 (16) (1) / | (loop exit) | (15) | (back edge) Next we thread eq_1 -> check_3 and eq_2 -> check_3 to check_1 as new back edges. Frequencies are updated to remove the frequency of eq_1 and eq_3 from check_3 and then the false edge leaving check_3 (changed frequencies are highlighted with * *): check_1 (16) (8) / | eq_1~ | (8) / | / check_2 (*8*) / (8) / | /-- eq_2~ | (*0*) (back edge) | check_3 (*0*) (*0*) / | (loop exit) | (*0*) | (back edge) As a result, the loop exit edge ends up with 0 frequency which in turn makes the loop header to have maximum frequency. There are a few potential problems here: 1. The profile data seems odd. There is a single profile sample of the loop being entered. On the other hand, there are no weights inside the loop. 2. Based on static estimation we shouldn't set edges to "extreme" values, i.e. extremely likely or unlikely. 3. We shouldn't create profile metadata that is calculated from static estimation. I am not sure what policy is but it seems to make sense to treat profile metadata as something that is known to originate from profiling. Estimated probabilities should only be reflected in BPI/BFI. Any one of these would probably fix the immediate problem. I went for 3 because I think it's a good policy to have and added a FIXME about 2. Differential Revision: https://reviews.llvm.org/D24118 llvm-svn: 280713 |
||
---|---|---|
.. | ||
ADCE | ||
AddDiscriminators | ||
AlignmentFromAssumptions | ||
ArgumentPromotion | ||
AtomicExpand | ||
BBVectorize | ||
BDCE | ||
BranchFolding | ||
CodeExtractor | ||
CodeGenPrepare | ||
ConstantHoisting | ||
ConstantMerge | ||
ConstProp | ||
Coroutines | ||
CorrelatedValuePropagation | ||
CountingFunctionInserter | ||
CrossDSOCFI | ||
DCE | ||
DeadArgElim | ||
DeadStoreElimination | ||
EarlyCSE | ||
EliminateAvailableExternally | ||
Float2Int | ||
ForcedFunctionAttrs | ||
FunctionAttrs | ||
FunctionImport | ||
GCOVProfiling | ||
GlobalDCE | ||
GlobalMerge | ||
GlobalOpt | ||
GuardWidening | ||
GVN | ||
GVNHoist | ||
IndVarSimplify | ||
InferFunctionAttrs | ||
Inline | ||
InstCombine | ||
InstMerge | ||
InstSimplify | ||
Internalize | ||
IPConstantProp | ||
IRCE | ||
JumpThreading | ||
LCSSA | ||
LICM | ||
LoadCombine | ||
LoadStoreVectorizer | ||
LoopDataPrefetch | ||
LoopDeletion | ||
LoopDistribute | ||
LoopIdiom | ||
LoopInterchange | ||
LoopLoadElim | ||
LoopReroll | ||
LoopRotate | ||
LoopSimplify | ||
LoopSimplifyCFG | ||
LoopStrengthReduce | ||
LoopUnroll | ||
LoopUnswitch | ||
LoopVectorize | ||
LoopVersioning | ||
LoopVersioningLICM | ||
LowerAtomic | ||
LowerExpectIntrinsic | ||
LowerGuardIntrinsic | ||
LowerInvoke | ||
LowerSwitch | ||
LowerTypeTests | ||
Mem2Reg | ||
MemCpyOpt | ||
MergeFunc | ||
MetaRenamer | ||
NameAnonFunctions | ||
NaryReassociate | ||
ObjCARC | ||
PartiallyInlineLibCalls | ||
PGOProfile | ||
PhaseOrdering | ||
PlaceSafepoints | ||
PreISelIntrinsicLowering | ||
PruneEH | ||
Reassociate | ||
Reg2Mem | ||
RewriteStatepointsForGC | ||
SafeStack | ||
SampleProfile | ||
Scalarizer | ||
SCCP | ||
SeparateConstOffsetFromGEP | ||
SimplifyCFG | ||
Sink | ||
SLPVectorizer | ||
SpeculativeExecution | ||
SROA | ||
StraightLineStrengthReduce | ||
StripDeadPrototypes | ||
StripSymbols | ||
StructurizeCFG | ||
TailCallElim | ||
Util | ||
WholeProgramDevirt |