Commit acd674db authored by ishell's avatar ishell Committed by Commit bot

[crankshaft] Use canonical nan_value or minus_zero_value objects instead of...

[crankshaft] Use canonical nan_value or minus_zero_value objects instead of constant heap numbers with NaN or -0.0 values.

BUG=chromium:625547

Review-Url: https://codereview.chromium.org/2115413002
Cr-Commit-Position: refs/heads/master@{#37495}
parent a21725c5
......@@ -2172,6 +2172,32 @@ HConstant::HConstant(Handle<Object> object, Representation r)
BooleanValueField::encode(object->BooleanValue()) |
IsUndetectableField::encode(false) | IsCallableField::encode(false) |
InstanceTypeField::encode(kUnknownInstanceType)) {
if (object->IsNumber()) {
double n = object->Number();
bool has_int32_value = IsInteger32(n);
bit_field_ = HasInt32ValueField::update(bit_field_, has_int32_value);
int32_value_ = DoubleToInt32(n);
bit_field_ = HasSmiValueField::update(
bit_field_, has_int32_value && Smi::IsValid(int32_value_));
if (std::isnan(n)) {
double_value_ = std::numeric_limits<double>::quiet_NaN();
// Canonicalize object with NaN value.
DCHECK(object->IsHeapObject()); // NaN can't be a Smi.
Isolate* isolate = HeapObject::cast(*object)->GetIsolate();
object = isolate->factory()->nan_value();
object_ = Unique<Object>::CreateUninitialized(object);
} else {
double_value_ = n;
// Canonicalize object with -0.0 value.
if (bit_cast<int64_t>(n) == bit_cast<int64_t>(-0.0)) {
DCHECK(object->IsHeapObject()); // -0.0 can't be a Smi.
Isolate* isolate = HeapObject::cast(*object)->GetIsolate();
object = isolate->factory()->minus_zero_value();
object_ = Unique<Object>::CreateUninitialized(object);
}
}
bit_field_ = HasDoubleValueField::update(bit_field_, true);
}
if (object->IsHeapObject()) {
Handle<HeapObject> heap_object = Handle<HeapObject>::cast(object);
Isolate* isolate = heap_object->GetIsolate();
......@@ -2187,20 +2213,6 @@ HConstant::HConstant(Handle<Object> object, Representation r)
bit_field_,
HasMapValue() && Handle<Map>::cast(heap_object)->is_stable());
}
if (object->IsNumber()) {
double n = object->Number();
bool has_int32_value = IsInteger32(n);
bit_field_ = HasInt32ValueField::update(bit_field_, has_int32_value);
int32_value_ = DoubleToInt32(n);
bit_field_ = HasSmiValueField::update(
bit_field_, has_int32_value && Smi::IsValid(int32_value_));
if (std::isnan(n)) {
double_value_ = std::numeric_limits<double>::quiet_NaN();
} else {
double_value_ = n;
}
bit_field_ = HasDoubleValueField::update(bit_field_, true);
}
Initialize(r);
}
......
// Copyright 2016 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: --allow-natives-syntax --expose-gc
var v1 = {};
v1 = 0;
var v2 = {};
v2 = 0;
gc();
var minus_zero = {z:-0.0}.z;
var nan = undefined + 1;
function f() {
v1 = minus_zero;
v2 = nan;
};
%OptimizeFunctionOnNextCall(f);
f();
gc(); // Boom!
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