@@ -1083,6 +1083,14 @@ namespace IGC {
1083
1083
RPE->rerunLivenessAnalysis (*F, &AffectedBBs);
1084
1084
};
1085
1085
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
+
1086
1094
bool EverChanged = false ;
1087
1095
1088
1096
// Find LIs in preheader that would definitely reduce
@@ -1105,6 +1113,7 @@ namespace IGC {
1105
1113
uint MaxLoopPressure = InitialLoopPressure;
1106
1114
1107
1115
bool AchievedNeededRegpressure = false ;
1116
+ bool RecomputeMaxLoopPressure = false ;
1108
1117
1109
1118
do
1110
1119
{
@@ -1159,9 +1168,21 @@ namespace IGC {
1159
1168
LocalInstSet.clear ();
1160
1169
}
1161
1170
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
+
1162
1181
rerunLiveness ();
1163
1182
MaxLoopPressure = getMaxRegCountForLoop (L);
1183
+ RecomputeMaxLoopPressure = false ;
1164
1184
PrintDump (" New max loop pressure = " << MaxLoopPressure << " \n " );
1185
+
1165
1186
if ((MaxLoopPressure < NeededRegpressure)
1166
1187
&& (Mode == LoopSinkMode::SinkWhileRegpressureIsHigh))
1167
1188
{
@@ -1199,6 +1220,12 @@ namespace IGC {
1199
1220
return false ;
1200
1221
}
1201
1222
1223
+ if (RecomputeMaxLoopPressure)
1224
+ {
1225
+ rerunLiveness ();
1226
+ MaxLoopPressure = getMaxRegCountForLoop (L);
1227
+ }
1228
+
1202
1229
PrintDump (" New max loop pressure = " << MaxLoopPressure << " \n " );
1203
1230
1204
1231
bool NeedToRollback = false ;
0 commit comments