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

Commit 6a773c4

Browse files
committed
Fix for duplicate call to Set when we run out of budget
1 parent 07143ef commit 6a773c4

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/jit/valuenum.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,8 +2381,8 @@ ValueNum ValueNumStore::VNForMapSelectWork(
23812381
{
23822382
#if FEATURE_VN_TRACE_APPLY_SELECTORS
23832383
JITDUMP(" AX1: select([" FMT_VN "]store(" FMT_VN ", " FMT_VN ", " FMT_VN "), " FMT_VN
2384-
") ==> " FMT_VN ".\n",
2385-
funcApp.m_args[0], arg0VN, funcApp.m_args[1], funcApp.m_args[2], arg1VN, funcApp.m_args[2]);
2384+
") ==> " FMT_VN ".\n",
2385+
funcApp.m_args[0], arg0VN, funcApp.m_args[1], funcApp.m_args[2], arg1VN, funcApp.m_args[2]);
23862386
#endif
23872387
return funcApp.m_args[2];
23882388
}
@@ -2393,9 +2393,9 @@ ValueNum ValueNumStore::VNForMapSelectWork(
23932393
assert(funcApp.m_args[1] != arg1VN); // we already checked this above.
23942394
#if FEATURE_VN_TRACE_APPLY_SELECTORS
23952395
JITDUMP(" AX2: " FMT_VN " != " FMT_VN " ==> select([" FMT_VN "]store(" FMT_VN ", " FMT_VN
2396-
", " FMT_VN "), " FMT_VN ") ==> select(" FMT_VN ", " FMT_VN ").\n",
2397-
arg1VN, funcApp.m_args[1], arg0VN, funcApp.m_args[0], funcApp.m_args[1], funcApp.m_args[2],
2398-
arg1VN, funcApp.m_args[0], arg1VN);
2396+
", " FMT_VN "), " FMT_VN ") ==> select(" FMT_VN ", " FMT_VN ").\n",
2397+
arg1VN, funcApp.m_args[1], arg0VN, funcApp.m_args[0], funcApp.m_args[1], funcApp.m_args[2],
2398+
arg1VN, funcApp.m_args[0], arg1VN);
23992399
#endif
24002400
// This is the equivalent of the recursive tail call:
24012401
// return VNForMapSelect(vnk, typ, funcApp.m_args[0], arg1VN);
@@ -2406,19 +2406,19 @@ ValueNum ValueNumStore::VNForMapSelectWork(
24062406
}
24072407
else if (funcApp.m_func == VNF_PhiDef || funcApp.m_func == VNF_PhiMemoryDef)
24082408
{
2409-
unsigned lclNum = BAD_VAR_NUM;
2409+
unsigned lclNum = BAD_VAR_NUM;
24102410
bool isMemory = false;
24112411
VNFuncApp phiFuncApp;
24122412
bool defArgIsFunc = false;
24132413
if (funcApp.m_func == VNF_PhiDef)
24142414
{
2415-
lclNum = unsigned(funcApp.m_args[0]);
2415+
lclNum = unsigned(funcApp.m_args[0]);
24162416
defArgIsFunc = GetVNFunc(funcApp.m_args[2], &phiFuncApp);
24172417
}
24182418
else
24192419
{
24202420
assert(funcApp.m_func == VNF_PhiMemoryDef);
2421-
isMemory = true;
2421+
isMemory = true;
24222422
defArgIsFunc = GetVNFunc(funcApp.m_args[1], &phiFuncApp);
24232423
}
24242424
if (defArgIsFunc && phiFuncApp.m_func == VNF_Phi)
@@ -2462,7 +2462,7 @@ ValueNum ValueNumStore::VNForMapSelectWork(
24622462
VNFuncApp phiArgFuncApp;
24632463
if (GetVNFunc(argRest, &phiArgFuncApp) && phiArgFuncApp.m_func == VNF_Phi)
24642464
{
2465-
cur = phiArgFuncApp.m_args[0];
2465+
cur = phiArgFuncApp.m_args[0];
24662466
argRest = phiArgFuncApp.m_args[1];
24672467
}
24682468
else
@@ -2525,13 +2525,17 @@ ValueNum ValueNumStore::VNForMapSelectWork(
25252525
}
25262526
}
25272527

2528-
// Otherwise, assign a new VN for the function application.
2529-
Chunk* c = GetAllocChunk(typ, CEA_Func2);
2530-
unsigned offsetWithinChunk = c->AllocVN();
2531-
res = c->m_baseVN + offsetWithinChunk;
2532-
reinterpret_cast<VNDefFunc2Arg*>(c->m_defs)[offsetWithinChunk] = fstruct;
2533-
GetVNFunc2Map()->Set(fstruct, res);
2534-
return res;
2528+
// We may have run out of budget and already assigned a result
2529+
if (!GetVNFunc2Map()->Lookup(fstruct, &res))
2530+
{
2531+
// Otherwise, assign a new VN for the function application.
2532+
Chunk* c = GetAllocChunk(typ, CEA_Func2);
2533+
unsigned offsetWithinChunk = c->AllocVN();
2534+
res = c->m_baseVN + offsetWithinChunk;
2535+
reinterpret_cast<VNDefFunc2Arg*>(c->m_defs)[offsetWithinChunk] = fstruct;
2536+
GetVNFunc2Map()->Set(fstruct, res);
2537+
}
2538+
return res;
25352539
}
25362540
}
25372541

0 commit comments

Comments
 (0)