Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 5bc1e42

Browse files
author
Sergey Andreenko
authored
Do not spill eeStack after ldtoken opcode. (#10215)
Do not spill eeStack if the last opcode was ldtoken.
1 parent cdde909 commit 5bc1e42

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/jit/compiler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,6 +3137,11 @@ class Compiler
31373137

31383138
//---------------- Spilling the importer stack ----------------------------
31393139

3140+
// The maximum number of bytes of IL processed without clean stack state.
3141+
// It allows to limit the maximum tree size and depth.
3142+
static const unsigned MAX_TREE_SIZE = 200;
3143+
bool impCanSpillNow(OPCODE prevOpcode);
3144+
31403145
struct PendingDsc
31413146
{
31423147
PendingDsc* pdNext;

src/jit/importer.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2594,6 +2594,21 @@ inline IL_OFFSETX Compiler::impCurILOffset(IL_OFFSET offs, bool callInstruction)
25942594
}
25952595
}
25962596

2597+
//------------------------------------------------------------------------
2598+
// impCanSpillNow: check is it possible to spill all values from eeStack to local variables.
2599+
//
2600+
// Arguments:
2601+
// prevOpcode - last importer opcode
2602+
//
2603+
// Return Value:
2604+
// true if it is legal, false if it could be a sequence that we do not want to divide.
2605+
bool Compiler::impCanSpillNow(OPCODE prevOpcode)
2606+
{
2607+
// Don't spill after ldtoken, because it could be a part of the InitializeArray sequence.
2608+
// Avoid breaking up to guarantee that impInitializeArrayIntrinsic can succeed.
2609+
return prevOpcode != CEE_LDTOKEN;
2610+
}
2611+
25972612
/*****************************************************************************
25982613
*
25992614
* Remember the instr offset for the statements
@@ -9554,7 +9569,7 @@ void Compiler::impImportBlockCode(BasicBlock* block)
95549569
/* Has it been a while since we last saw a non-empty stack (which
95559570
guarantees that the tree depth isnt accumulating. */
95569571

9557-
if ((opcodeOffs - lastSpillOffs) > 200)
9572+
if ((opcodeOffs - lastSpillOffs) > MAX_TREE_SIZE && impCanSpillNow(prevOpcode))
95589573
{
95599574
impSpillStackEnsure();
95609575
lastSpillOffs = opcodeOffs;

0 commit comments

Comments
 (0)