Commit 3ebb74e0 authored by ahaas's avatar ahaas Committed by Commit bot

[wasm] Use branch hint for the -1 check in I(32|64)Div.

R=titzer@chromium.org

Review-Url: https://codereview.chromium.org/2413343002
Cr-Commit-Position: refs/heads/master@{#40400}
parent 1b4e0fca
......@@ -990,16 +990,36 @@ Node* WasmGraphBuilder::HeapConstant(Handle<HeapObject> value) {
return jsgraph()->HeapConstant(value);
}
Node* WasmGraphBuilder::Branch(Node* cond, Node** true_node,
Node** false_node) {
namespace {
Node* Branch(JSGraph* jsgraph, Node* cond, Node** true_node, Node** false_node,
Node* control, BranchHint hint) {
DCHECK_NOT_NULL(cond);
DCHECK_NOT_NULL(*control_);
DCHECK_NOT_NULL(control);
Node* branch =
graph()->NewNode(jsgraph()->common()->Branch(), cond, *control_);
*true_node = graph()->NewNode(jsgraph()->common()->IfTrue(), branch);
*false_node = graph()->NewNode(jsgraph()->common()->IfFalse(), branch);
jsgraph->graph()->NewNode(jsgraph->common()->Branch(hint), cond, control);
*true_node = jsgraph->graph()->NewNode(jsgraph->common()->IfTrue(), branch);
*false_node = jsgraph->graph()->NewNode(jsgraph->common()->IfFalse(), branch);
return branch;
}
} // namespace
Node* WasmGraphBuilder::BranchNoHint(Node* cond, Node** true_node,
Node** false_node) {
return Branch(jsgraph(), cond, true_node, false_node, *control_,
BranchHint::kNone);
}
Node* WasmGraphBuilder::BranchExpectTrue(Node* cond, Node** true_node,
Node** false_node) {
return Branch(jsgraph(), cond, true_node, false_node, *control_,
BranchHint::kTrue);
}
Node* WasmGraphBuilder::BranchExpectFalse(Node* cond, Node** true_node,
Node** false_node) {
return Branch(jsgraph(), cond, true_node, false_node, *control_,
BranchHint::kFalse);
}
Node* WasmGraphBuilder::Switch(unsigned count, Node* key) {
return graph()->NewNode(jsgraph()->common()->Switch(count), key, *control_);
......@@ -1758,7 +1778,7 @@ Node* WasmGraphBuilder::Catch(Node* input, wasm::WasmCodePosition position) {
Node* is_smi;
Node* is_heap;
Branch(BuildTestNotSmi(value), &is_heap, &is_smi);
BranchExpectFalse(BuildTestNotSmi(value), &is_heap, &is_smi);
// is_smi
Node* smi_i32 = BuildChangeSmiToInt32(value);
......@@ -1798,7 +1818,7 @@ Node* WasmGraphBuilder::BuildI32DivS(Node* left, Node* right,
Node* before = *control_;
Node* denom_is_m1;
Node* denom_is_not_m1;
Branch(
BranchExpectFalse(
graph()->NewNode(m->Word32Equal(), right, jsgraph()->Int32Constant(-1)),
&denom_is_m1, &denom_is_not_m1);
*control_ = denom_is_m1;
......@@ -1940,9 +1960,9 @@ Node* WasmGraphBuilder::BuildI64DivS(Node* left, Node* right,
Node* before = *control_;
Node* denom_is_m1;
Node* denom_is_not_m1;
Branch(graph()->NewNode(jsgraph()->machine()->Word64Equal(), right,
jsgraph()->Int64Constant(-1)),
&denom_is_m1, &denom_is_not_m1);
BranchExpectFalse(graph()->NewNode(jsgraph()->machine()->Word64Equal(), right,
jsgraph()->Int64Constant(-1)),
&denom_is_m1, &denom_is_not_m1);
*control_ = denom_is_m1;
trap_->TrapIfEq64(wasm::kTrapDivUnrepresentable, left,
std::numeric_limits<int64_t>::min(), position);
......
......@@ -148,7 +148,10 @@ class WasmGraphBuilder {
//-----------------------------------------------------------------------
// Operations that read and/or write {control} and {effect}.
//-----------------------------------------------------------------------
Node* Branch(Node* cond, Node** true_node, Node** false_node);
Node* BranchNoHint(Node* cond, Node** true_node, Node** false_node);
Node* BranchExpectTrue(Node* cond, Node** true_node, Node** false_node);
Node* BranchExpectFalse(Node* cond, Node** true_node, Node** false_node);
Node* Switch(unsigned count, Node* key);
Node* IfValue(int32_t value, Node* sw);
Node* IfDefault(Node* sw);
......
......@@ -698,7 +698,7 @@ class WasmFullDecoder : public WasmDecoder {
Value cond = Pop(0, kAstI32);
TFNode* if_true = nullptr;
TFNode* if_false = nullptr;
BUILD(Branch, cond.node, &if_true, &if_false);
BUILD(BranchNoHint, cond.node, &if_true, &if_false);
SsaEnv* end_env = ssa_env_;
SsaEnv* false_env = Split(ssa_env_);
false_env->control = if_false;
......@@ -816,7 +816,7 @@ class WasmFullDecoder : public WasmDecoder {
DCHECK(fval.type != kAstEnd);
DCHECK(cond.type != kAstEnd);
TFNode* controls[2];
builder_->Branch(cond.node, &controls[0], &controls[1]);
builder_->BranchNoHint(cond.node, &controls[0], &controls[1]);
TFNode* merge = builder_->Merge(2, controls);
TFNode* vals[2] = {tval.node, fval.node};
TFNode* phi = builder_->Phi(tval.type, 2, vals, merge);
......@@ -843,7 +843,7 @@ class WasmFullDecoder : public WasmDecoder {
SsaEnv* fenv = ssa_env_;
SsaEnv* tenv = Split(fenv);
fenv->SetNotMerged();
BUILD(Branch, cond.node, &tenv->control, &fenv->control);
BUILD(BranchNoHint, cond.node, &tenv->control, &fenv->control);
ssa_env_ = tenv;
BreakTo(operand.depth);
ssa_env_ = fenv;
......
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