Skip to content

Commit 51f5fdc

Browse files
paigealesys_zuul
authored andcommitted
Fix for LLVM9 upgrade to limit the unrolling threshold for cases in which we get large numbers of integer operation inside of a loop. When we get into SCEV we can potentially get a stack overflow if the number of instructions gets too large to evaluate.
Change-Id: Iacee3e2ce597ba4edb6d8d1f0bfe2711d8f33539
1 parent 0a4c172 commit 51f5fdc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

IGC/Compiler/GenTTI.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ namespace llvm {
222222
}
223223
return Total - PHIs;
224224
};
225+
auto countIntegerOperations = [](BasicBlock* BB) {
226+
unsigned Int_Instructions = 0;
227+
for (auto BI = BB->begin(), BE = BB->end(); BI != BE; ++BI) {
228+
if (isa<IntegerType>((&*BI)->getType()))
229+
++Int_Instructions;
230+
}
231+
return Int_Instructions;
232+
};
225233
auto hasLoad = [](BasicBlock* BB) {
226234
for (auto BI = BB->begin(), BE = BB->end(); BI != BE; ++BI)
227235
if (isa<LoadInst>(&*BI))
@@ -243,11 +251,13 @@ namespace llvm {
243251
};
244252
// For innermost loop, allow certain patterns.
245253
unsigned Count = 0;
254+
unsigned Int_Count = 0;
246255
bool HasCall = false;
247256
bool HasStore = false;
248257
bool MayHasLoadInHeaderOnly = true;
249258
for (auto BI = L->block_begin(), BE = L->block_end(); BI != BE; ++BI) {
250259
Count += countNonPHI(*BI);
260+
Int_Count += countIntegerOperations(*BI);
251261
HasCall |= hasCall(*BI);
252262
HasStore |= hasStore(*BI);
253263
if (L->getHeader() != *BI)
@@ -263,6 +273,15 @@ namespace llvm {
263273
// The following is only available and required from LLVM 3.7+.
264274
UP.AllowExpensiveTripCount = true;
265275
}
276+
//Controls stack size growth being too big to compile. When we get into SCEV
277+
//and start processing the i32 instructions we can get too deep in the call stack
278+
//that we cause a stack overflow during compilation.
279+
unsigned Total_Potential_Inst = TripCount * Int_Count;
280+
if (Total_Potential_Inst > 2700)
281+
{
282+
UP.Threshold = 2000;
283+
UP.PartialThreshold = 2000;
284+
}
266285
}
267286
return;
268287
}

0 commit comments

Comments
 (0)