Commit f30af0bf authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Skip unneeded check for undefined value

After calling the ToNumber builtin, we are guaranteed to get either a
Smi or a HeapNumber. Thus we can skip the check for undefined, which
removes quite some unneeded code from wasm-to-js and js-to-wasm
wrappers.

R=ahaas@chromium.org

Bug: v8:10070
Change-Id: I0e2ad19f1575fb6979222e324fbdb71aaf85e6fd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1962279
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65520}
parent 288aaef9
...@@ -5309,6 +5309,8 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -5309,6 +5309,8 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
return pos; return pos;
} }
// Calls the ECMAScript ToNumber operation on {node}. Returns a {Smi} or
// {HeapNumber}.
Node* BuildJavaScriptToNumber(Node* node, Node* js_context) { Node* BuildJavaScriptToNumber(Node* node, Node* js_context) {
auto call_descriptor = Linkage::GetStubCallDescriptor( auto call_descriptor = Linkage::GetStubCallDescriptor(
mcgraph()->zone(), TypeConversionDescriptor{}, 0, mcgraph()->zone(), TypeConversionDescriptor{}, 0,
...@@ -5325,52 +5327,27 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -5325,52 +5327,27 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
return result; return result;
} }
Node* BuildChangeTaggedToFloat64(Node* value) { // Converts a number (Smi or HeapNumber) to float64.
MachineOperatorBuilder* machine = mcgraph()->machine(); Node* BuildChangeNumberToFloat64(Node* value) {
CommonOperatorBuilder* common = mcgraph()->common(); // If the input is a HeapNumber, we load the value from it.
// Implement the following decision tree:
// heap object?
// ├─ true: undefined?
// │ ├─ true: f64 const
// │ └─ false: load heap number value
// └─ false: smi to float64
Node* check_heap_object = BuildTestHeapObject(value); Node* check_heap_object = BuildTestHeapObject(value);
Diamond is_heap_object(graph(), common, check_heap_object, Diamond is_heapnumber(graph(), mcgraph()->common(), check_heap_object,
BranchHint::kFalse); BranchHint::kFalse);
is_heap_object.Chain(Control()); is_heapnumber.Chain(Control());
SetControl(is_heap_object.if_true);
Node* orig_effect = Effect();
Node* undefined_node = BuildLoadUndefinedValueFromInstance();
Node* check_undefined =
graph()->NewNode(machine->WordEqual(), value, undefined_node);
Node* effect_tagged = Effect();
Diamond is_undefined(graph(), common, check_undefined, BranchHint::kFalse);
is_undefined.Nest(is_heap_object, true);
SetControl(is_undefined.if_false);
Node* vheap_number = BuildLoadHeapNumberValue(value);
Node* effect_undefined = Effect();
SetControl(is_undefined.merge); SetControl(is_heapnumber.if_true);
Node* vundefined = Node* effect_orig = Effect();
mcgraph()->Float64Constant(std::numeric_limits<double>::quiet_NaN()); Node* v_heapnumber = BuildLoadHeapNumberValue(value);
Node* vtagged = is_undefined.Phi(MachineRepresentation::kFloat64, Node* effect_heapnumber = Effect();
vundefined, vheap_number);
effect_tagged = is_undefined.EffectPhi(effect_tagged, effect_undefined); SetControl(is_heapnumber.merge);
// If the input is Smi, just convert to float64.
Node* v_smi = BuildChangeSmiToFloat64(value);
// If input is Smi: just convert to float64. SetEffect(is_heapnumber.EffectPhi(effect_heapnumber, effect_orig));
Node* vfrom_smi = BuildChangeSmiToFloat64(value);
SetControl(is_heap_object.merge); return is_heapnumber.Phi(MachineRepresentation::kFloat64, v_heapnumber,
SetEffect(is_heap_object.EffectPhi(effect_tagged, orig_effect)); v_smi);
return is_heap_object.Phi(MachineRepresentation::kFloat64, vtagged,
vfrom_smi);
} }
Node* ToJS(Node* node, wasm::ValueType type) { Node* ToJS(Node* node, wasm::ValueType type) {
...@@ -5475,7 +5452,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -5475,7 +5452,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
num = BuildJavaScriptToNumber(node, js_context); num = BuildJavaScriptToNumber(node, js_context);
// Change representation. // Change representation.
num = BuildChangeTaggedToFloat64(num); num = BuildChangeNumberToFloat64(num);
} }
switch (type) { switch (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