Commit 338f90a6 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Fix effect chain in {BuildChangeTaggedToFloat64}

1) Refactor code using the {Diamond} helper.
2) Fix the effect chain to include the loads in that method.

R=mstarzinger@chromium.org

Change-Id: I8583b46c1c56b226842248f3c1763c7565ef3797
Reviewed-on: https://chromium-review.googlesource.com/1128864
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54332}
parent c4323e08
...@@ -4083,17 +4083,15 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -4083,17 +4083,15 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
BuildChangeSmiToInt32(value)); BuildChangeSmiToInt32(value));
} }
Node* BuildTestNotSmi(Node* value) { Node* BuildTestHeapObject(Node* value) {
STATIC_ASSERT(kSmiTag == 0);
STATIC_ASSERT(kSmiTagMask == 1);
return graph()->NewNode(mcgraph()->machine()->WordAnd(), value, return graph()->NewNode(mcgraph()->machine()->WordAnd(), value,
mcgraph()->IntPtrConstant(kSmiTagMask)); mcgraph()->IntPtrConstant(kHeapObjectTag));
} }
Node* BuildLoadHeapNumberValue(Node* value, Node* control) { Node* BuildLoadHeapNumberValue(Node* value) {
return graph()->NewNode(mcgraph()->machine()->Load(MachineType::Float64()), return *effect_ = graph()->NewNode(
value, BuildHeapNumberValueIndexConstant(), mcgraph()->machine()->Load(MachineType::Float64()), value,
graph()->start(), control); BuildHeapNumberValueIndexConstant(), *effect_, *control_);
} }
Node* BuildHeapNumberValueIndexConstant() { Node* BuildHeapNumberValueIndexConstant() {
...@@ -4259,42 +4257,53 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -4259,42 +4257,53 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
MachineOperatorBuilder* machine = mcgraph()->machine(); MachineOperatorBuilder* machine = mcgraph()->machine();
CommonOperatorBuilder* common = mcgraph()->common(); CommonOperatorBuilder* common = mcgraph()->common();
Node* check = BuildTestNotSmi(value); // Implement the following decision tree:
Node* branch = graph()->NewNode(common->Branch(BranchHint::kFalse), check, // heap object?
graph()->start()); // ├─ true: undefined?
// │ ├─ true: f64 const
// │ └─ false: load heap number value
// └─ false: smi to float64
Node* if_not_smi = graph()->NewNode(common->IfTrue(), branch); Node* check_heap_object = BuildTestHeapObject(value);
Diamond is_heap_object(graph(), common, check_heap_object,
BranchHint::kFalse);
is_heap_object.Chain(*control_);
Node* vnot_smi; *control_ = is_heap_object.if_true;
Node* undefined_node = Node* orig_effect = *effect_;
Node* undefined_node = *effect_ =
LOAD_INSTANCE_FIELD(UndefinedValue, MachineType::TaggedPointer()); LOAD_INSTANCE_FIELD(UndefinedValue, MachineType::TaggedPointer());
Node* check_undefined = Node* check_undefined =
graph()->NewNode(machine->WordEqual(), value, undefined_node); graph()->NewNode(machine->WordEqual(), value, undefined_node);
Node* branch_undefined = graph()->NewNode( Node* effect_tagged = *effect_;
common->Branch(BranchHint::kFalse), check_undefined, if_not_smi);
Diamond is_undefined(graph(), common, check_undefined, BranchHint::kFalse);
is_undefined.Nest(is_heap_object, true);
Node* if_undefined = graph()->NewNode(common->IfTrue(), branch_undefined); *control_ = is_undefined.if_false;
Node* vheap_number = BuildLoadHeapNumberValue(value);
Node* effect_undefined = *effect_;
*control_ = is_undefined.merge;
Node* vundefined = Node* vundefined =
mcgraph()->Float64Constant(std::numeric_limits<double>::quiet_NaN()); mcgraph()->Float64Constant(std::numeric_limits<double>::quiet_NaN());
Node* vtagged = is_undefined.Phi(MachineRepresentation::kFloat64,
vundefined, vheap_number);
Node* if_not_undefined = effect_tagged =
graph()->NewNode(common->IfFalse(), branch_undefined); graph()->NewNode(mcgraph()->common()->EffectPhi(2), effect_tagged,
Node* vheap_number = BuildLoadHeapNumberValue(value, if_not_undefined); effect_undefined, is_undefined.merge);
if_not_smi =
graph()->NewNode(common->Merge(2), if_undefined, if_not_undefined);
vnot_smi = graph()->NewNode(common->Phi(MachineRepresentation::kFloat64, 2),
vundefined, vheap_number, if_not_smi);
Node* if_smi = graph()->NewNode(common->IfFalse(), branch); // If input is Smi: just convert to float64.
Node* vfrom_smi = BuildChangeSmiToFloat64(value); Node* vfrom_smi = BuildChangeSmiToFloat64(value);
Node* merge = graph()->NewNode(common->Merge(2), if_not_smi, if_smi); *control_ = is_heap_object.merge;
Node* phi = *effect_ =
graph()->NewNode(common->Phi(MachineRepresentation::kFloat64, 2), graph()->NewNode(mcgraph()->common()->EffectPhi(2), effect_tagged,
vnot_smi, vfrom_smi, merge); orig_effect, is_heap_object.merge);
return is_heap_object.Phi(MachineRepresentation::kFloat64, vtagged,
return phi; vfrom_smi);
} }
Node* ToJS(Node* node, wasm::ValueType type) { Node* ToJS(Node* node, wasm::ValueType type) {
......
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