Changeset 258965 in webkit


Ignore:
Timestamp:
Mar 24, 2020, 5:51:44 PM (6 years ago)
Author:
Tadeu Zagallo
Message:

LLIntGenerator must link switch jumps to otherwise redundant labels
https://bugs.webkit.org/show_bug.cgi?id=209333
<rdar://problem/60827987>

Reviewed by Saam Barati.

JSTests:

  • wasm/stress/terminal-jump-switch-target.js: Added.

Source/JavaScriptCore:

The LLIntGenerator optimizes jumps at the end of blocks. It does so when a block ends, by checking if
the last instruction emitted was a jump, if it pointed to the end of the current block and if it was
the only jump that pointed there. If all those conditions are satisfied, the jump is removed and it's
not necessary to emit the label at the end of block, since the only jump that pointed to it was removed.
However, switches (br_table) are handled specially by the LLIntGenerator and therefore are not counted
in Label::unresolvedJumps, which was used to check whether we could skip emitting the label.
The end result is that we might skip linking a switch jump if it points to a block that ends with a jump.

  • wasm/WasmLLIntGenerator.cpp:

(JSC::Wasm::LLIntGenerator::addEndToUnreachable):
(JSC::Wasm::LLIntGenerator::linkSwitchTargets):
(JSC::GenericLabel<Wasm::GeneratorTraits>::setLocation):

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r258963 r258965  
     12020-03-24  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        LLIntGenerator must link switch jumps to otherwise redundant labels
     4        https://bugs.webkit.org/show_bug.cgi?id=209333
     5        <rdar://problem/60827987>
     6
     7        Reviewed by Saam Barati.
     8
     9        * wasm/stress/terminal-jump-switch-target.js: Added.
     10
    1112020-03-24  Alexey Shvayka  <shvaikalesh@gmail.com>
    212
  • trunk/Source/JavaScriptCore/ChangeLog

    r258964 r258965  
     12020-03-24  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        LLIntGenerator must link switch jumps to otherwise redundant labels
     4        https://bugs.webkit.org/show_bug.cgi?id=209333
     5        <rdar://problem/60827987>
     6
     7        Reviewed by Saam Barati.
     8
     9        The LLIntGenerator optimizes jumps at the end of blocks. It does so when a block ends, by checking if
     10        the last instruction emitted was a jump, if it pointed to the end of the current block and if it was
     11        the only jump that pointed there. If all those conditions are satisfied, the jump is removed and it's
     12        not necessary to emit the label at the end of block, since the only jump that pointed to it was removed.
     13        However, switches (br_table) are handled specially by the LLIntGenerator and therefore are not counted
     14        in Label::unresolvedJumps, which was used to check whether we could skip emitting the label.
     15        The end result is that we might skip linking a switch jump if it points to a block that ends with a jump.
     16
     17
     18        * wasm/WasmLLIntGenerator.cpp:
     19        (JSC::Wasm::LLIntGenerator::addEndToUnreachable):
     20        (JSC::Wasm::LLIntGenerator::linkSwitchTargets):
     21        (JSC::GenericLabel<Wasm::GeneratorTraits>::setLocation):
     22
    1232020-03-24  Saam Barati  <sbarati@apple.com>
    224
  • trunk/Source/JavaScriptCore/wasm/WasmLLIntGenerator.cpp

    r254735 r258965  
    260260    LLIntCallInformation callInformationForCaller(const Signature&);
    261261    Vector<VirtualRegister, 2> callInformationForCallee(const Signature&);
     262    void linkSwitchTargets(Label&, unsigned location);
    262263
    263264    VirtualRegister virtualRegisterForWasmLocal(uint32_t index)
     
    992993
    993994    if (m_lastOpcodeID == wasm_jmp && data.m_continuation->unresolvedJumps().size() == 1 && data.m_continuation->unresolvedJumps()[0] == static_cast<int>(m_lastInstruction.offset())) {
     995        linkSwitchTargets(*data.m_continuation, m_lastInstruction.offset());
    994996        m_lastOpcodeID = wasm_unreachable;
    995997        m_writer.rewind(m_lastInstruction);
     
    12111213}
    12121214
     1215void LLIntGenerator::linkSwitchTargets(Label& label, unsigned location)
     1216{
     1217    auto it = m_switches.find(&label);
     1218    if (it != m_switches.end()) {
     1219        for (const auto& entry : it->value) {
     1220            ASSERT(!*entry.jumpTarget);
     1221            *entry.jumpTarget = location - entry.offset;
     1222        }
     1223        m_switches.remove(it);
     1224    }
     1225}
     1226
    12131227}
    12141228
     
    12211235
    12221236    Wasm::LLIntGenerator* llintGenerator = static_cast<Wasm::LLIntGenerator*>(&generator);
    1223 
    1224     auto it = llintGenerator->m_switches.find(this);
    1225     if (it != llintGenerator->m_switches.end()) {
    1226         for (const auto& entry : it->value) {
    1227             ASSERT(!*entry.jumpTarget);
    1228             *entry.jumpTarget = m_location - entry.offset;
    1229         }
    1230         llintGenerator->m_switches.remove(it);
    1231     }
    1232 
     1237    llintGenerator->linkSwitchTargets(*this, m_location);
    12331238
    12341239    for (auto offset : m_unresolvedJumps) {
Note: See TracChangeset for help on using the changeset viewer.