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
10 changes: 3 additions & 7 deletions src/coreclr/jit/codegenwasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,10 @@ void CodeGen::genTableBasedSwitch(GenTree* treeNode)
BBswtDesc* const desc = block->GetSwitchTargets();
unsigned const caseCount = desc->GetCaseCount();

// TODO-WASM: update lowering not to peel off the default
// We don't expect degenerate or default-less switches
//
assert(!desc->HasDefaultCase());

if (caseCount == 0)
{
return;
}
assert(caseCount > 0);
assert(desc->HasDefaultCase());

GetEmitter()->emitIns_I(INS_br_table, EA_4BYTE, caseCount);

Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/jit/fgopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,11 @@ bool Compiler::fgOptimizeSwitchBranches(BasicBlock* block)
blockRange = &LIR::AsRange(block);
switchTree = blockRange->LastNode();

#ifdef TARGET_WASM
assert(switchTree->OperIs(GT_SWITCH));
#else
assert(switchTree->OperIs(GT_SWITCH_TABLE));
#endif
}
else
{
Expand Down
10 changes: 3 additions & 7 deletions src/coreclr/jit/fgwasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,6 @@ PhaseStatus Compiler::fgWasmControlFlow()
}

// Branch to next needs no block, unless this is a switch
// (eventually when we leave the default on the switch we can remove this).
//
if ((succNum == (cursor + 1)) && !block->KindIs(BBJ_SWITCH))
{
Expand Down Expand Up @@ -1623,13 +1622,10 @@ void Compiler::fgDumpWasmControlFlow()
BBswtDesc* const desc = block->GetSwitchTargets();
unsigned const caseCount = desc->GetCaseCount();

// BR_TABLE supports a default case, so we need to ensure
// that wasm lower does not remove it.
// BR_TABLE supports a default case.
// Wasm lower should not remove it.
//
// For now, we expect non-wasm lower has made the default case check explicit
// and so our BR_TABLE emission is deficient.
//
assert(!desc->HasDefaultCase());
assert(desc->HasDefaultCase());

if (caseCount == 0)
{
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,12 @@ GenTree* Lowering::LowerSwitch(GenTree* node)

noway_assert(jumpCnt >= 2);

#ifdef TARGET_WASM
// Wasm's br_table maps exactly to GT_SWITCH
//
return node->gtNext;
#endif // TARGET_WASM

// Spill the argument to the switch node into a local so that it can be used later.
LIR::Use use(switchBBRange, &(node->AsOp()->gtOp1), node);
ReplaceWithLclVar(use);
Expand Down
Loading