Skip to content

Commit 9299aa2

Browse files
Ilya YanokCommit Bot
Ilya Yanok
authored and
Commit Bot
committed
Revert "[vm/compiler] Optimize switch statements"
This reverts commit f522812. Reason for revert: causes a VM crash, see b/242964932 (the test is also publicly available at https://github.com/simolus3/drift/blob/93fb0da38a5f33c8db289bfde696b0ca3d401b7f/drift_dev/test/analyzer/sql_queries/query_analyzer_test.dart#L8) Original change's description: > [vm/compiler] Optimize switch statements > > Switch statements that either contain only integers or only enum values of the same type can be optimized. > > Depending on the number of switch expressions and the number of holes that the range of switch expressions contains, either a binary search or a jump table is used. > > TEST=runtime/test/vm/dart{,_2}/optimized_switch > TEST=tests/language{,_2}/switch > > Fixes: #49585 > > Co-authored-by: Gabriel Terwesten [email protected] > > Change-Id: I62dcdb7843107f03de7e468c60b4db52ec78f676 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253787 > Reviewed-by: Alexander Markov <[email protected]> > Commit-Queue: Alexander Markov <[email protected]> [email protected],[email protected],[email protected] Change-Id: I8c673ea70e7ed91dffb3674e7dcb4aaa0611e978 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/255258 Reviewed-by: Slava Egorov <[email protected]> Reviewed-by: Ilya Yanok <[email protected]> Commit-Queue: Slava Egorov <[email protected]>
1 parent 1611fe6 commit 9299aa2

30 files changed

+130
-2193
lines changed

runtime/tests/vm/dart/optimized_switch_test.dart

Lines changed: 0 additions & 577 deletions
This file was deleted.

runtime/tests/vm/dart_2/optimized_switch_test.dart

Lines changed: 0 additions & 579 deletions
This file was deleted.

runtime/vm/compiler/backend/branch_optimizer.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,8 @@ void IfConverter::Simplify(FlowGraph* flow_graph) {
284284
BranchInstr* branch = pred->last_instruction()->AsBranch();
285285

286286
if (branch == nullptr) {
287-
// There is no "B_pred" block, or the block is the IndirectGoto
288-
// of a switch that uses it as a jump table.
289-
ASSERT(pred->last_instruction()->IsGraphEntry() ||
290-
pred->last_instruction()->IsIndirectGoto());
287+
// There is no "B_pred" block.
288+
ASSERT(pred->last_instruction()->IsGraphEntry());
291289
continue;
292290
}
293291

runtime/vm/compiler/backend/constant_propagator.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,8 @@ void ConstantPropagator::VisitGoto(GotoInstr* instr) {
232232
}
233233

234234
void ConstantPropagator::VisitIndirectGoto(IndirectGotoInstr* instr) {
235-
if (reachable_->Contains(instr->GetBlock()->preorder_number())) {
236-
for (intptr_t i = 0; i < instr->SuccessorCount(); i++) {
237-
SetReachable(instr->SuccessorAt(i));
238-
}
235+
for (intptr_t i = 0; i < instr->SuccessorCount(); i++) {
236+
SetReachable(instr->SuccessorAt(i));
239237
}
240238
}
241239

@@ -1504,11 +1502,7 @@ static bool HasPhis(BlockEntryInstr* block) {
15041502
}
15051503

15061504
static bool IsEmptyBlock(BlockEntryInstr* block) {
1507-
// A block containing a goto to itself forms an infinite loop.
1508-
// We don't consider this an empty block to handle the edge-case where code
1509-
// reduces to an infinite loop.
1510-
return block->next()->IsGoto() &&
1511-
block->next()->AsGoto()->successor() != block && !HasPhis(block) &&
1505+
return block->next()->IsGoto() && !HasPhis(block) &&
15121506
!block->IsIndirectEntry();
15131507
}
15141508

0 commit comments

Comments
 (0)