镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 33 additions & 11 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,8 @@ void Compiler::optAssertionInit(bool isLocalProp)
optMaxAssertionCount = 64;
}

optAssertionTabCapacity = optMaxAssertionCount;

// Local assertion prop keeps mappings from each local var to the assertions about that var.
//
optAssertionDep =
Expand All @@ -947,21 +949,17 @@ void Compiler::optAssertionInit(bool isLocalProp)
optLocalAssertionProp = false;
optCrossBlockLocalAssertionProp = false;

// Heuristic for sizing the assertion table.
//
// The weighting of basicBlocks vs locals reflects their relative contribution observed empirically.
// Validated against 1,115,046 compiled methods:
// - 94.6% of methods stay at the floor of 64 (only 1.9% actually need more).
// - Underpredicts for 481 methods (0.043%), with a worst-case deficit of 127.
// - Only 0.4% of methods hit the 256 cap.
optMaxAssertionCount = (AssertionIndex)max(64, min(256, (int)(lvaTrackedCount + 3 * fgBBcount + 48) >> 2));
// The table grows on demand and the bit vectors are sized by the actual number
// of assertions once all of them are created (see optAssertionPropMain).
optMaxAssertionCount = 512;
optAssertionTabCapacity = 64;

optComplementaryAssertionMap = new (this, CMK_AssertionProp)
AssertionIndex[optMaxAssertionCount + 1](); // zero-inited (NO_ASSERTION_INDEX)
AssertionIndex[optAssertionTabCapacity + 1](); // zero-inited (NO_ASSERTION_INDEX)
}

optAssertionTabPrivate = new (this, CMK_AssertionProp) AssertionDsc[optMaxAssertionCount];
optAssertionTraitsInit(optMaxAssertionCount);
optAssertionTabPrivate = new (this, CMK_AssertionProp) AssertionDsc[optAssertionTabCapacity];
optAssertionTraitsInit(optAssertionTabCapacity);

optAssertionCount = 0;
optAssertionOverflow = 0;
Expand Down Expand Up @@ -1622,6 +1620,27 @@ AssertionIndex Compiler::optAddAssertion(const AssertionDsc& newAssertion)
return NO_ASSERTION_INDEX;
}

if (optAssertionCount == optAssertionTabCapacity)
{
// Only global assertion prop grows the table, see optAssertionInit.
assert(!optLocalAssertionProp);
const AssertionIndex newCapacity =
(AssertionIndex)min(2u * optAssertionTabCapacity, (unsigned)optMaxAssertionCount);

AssertionDsc* newTab = new (this, CMK_AssertionProp) AssertionDsc[newCapacity];
for (unsigned i = 0; i < optAssertionCount; i++)
{
newTab[i] = optAssertionTabPrivate[i];
}
optAssertionTabPrivate = newTab;

AssertionIndex* newMap = new (this, CMK_AssertionProp) AssertionIndex[newCapacity + 1]();
memcpy(newMap, optComplementaryAssertionMap, (optAssertionTabCapacity + 1) * sizeof(AssertionIndex));
optComplementaryAssertionMap = newMap;

optAssertionTabCapacity = newCapacity;
}

optAssertionTabPrivate[optAssertionCount] = newAssertion;
optAssertionCount++;

Expand Down Expand Up @@ -6781,6 +6800,9 @@ PhaseStatus Compiler::optAssertionPropMain()
madeChanges |= optCreateJumpTableImpliedAssertions(switchBlock);
}

// All assertions are created, size the bit vectors accordingly.
optAssertionTraitsInit(max(optAssertionCount, (AssertionIndex)1));

if (optAssertionCount == 0)
{
// Zero out the bbAssertionIn values, as these can be referenced in RangeCheck::MergeAssertion
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9310,6 +9310,7 @@ class Compiler
VNSet* optAssertionVNsMap = nullptr;
AssertionIndex optAssertionCount = 0; // total number of assertions in the assertion table
AssertionIndex optMaxAssertionCount;
AssertionIndex optAssertionTabCapacity;
bool optCrossBlockLocalAssertionProp;
unsigned optAssertionOverflow;
bool optCanPropLclVar;
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/jit/rangecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,11 @@ void RangeCheck::MergeEdgeAssertionsWorker(Compiler* comp

const Compiler::AssertionDsc& curAssertion = comp->optGetAssertion(assertionIndex);

if (curAssertion.GetOp2().KindIs(Compiler::O2K_CONST_INT) && (curAssertion.GetOp1().GetVN() != normalLclVN))
Comment thread
EgorBo marked this conversation as resolved.
Resolved
{
continue;
}

Limit limit(Limit::keUndef);
genTreeOps cmpOper = GT_NONE;
bool isUnsigned = false;
Expand Down
Loading