') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Skip assertion list look ups where unnecessary by kunalspathak · Pull Request #73142 · dotnet/runtime · GitHub
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
48 changes: 33 additions & 15 deletions src/coreclr/jit/assertionprop.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -979,6 +979,11 @@ void Compiler::optAssertionInit(bool isLocalProp)
optAssertionCount = 0;
optAssertionPropagated = false;
bbJtrueAssertionOut = nullptr;
optCanPropLclVar = false;
optCanPropEqual = false;
optCanPropNonNull = false;
optCanPropBndsChk = false;
optCanPropSubRange = false;
}

#ifdef DEBUG
Expand DownExpand Up@@ -1996,6 +2001,13 @@ AssertionIndex Compiler::optAddAssertion(AssertionDsc* newAssertion)
}
#endif // DEBUG

// Track the shortcircuit criterias
optCanPropLclVar |= newAssertion->CanPropLclVar();
optCanPropEqual |= newAssertion->CanPropEqualOrNotEqual();
optCanPropNonNull |= newAssertion->CanPropNonNull();
optCanPropSubRange |= newAssertion->CanPropSubRange();
optCanPropBndsChk |= newAssertion->CanPropBndsCheck();

// Assertion mask bits are [index + 1].
if (optLocalAssertionProp)
{
Expand DownExpand Up@@ -2826,7 +2838,7 @@ AssertionIndex Compiler::optFindComplementary(AssertionIndex assertIndex)
//
AssertionIndex Compiler::optAssertionIsSubrange(GenTree* tree, IntegralRange range, ASSERT_VALARG_TP assertions)
{
if (!optLocalAssertionProp && BitVecOps::IsEmpty(apTraits, assertions))
if ((!optLocalAssertionProp && BitVecOps::IsEmpty(apTraits, assertions)) || !optCanPropSubRange)
{
return NO_ASSERTION_INDEX;
}
Expand All@@ -2836,8 +2848,7 @@ AssertionIndex Compiler::optAssertionIsSubrange(GenTree* tree, IntegralRange ran
AssertionDsc* curAssertion = optGetAssertion(index);
if ((optLocalAssertionProp ||
BitVecOps::IsMember(apTraits, assertions, index - 1)) && // either local prop or use propagated assertions
(curAssertion->assertionKind == OAK_SUBRANGE) &&
(curAssertion->op1.kind == O1K_LCLVAR))
curAssertion->CanPropSubRange())
{
// For local assertion prop use comparison on locals, and use comparison on vns for global prop.
bool isEqual = optLocalAssertionProp
Expand DownExpand Up@@ -3597,6 +3608,13 @@ GenTree* Compiler::optAssertionProp_LclVar(ASSERT_VALARG_TP assertions, GenTreeL
return nullptr;
}

// There are no constant assertions for structs in global propagation.
//
if ((!optLocalAssertionProp && varTypeIsStruct(tree)) || !optCanPropLclVar)
{
return nullptr;
}

BitVecOps::Iter iter(apTraits, assertions);
unsigned index = 0;
while (iter.NextElem(&index))
Expand All@@ -3608,7 +3626,7 @@ GenTree* Compiler::optAssertionProp_LclVar(ASSERT_VALARG_TP assertions, GenTreeL
}
// See if the variable is equal to a constant or another variable.
AssertionDsc* curAssertion = optGetAssertion(assertionIndex);
if (curAssertion->assertionKind != OAK_EQUAL || curAssertion->op1.kind != O1K_LCLVAR)
if (!curAssertion->CanPropLclVar())
{
continue;
}
Expand DownExpand Up@@ -3795,7 +3813,7 @@ AssertionIndex Compiler::optLocalAssertionIsEqualOrNotEqual(
//
AssertionIndex Compiler::optGlobalAssertionIsEqualOrNotEqual(ASSERT_VALARG_TP assertions, GenTree* op1, GenTree* op2)
{
if (BitVecOps::IsEmpty(apTraits, assertions))
if (BitVecOps::IsEmpty(apTraits, assertions) || !optCanPropEqual)
{
return NO_ASSERTION_INDEX;
}
Expand All@@ -3809,7 +3827,7 @@ AssertionIndex Compiler::optGlobalAssertionIsEqualOrNotEqual(ASSERT_VALARG_TP as
break;
}
AssertionDsc* curAssertion = optGetAssertion(assertionIndex);
if ((curAssertion->assertionKind != OAK_EQUAL && curAssertion->assertionKind != OAK_NOT_EQUAL))
if (!curAssertion->CanPropEqualOrNotEqual())
{
continue;
}
Expand DownExpand Up@@ -3848,7 +3866,7 @@ AssertionIndex Compiler::optGlobalAssertionIsEqualOrNotEqual(ASSERT_VALARG_TP as
*/
AssertionIndex Compiler::optGlobalAssertionIsEqualOrNotEqualZero(ASSERT_VALARG_TP assertions, GenTree* op1)
{
if (BitVecOps::IsEmpty(apTraits, assertions))
if (BitVecOps::IsEmpty(apTraits, assertions) || !optCanPropEqual)
{
return NO_ASSERTION_INDEX;
}
Expand All@@ -3862,7 +3880,7 @@ AssertionIndex Compiler::optGlobalAssertionIsEqualOrNotEqualZero(ASSERT_VALARG_T
break;
}
AssertionDsc* curAssertion = optGetAssertion(assertionIndex);
if ((curAssertion->assertionKind != OAK_EQUAL && curAssertion->assertionKind != OAK_NOT_EQUAL))
if (!curAssertion->CanPropEqualOrNotEqual())
{
continue;
}
Expand DownExpand Up@@ -4487,6 +4505,11 @@ AssertionIndex Compiler::optAssertionIsNonNullInternal(GenTree* op,
*pVnBased = false;
#endif

if (!optCanPropNonNull)
{
return NO_ASSERTION_INDEX;
}

// If local assertion prop use lcl comparison, else use VN comparison.
if (!optLocalAssertionProp)
{
Expand DownExpand Up@@ -4531,12 +4554,7 @@ AssertionIndex Compiler::optAssertionIsNonNullInternal(GenTree* op,
break;
}
AssertionDsc* curAssertion = optGetAssertion(assertionIndex);
if (curAssertion->assertionKind != OAK_NOT_EQUAL)
{
continue;
}

if (curAssertion->op2.vn != ValueNumStore::VNForNull())
if (!curAssertion->CanPropNonNull())
{
continue;
}
Expand DownExpand Up@@ -4681,7 +4699,7 @@ GenTree* Compiler::optAssertionProp_Call(ASSERT_VALARG_TP assertions, GenTreeCal
*/
GenTree* Compiler::optAssertionProp_BndsChk(ASSERT_VALARG_TP assertions, GenTree* tree, Statement* stmt)
{
if (optLocalAssertionProp)
if (optLocalAssertionProp || !optCanPropBndsChk)
{
return nullptr;
}
Expand Down
30 changes: 30 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -7110,6 +7110,31 @@ class Compiler
return ((assertionKind == OAK_EQUAL) || (assertionKind == OAK_NOT_EQUAL)) && (op2.kind == O2K_CONST_INT);
}

bool CanPropLclVar()
{
return assertionKind == OAK_EQUAL && op1.kind == O1K_LCLVAR;
}

bool CanPropEqualOrNotEqual()
{
return assertionKind == OAK_EQUAL || assertionKind == OAK_NOT_EQUAL;
}

bool CanPropNonNull()
{
return assertionKind == OAK_NOT_EQUAL && op2.vn == ValueNumStore::VNForNull();
}

bool CanPropBndsCheck()
{
return op1.kind == O1K_ARR_BND;
}

bool CanPropSubRange()
{
return assertionKind == OAK_SUBRANGE && op1.kind == O1K_LCLVAR;
}

static bool SameKind(AssertionDsc* a1, AssertionDsc* a2)
{
return a1->assertionKind == a2->assertionKind && a1->op1.kind == a2->op1.kind &&
Expand DownExpand Up@@ -7231,6 +7256,11 @@ class Compiler
AssertionDsc* optAssertionTabPrivate; // table that holds info about value assignments
AssertionIndex optAssertionCount; // total number of assertions in the assertion table
AssertionIndex optMaxAssertionCount;
bool optCanPropLclVar;
bool optCanPropEqual;
bool optCanPropNonNull;
bool optCanPropBndsChk;
bool optCanPropSubRange;

public:
void optVnNonNullPropCurStmt(BasicBlock* block, Statement* stmt, GenTree* tree);
Expand Down