Commit 45d75bca authored by titzer's avatar titzer Committed by Commit bot

[turbofan] Handle dead diamonds in scheduling and add a test.

The background here is that graphs generated from WASM are not trimmed.
That means there can be some floating control diamonds that are not
reachable from end. An assertion in the scheduler for phis from floating
diamonds checks that the use edge in this situation is the control edge,
but in general, any edge could cause this.

Scheduling still works without this assertion. The longer term fix
is to either trim the graphs (more compile time overhead for WASM)
or improve the scheduler's handling of dead code in the graph. Currently
it does not schedule dead code but the potential use positions of
dead code are used in the computation of the common dominator of uses. We could
recognize dead nodes in PrepareUses() and check in GetBlockForUse()
as per TODO.

R=bradnelson@chromium.org, mstarzinger@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1846933002

Cr-Commit-Position: refs/heads/master@{#35245}
parent eebdee8e
......@@ -1538,6 +1538,8 @@ class ScheduleLateNodeVisitor {
}
BasicBlock* GetBlockForUse(Edge edge) {
// TODO(titzer): ignore uses from dead nodes (not visited in PrepareUses()).
// Dead uses only occur if the graph is not trimmed before scheduling.
Node* use = edge.from();
if (IrOpcode::IsPhiOpcode(use->opcode())) {
// If the use is from a coupled (i.e. floating) phi, compute the common
......@@ -1545,7 +1547,8 @@ class ScheduleLateNodeVisitor {
if (scheduler_->GetPlacement(use) == Scheduler::kCoupled) {
TRACE(" inspecting uses of coupled #%d:%s\n", use->id(),
use->op()->mnemonic());
DCHECK_EQ(edge.to(), NodeProperties::GetControlInput(use));
// TODO(titzer): reenable once above TODO is addressed.
// DCHECK_EQ(edge.to(), NodeProperties::GetControlInput(use));
return GetCommonDominatorOfUses(use);
}
// If the use is from a fixed (i.e. non-floating) phi, we use the
......
......@@ -2818,3 +2818,15 @@ TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); }
TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); }
TEST(Run_WASM_Int32RemS_dead) {
WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32());
BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_ZERO);
const int32_t kMin = std::numeric_limits<int32_t>::min();
CHECK_EQ(0, r.Call(133, 100));
CHECK_EQ(0, r.Call(kMin, -1));
CHECK_EQ(0, r.Call(0, 1));
CHECK_TRAP(r.Call(100, 0));
CHECK_TRAP(r.Call(-1001, 0));
CHECK_TRAP(r.Call(kMin, 0));
}
......@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler/schedule.h"
#include "src/compiler/access-builder.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/graph.h"
#include "src/compiler/graph-visualizer.h"
#include "src/compiler/graph.h"
#include "src/compiler/js-operator.h"
#include "src/compiler/node.h"
#include "src/compiler/opcodes.h"
#include "src/compiler/operator.h"
#include "src/compiler/schedule.h"
#include "src/compiler/scheduler.h"
#include "src/compiler/simplified-operator.h"
#include "src/compiler/source-position.h"
......@@ -136,6 +136,51 @@ TARGET_TEST_F(SchedulerTest, FloatingDiamond1) {
ComputeAndVerifySchedule(13);
}
TARGET_TEST_F(SchedulerTest, FloatingDeadDiamond1) {
Node* start = graph()->NewNode(common()->Start(1));
graph()->SetStart(start);
Node* p0 = graph()->NewNode(common()->Parameter(0), start);
Node* d1 = CreateDiamond(graph(), common(), p0);
USE(d1);
Node* ret = graph()->NewNode(common()->Return(), p0, start, start);
Node* end = graph()->NewNode(common()->End(1), ret);
graph()->SetEnd(end);
ComputeAndVerifySchedule(4);
}
TARGET_TEST_F(SchedulerTest, FloatingDeadDiamond2) {
Graph* g = graph();
Node* start = g->NewNode(common()->Start(1));
g->SetStart(start);
Node* n1 = g->NewNode(common()->Parameter(1), start);
Node* n2 = g->NewNode(common()->Branch(), n1, start);
Node* n3 = g->NewNode(common()->IfTrue(), n2);
Node* n4 = g->NewNode(common()->IfFalse(), n2);
Node* n5 = g->NewNode(common()->Int32Constant(-100));
Node* n6 = g->NewNode(common()->Return(), n5, start, n4);
Node* n7 = g->NewNode(common()->Int32Constant(0));
Node* n8 = g->NewNode(common()->Return(), n7, start, n3);
Node* n9 = g->NewNode(common()->End(2), n6, n8);
// Dead nodes
Node* n10 = g->NewNode(common()->Branch(), n1, n3);
Node* n11 = g->NewNode(common()->IfTrue(), n10);
Node* n12 = g->NewNode(common()->IfFalse(), n10);
Node* n13 = g->NewNode(common()->Merge(2), n11, n12);
Node* n14 =
g->NewNode(common()->Phi(MachineRepresentation::kWord32, 2), n1, n7, n13);
USE(n14);
g->SetEnd(n9);
ComputeAndVerifySchedule(10);
}
TARGET_TEST_F(SchedulerTest, FloatingDiamond2) {
Node* start = graph()->NewNode(common()->Start(2));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment