[wasm][turbofan] Remove niche optimization

The optimization of a trap inside a branch is being removed. Since it
does not speed-up non-trapping programs, and it is quite narrow, it is
not worth the maintenance cost.

Bug: chromium:1338947, chromium:1338950, chromium:1339153
Change-Id: I5b3f52e2b11d4c5113dd44fe23c14d74124a15f6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3721617
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81357}
This commit is contained in:
Manos Koukoutos 2022-06-24 14:46:47 +00:00 committed by V8 LUCI CQ
parent 5ece5258ef
commit 930f3ffb73
2 changed files with 26 additions and 65 deletions

View File

@ -175,71 +175,8 @@ Reduction BranchElimination::ReduceTrapConditional(Node* node) {
if (branch_condition.IsSet()) {
bool condition_value = branch_condition.is_true;
if (condition_value == trapping_condition) {
// Special case: Trap directly below an IfTrue/IfFalse without sibling
// nodes. Replace the branch with the trap.
//
// condition effect control
// | \ / \ /
// | X X
// | / \ / \
// | / Branch \
// | / / | \
// | / IfTrue IfFalse \
// | | / | \
// | | / control2 effect2
// TrapIf
// | \
// control1 effect1
//
// --- becomes ---
//
// condition effect control
// \ | /
// \ | /
// TrapIf
// / \
// control2 effect2
//
// (and symmetrically for TrapUnless.)
if (((trapping_condition &&
control_input->opcode() == IrOpcode::kIfTrue) ||
(!trapping_condition &&
control_input->opcode() == IrOpcode::kIfFalse)) &&
control_input->UseCount() == 1) {
Node* branch = NodeProperties::GetControlInput(control_input);
DCHECK_EQ(branch->opcode(), IrOpcode::kBranch);
if (condition == NodeProperties::GetValueInput(branch, 0)) {
Node* other_if_branch = nullptr;
for (Node* use : branch->uses()) {
if (use != control_input) other_if_branch = use;
}
DCHECK_NOT_NULL(other_if_branch);
Node* effect_input = NodeProperties::GetEffectInput(node);
Node* other_effect = nullptr;
for (Node* use : effect_input->uses()) {
if (use != node) {
DCHECK_EQ(other_effect, nullptr);
other_effect = use;
}
}
DCHECK_NOT_NULL(other_effect);
node->ReplaceInput(NodeProperties::FirstControlIndex(node),
NodeProperties::GetControlInput(branch));
ReplaceWithValue(node, dead(), dead(), dead());
ReplaceWithValue(other_if_branch, dead(), dead(), node);
other_effect->ReplaceInput(
NodeProperties::FirstEffectIndex(other_effect), node);
other_if_branch->Kill();
control_input->Kill();
branch->Kill();
return Changed(node);
}
}
// General case: This will always trap. Mark its outputs as dead and
// connect it to graph()->end().
// This will always trap. Mark its outputs as dead and connect it to
// graph()->end().
ReplaceWithValue(node, dead(), dead(), dead());
Node* control = graph()->NewNode(common()->Throw(), node, node);
NodeProperties::MergeControlToEnd(graph(), common(), control);

View File

@ -0,0 +1,24 @@
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --no-liftoff
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
builder.addFunction("main", kSig_i_iii)
.addBody([kExprLoop, kWasmI32,
...wasmI32Const(10),
...wasmI32Const(10),
kExprLocalGet, 0,
kExprLocalTee, 1,
kExprCallFunction, 0,
kExprLocalGet, 1,
kExprLocalGet, 0,
kExprBrIf, 0,
kExprI32DivS,
kExprEnd]);
builder.instantiate();