Optimize BBQ for runs of jump targets in br.table - #31786
Conversation
|
EWS run on previous version of this PR (hash 707c838) Details |
kmiller68
left a comment
There was a problem hiding this comment.
I think we should integrate this into BinarySwitch rather than add a new class. That could be done by adding a new constructor if needed.
There was a problem hiding this comment.
This whitespace change seems wrong.
There was a problem hiding this comment.
This could just be out.print(kind);
707c838 to
8c5b442
Compare
|
EWS run on previous version of this PR (hash 8c5b442) Details |
https://bugs.webkit.org/show_bug.cgi?id=277686 rdar://133300128 Reviewed by NOBODY (OOPS!). Previously, BBQ generated an entire binary search for every possible case in a `br.table`, even if we had long consecutive runs that could avoid many comparisons. This patch optimizes `br.table` generation to reduce the tree depth when it is possible. * Source/JavaScriptCore/jit/BinarySwitch.cpp: (JSC::BinarySwitch::BinarySwitch): (JSC::BinarySwitch::advance): (JSC::BinarySwitch::buildCheckRuns): (JSC::BinarySwitch::BranchCode::dump const): * Source/JavaScriptCore/jit/BinarySwitch.h: (JSC::BinarySwitch::BranchCode::BranchCode): * Source/JavaScriptCore/wasm/WasmBBQJIT.cpp: (JSC::Wasm::BBQJITImpl::BBQJIT::addSwitch):
8c5b442 to
d39f470
Compare
|
EWS run on current version of this PR (hash d39f470) Details |
| while (wasmSwitch.advance(m_jit)) { | ||
| unsigned value = wasmSwitch.caseValue(); | ||
| unsigned index = wasmSwitch.caseIndex(); | ||
| UNUSED_VARIABLE(value); |
There was a problem hiding this comment.
Yeah, just get rid of value
| m_cases.append(Case(cases[i], i)); | ||
|
|
||
| std::sort(m_cases.begin(), m_cases.end()); | ||
| if (type == Int32 || type == IntPtr) { |
There was a problem hiding this comment.
Nit: I would add a isCheckRuns() and use that.
| while (wasmSwitch.advance(m_jit)) { | ||
| unsigned value = wasmSwitch.caseValue(); | ||
| unsigned index = wasmSwitch.caseIndex(); | ||
| UNUSED_VARIABLE(value); |
There was a problem hiding this comment.
Yeah, just get rid of value
| #endif | ||
| build(0, false, m_cases.size()); | ||
| } else { | ||
| m_cases.reserveInitialCapacity(cases.size()); |
There was a problem hiding this comment.
cases are expected to be sorted right? Can we add an ASSERT?
|
Sorry for the noise, I didn’t notice this PR when I picked up the bug. It was unassigned on Bugzilla and I only saw the open work after I had already opened a new patch. I posted a separate attempt here: #69487 At a high level it tries the same optimization (collapse runs of the same
Happy to close #69487 if you’d rather continue this one, help review / contribute to this PR, or fold any of those bits in here if useful. |
d39f470
d39f470