Skip to content

Commit 7233428

Browse files
admitricigcbot
authored andcommitted
Improve CodeLoopSinking compilation time
Add a heuristic to check the candidates size on every iteration before rerunning the liveness analysis. Skip the rerun if the candidates size is too small to achieve the needed register pressure
1 parent 4f43ac7 commit 7233428

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

IGC/Compiler/CISACodeGen/CodeSinking.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,14 @@ namespace IGC {
10831083
RPE->rerunLivenessAnalysis(*F, &AffectedBBs);
10841084
};
10851085

1086+
auto getSizeInRegs = [&](const SmallVectorImpl<Instruction *> &Insts)
1087+
{
1088+
auto SIMD = numLanes(RPE->bestGuessSIMDSize(F));
1089+
ValueSet InstsSet(Insts.begin(), Insts.end());
1090+
unsigned int SizeInBytes = RPE->estimateSizeInBytes(InstsSet, *F, SIMD, &WI);
1091+
return RPE->bytesToRegisters(SizeInBytes);
1092+
};
1093+
10861094
bool EverChanged = false;
10871095

10881096
// Find LIs in preheader that would definitely reduce
@@ -1105,6 +1113,7 @@ namespace IGC {
11051113
uint MaxLoopPressure = InitialLoopPressure;
11061114

11071115
bool AchievedNeededRegpressure = false;
1116+
bool RecomputeMaxLoopPressure = false;
11081117

11091118
do
11101119
{
@@ -1159,9 +1168,21 @@ namespace IGC {
11591168
LocalInstSet.clear();
11601169
}
11611170

1171+
if (MaxLoopPressure - getSizeInRegs(SinkCandidates) > NeededRegpressure)
1172+
{
1173+
// Heuristic to save recalculation of liveness
1174+
// The size of the candidates set is not enough to reach the needed regpressure
1175+
// even if we sinked everything
1176+
PrintDump("Running one more iteration without recalculating liveness...\n");
1177+
RecomputeMaxLoopPressure = true;
1178+
continue;
1179+
}
1180+
11621181
rerunLiveness();
11631182
MaxLoopPressure = getMaxRegCountForLoop(L);
1183+
RecomputeMaxLoopPressure = false;
11641184
PrintDump("New max loop pressure = " << MaxLoopPressure << "\n");
1185+
11651186
if ((MaxLoopPressure < NeededRegpressure)
11661187
&& (Mode == LoopSinkMode::SinkWhileRegpressureIsHigh))
11671188
{
@@ -1199,6 +1220,12 @@ namespace IGC {
11991220
return false;
12001221
}
12011222

1223+
if (RecomputeMaxLoopPressure)
1224+
{
1225+
rerunLiveness();
1226+
MaxLoopPressure = getMaxRegCountForLoop(L);
1227+
}
1228+
12021229
PrintDump("New max loop pressure = " << MaxLoopPressure << "\n");
12031230

12041231
bool NeedToRollback = false;

0 commit comments

Comments
 (0)