2014-08-12 08:24:20 +00:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
2014-10-30 09:00:58 +00:00
|
|
|
#include "src/code-stubs.h"
|
2014-08-12 08:24:20 +00:00
|
|
|
#include "src/compiler/change-lowering.h"
|
2014-08-18 06:54:07 +00:00
|
|
|
#include "src/compiler/js-graph.h"
|
2014-12-23 12:50:43 +00:00
|
|
|
#include "src/compiler/linkage.h"
|
2015-01-29 09:17:45 +00:00
|
|
|
#include "src/compiler/node-properties.h"
|
2014-08-12 08:24:20 +00:00
|
|
|
#include "src/compiler/simplified-operator.h"
|
2014-10-01 08:34:25 +00:00
|
|
|
#include "test/unittests/compiler/compiler-test-utils.h"
|
|
|
|
#include "test/unittests/compiler/graph-unittest.h"
|
2014-10-20 11:26:23 +00:00
|
|
|
#include "test/unittests/compiler/node-test-utils.h"
|
2014-08-18 06:54:07 +00:00
|
|
|
#include "testing/gmock-support.h"
|
2014-08-12 08:24:20 +00:00
|
|
|
|
|
|
|
using testing::_;
|
2014-08-18 06:54:07 +00:00
|
|
|
using testing::AllOf;
|
2015-01-05 12:29:04 +00:00
|
|
|
using testing::BitEq;
|
2014-08-18 06:54:07 +00:00
|
|
|
using testing::Capture;
|
|
|
|
using testing::CaptureEq;
|
2014-08-12 08:24:20 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
2015-03-18 07:27:31 +00:00
|
|
|
class ChangeLoweringTest : public TypedGraphTest {
|
2014-08-12 08:24:20 +00:00
|
|
|
public:
|
2014-08-18 06:54:07 +00:00
|
|
|
ChangeLoweringTest() : simplified_(zone()) {}
|
2014-08-12 08:24:20 +00:00
|
|
|
|
2014-08-19 04:54:06 +00:00
|
|
|
virtual MachineType WordRepresentation() const = 0;
|
|
|
|
|
2014-08-12 08:24:20 +00:00
|
|
|
protected:
|
2014-08-19 04:54:06 +00:00
|
|
|
bool Is32() const { return WordRepresentation() == kRepWord32; }
|
2015-03-18 07:27:31 +00:00
|
|
|
bool Is64() const { return WordRepresentation() == kRepWord64; }
|
2014-08-19 04:54:06 +00:00
|
|
|
|
2014-08-12 08:24:20 +00:00
|
|
|
Reduction Reduce(Node* node) {
|
2014-11-10 14:28:09 +00:00
|
|
|
MachineOperatorBuilder machine(zone(), WordRepresentation());
|
2014-09-12 11:06:37 +00:00
|
|
|
JSOperatorBuilder javascript(zone());
|
2015-10-16 12:38:46 +00:00
|
|
|
JSGraph jsgraph(isolate(), graph(), common(), &javascript, nullptr,
|
|
|
|
&machine);
|
2015-02-11 14:12:03 +00:00
|
|
|
ChangeLowering reducer(&jsgraph);
|
2014-08-12 08:24:20 +00:00
|
|
|
return reducer.Reduce(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
SimplifiedOperatorBuilder* simplified() { return &simplified_; }
|
|
|
|
|
2014-08-19 04:54:06 +00:00
|
|
|
Matcher<Node*> IsAllocateHeapNumber(const Matcher<Node*>& effect_matcher,
|
|
|
|
const Matcher<Node*>& control_matcher) {
|
2015-08-31 08:24:52 +00:00
|
|
|
return IsCall(
|
|
|
|
_, IsHeapConstant(AllocateHeapNumberStub(isolate()).GetCode()),
|
|
|
|
IsNumberConstant(BitEq(0.0)), effect_matcher, control_matcher);
|
2014-08-12 08:24:20 +00:00
|
|
|
}
|
2015-03-18 07:27:31 +00:00
|
|
|
Matcher<Node*> IsChangeInt32ToSmi(const Matcher<Node*>& value_matcher) {
|
|
|
|
return Is64() ? IsWord64Shl(IsChangeInt32ToInt64(value_matcher),
|
|
|
|
IsSmiShiftBitsConstant())
|
|
|
|
: IsWord32Shl(value_matcher, IsSmiShiftBitsConstant());
|
|
|
|
}
|
|
|
|
Matcher<Node*> IsChangeSmiToInt32(const Matcher<Node*>& value_matcher) {
|
|
|
|
return Is64() ? IsTruncateInt64ToInt32(
|
|
|
|
IsWord64Sar(value_matcher, IsSmiShiftBitsConstant()))
|
|
|
|
: IsWord32Sar(value_matcher, IsSmiShiftBitsConstant());
|
|
|
|
}
|
|
|
|
Matcher<Node*> IsChangeUint32ToSmi(const Matcher<Node*>& value_matcher) {
|
|
|
|
return Is64() ? IsWord64Shl(IsChangeUint32ToUint64(value_matcher),
|
|
|
|
IsSmiShiftBitsConstant())
|
|
|
|
: IsWord32Shl(value_matcher, IsSmiShiftBitsConstant());
|
|
|
|
}
|
2014-10-01 11:08:37 +00:00
|
|
|
Matcher<Node*> IsLoadHeapNumber(const Matcher<Node*>& value_matcher,
|
|
|
|
const Matcher<Node*>& control_matcher) {
|
|
|
|
return IsLoad(kMachFloat64, value_matcher,
|
2015-03-18 07:27:31 +00:00
|
|
|
IsIntPtrConstant(HeapNumber::kValueOffset - kHeapObjectTag),
|
|
|
|
graph()->start(), control_matcher);
|
2014-10-01 11:08:37 +00:00
|
|
|
}
|
2014-10-31 06:41:07 +00:00
|
|
|
Matcher<Node*> IsIntPtrConstant(int value) {
|
|
|
|
return Is32() ? IsInt32Constant(value) : IsInt64Constant(value);
|
|
|
|
}
|
2015-03-18 07:27:31 +00:00
|
|
|
Matcher<Node*> IsSmiShiftBitsConstant() {
|
|
|
|
return IsIntPtrConstant(kSmiShiftSize + kSmiTagSize);
|
|
|
|
}
|
2014-08-19 04:54:06 +00:00
|
|
|
Matcher<Node*> IsWordEqual(const Matcher<Node*>& lhs_matcher,
|
|
|
|
const Matcher<Node*>& rhs_matcher) {
|
|
|
|
return Is32() ? IsWord32Equal(lhs_matcher, rhs_matcher)
|
|
|
|
: IsWord64Equal(lhs_matcher, rhs_matcher);
|
2014-08-12 08:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SimplifiedOperatorBuilder simplified_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-19 04:54:06 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Common.
|
2014-08-12 08:24:20 +00:00
|
|
|
|
|
|
|
|
2014-08-19 05:24:32 +00:00
|
|
|
class ChangeLoweringCommonTest
|
|
|
|
: public ChangeLoweringTest,
|
|
|
|
public ::testing::WithParamInterface<MachineType> {
|
2014-08-19 04:54:06 +00:00
|
|
|
public:
|
2015-04-20 13:08:11 +00:00
|
|
|
~ChangeLoweringCommonTest() override {}
|
2014-08-19 04:54:06 +00:00
|
|
|
|
2015-04-20 13:08:11 +00:00
|
|
|
MachineType WordRepresentation() const final { return GetParam(); }
|
2014-08-19 04:54:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-19 05:24:32 +00:00
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, ChangeBitToBool) {
|
2015-03-18 07:27:31 +00:00
|
|
|
Node* value = Parameter(Type::Boolean());
|
|
|
|
Reduction r =
|
|
|
|
Reduce(graph()->NewNode(simplified()->ChangeBitToBool(), value));
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsSelect(kMachAnyTagged, value, IsTrueConstant(),
|
|
|
|
IsFalseConstant()));
|
2014-08-12 08:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 05:24:32 +00:00
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, ChangeBoolToBit) {
|
2015-03-18 07:27:31 +00:00
|
|
|
Node* value = Parameter(Type::Number());
|
|
|
|
Reduction r =
|
|
|
|
Reduce(graph()->NewNode(simplified()->ChangeBoolToBit(), value));
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsWordEqual(value, IsTrueConstant()));
|
2015-01-08 09:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-18 07:27:31 +00:00
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, ChangeInt32ToTaggedWithSignedSmall) {
|
|
|
|
Node* value = Parameter(Type::SignedSmall());
|
|
|
|
Reduction r =
|
|
|
|
Reduce(graph()->NewNode(simplified()->ChangeInt32ToTagged(), value));
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsChangeInt32ToSmi(value));
|
2014-08-12 08:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-18 07:27:31 +00:00
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, ChangeUint32ToTaggedWithUnsignedSmall) {
|
|
|
|
Node* value = Parameter(Type::UnsignedSmall());
|
|
|
|
Reduction r =
|
|
|
|
Reduce(graph()->NewNode(simplified()->ChangeUint32ToTagged(), value));
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsChangeUint32ToSmi(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, ChangeTaggedToInt32WithTaggedSigned) {
|
|
|
|
Node* value = Parameter(Type::TaggedSigned());
|
|
|
|
Reduction r =
|
|
|
|
Reduce(graph()->NewNode(simplified()->ChangeTaggedToInt32(), value));
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsChangeSmiToInt32(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, ChangeTaggedToInt32WithTaggedPointer) {
|
|
|
|
Node* value = Parameter(Type::TaggedPointer());
|
|
|
|
Reduction r =
|
|
|
|
Reduce(graph()->NewNode(simplified()->ChangeTaggedToInt32(), value));
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsChangeFloat64ToInt32(
|
|
|
|
IsLoadHeapNumber(value, graph()->start())));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, ChangeTaggedToUint32WithTaggedSigned) {
|
|
|
|
Node* value = Parameter(Type::TaggedSigned());
|
|
|
|
Reduction r =
|
|
|
|
Reduce(graph()->NewNode(simplified()->ChangeTaggedToUint32(), value));
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsChangeSmiToInt32(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, ChangeTaggedToUint32WithTaggedPointer) {
|
|
|
|
Node* value = Parameter(Type::TaggedPointer());
|
|
|
|
Reduction r =
|
|
|
|
Reduce(graph()->NewNode(simplified()->ChangeTaggedToUint32(), value));
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsChangeFloat64ToUint32(
|
|
|
|
IsLoadHeapNumber(value, graph()->start())));
|
2014-08-19 04:54:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-13 08:11:59 +00:00
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, StoreFieldSmi) {
|
|
|
|
FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize,
|
|
|
|
Handle<Name>::null(), Type::Any(), kMachAnyTagged};
|
|
|
|
Node* p0 = Parameter(Type::TaggedPointer());
|
|
|
|
Node* p1 = Parameter(Type::TaggedSigned());
|
|
|
|
Node* store = graph()->NewNode(simplified()->StoreField(access), p0, p1,
|
|
|
|
graph()->start(), graph()->start());
|
|
|
|
Reduction r = Reduce(store);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(),
|
|
|
|
IsStore(StoreRepresentation(kMachAnyTagged, kNoWriteBarrier), p0,
|
|
|
|
IsIntPtrConstant(access.offset - access.tag()), p1,
|
|
|
|
graph()->start(), graph()->start()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, StoreFieldTagged) {
|
|
|
|
FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize,
|
|
|
|
Handle<Name>::null(), Type::Any(), kMachAnyTagged};
|
|
|
|
Node* p0 = Parameter(Type::TaggedPointer());
|
|
|
|
Node* p1 = Parameter(Type::Tagged());
|
|
|
|
Node* store = graph()->NewNode(simplified()->StoreField(access), p0, p1,
|
|
|
|
graph()->start(), graph()->start());
|
|
|
|
Reduction r = Reduce(store);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(),
|
|
|
|
IsStore(StoreRepresentation(kMachAnyTagged, kFullWriteBarrier),
|
|
|
|
p0, IsIntPtrConstant(access.offset - access.tag()), p1,
|
|
|
|
graph()->start(), graph()->start()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, LoadField) {
|
|
|
|
FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize,
|
|
|
|
Handle<Name>::null(), Type::Any(), kMachAnyTagged};
|
|
|
|
Node* p0 = Parameter(Type::TaggedPointer());
|
|
|
|
Node* load = graph()->NewNode(simplified()->LoadField(access), p0,
|
|
|
|
graph()->start(), graph()->start());
|
|
|
|
Reduction r = Reduce(load);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
Matcher<Node*> index_match = IsIntPtrConstant(access.offset - access.tag());
|
|
|
|
EXPECT_THAT(
|
|
|
|
r.replacement(),
|
|
|
|
IsLoad(kMachAnyTagged, p0, IsIntPtrConstant(access.offset - access.tag()),
|
|
|
|
graph()->start(), graph()->start()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, StoreElementTagged) {
|
|
|
|
ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, Type::Any(),
|
|
|
|
kMachAnyTagged};
|
|
|
|
Node* p0 = Parameter(Type::TaggedPointer());
|
|
|
|
Node* p1 = Parameter(Type::Signed32());
|
|
|
|
Node* p2 = Parameter(Type::Tagged());
|
|
|
|
Node* store = graph()->NewNode(simplified()->StoreElement(access), p0, p1, p2,
|
|
|
|
graph()->start(), graph()->start());
|
|
|
|
Reduction r = Reduce(store);
|
|
|
|
|
|
|
|
const int element_size_shift = ElementSizeLog2Of(access.machine_type);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
Matcher<Node*> index_match =
|
|
|
|
IsInt32Add(IsWord32Shl(p1, IsInt32Constant(element_size_shift)),
|
|
|
|
IsInt32Constant(access.header_size - access.tag()));
|
|
|
|
if (!Is32()) {
|
|
|
|
index_match = IsChangeUint32ToUint64(index_match);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_THAT(r.replacement(),
|
|
|
|
IsStore(StoreRepresentation(kMachAnyTagged, kFullWriteBarrier),
|
|
|
|
p0, index_match, p2, graph()->start(), graph()->start()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, StoreElementUint8) {
|
|
|
|
ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize,
|
|
|
|
Type::Signed32(), kMachUint8};
|
|
|
|
Node* p0 = Parameter(Type::TaggedPointer());
|
|
|
|
Node* p1 = Parameter(Type::Signed32());
|
|
|
|
Node* p2 = Parameter(Type::Signed32());
|
|
|
|
Node* store = graph()->NewNode(simplified()->StoreElement(access), p0, p1, p2,
|
|
|
|
graph()->start(), graph()->start());
|
|
|
|
Reduction r = Reduce(store);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
Matcher<Node*> index_match =
|
|
|
|
IsInt32Add(p1, IsInt32Constant(access.header_size - access.tag()));
|
|
|
|
if (!Is32()) {
|
|
|
|
index_match = IsChangeUint32ToUint64(index_match);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_THAT(r.replacement(),
|
|
|
|
IsStore(StoreRepresentation(kMachUint8, kNoWriteBarrier), p0,
|
|
|
|
index_match, p2, graph()->start(), graph()->start()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, LoadElementTagged) {
|
|
|
|
ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize, Type::Any(),
|
|
|
|
kMachAnyTagged};
|
|
|
|
Node* p0 = Parameter(Type::TaggedPointer());
|
|
|
|
Node* p1 = Parameter(Type::Signed32());
|
|
|
|
Node* load = graph()->NewNode(simplified()->LoadElement(access), p0, p1,
|
|
|
|
graph()->start(), graph()->start());
|
|
|
|
Reduction r = Reduce(load);
|
|
|
|
|
|
|
|
const int element_size_shift = ElementSizeLog2Of(access.machine_type);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
Matcher<Node*> index_match =
|
|
|
|
IsInt32Add(IsWord32Shl(p1, IsInt32Constant(element_size_shift)),
|
|
|
|
IsInt32Constant(access.header_size - access.tag()));
|
|
|
|
if (!Is32()) {
|
|
|
|
index_match = IsChangeUint32ToUint64(index_match);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_THAT(r.replacement(), IsLoad(kMachAnyTagged, p0, index_match,
|
|
|
|
graph()->start(), graph()->start()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, LoadElementInt8) {
|
|
|
|
ElementAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize,
|
|
|
|
Type::Signed32(), kMachInt8};
|
|
|
|
Node* p0 = Parameter(Type::TaggedPointer());
|
|
|
|
Node* p1 = Parameter(Type::Signed32());
|
|
|
|
Node* load = graph()->NewNode(simplified()->LoadElement(access), p0, p1,
|
|
|
|
graph()->start(), graph()->start());
|
|
|
|
Reduction r = Reduce(load);
|
|
|
|
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
Matcher<Node*> index_match =
|
|
|
|
IsInt32Add(p1, IsInt32Constant(access.header_size - access.tag()));
|
|
|
|
if (!Is32()) {
|
|
|
|
index_match = IsChangeUint32ToUint64(index_match);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPECT_THAT(r.replacement(), IsLoad(kMachInt8, p0, index_match,
|
|
|
|
graph()->start(), graph()->start()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, Allocate) {
|
|
|
|
Node* p0 = Parameter(Type::Signed32());
|
|
|
|
Node* alloc = graph()->NewNode(simplified()->Allocate(TENURED), p0,
|
|
|
|
graph()->start(), graph()->start());
|
|
|
|
Reduction r = Reduce(alloc);
|
|
|
|
|
|
|
|
// Only check that we lowered, but do not specify the exact form since
|
|
|
|
// this is subject to change.
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 05:24:32 +00:00
|
|
|
INSTANTIATE_TEST_CASE_P(ChangeLoweringTest, ChangeLoweringCommonTest,
|
2014-08-19 04:54:06 +00:00
|
|
|
::testing::Values(kRepWord32, kRepWord64));
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// 32-bit
|
|
|
|
|
|
|
|
|
|
|
|
class ChangeLowering32Test : public ChangeLoweringTest {
|
|
|
|
public:
|
2015-04-20 13:08:11 +00:00
|
|
|
~ChangeLowering32Test() override {}
|
|
|
|
MachineType WordRepresentation() const final { return kRepWord32; }
|
2014-08-19 04:54:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-12 09:52:39 +00:00
|
|
|
TARGET_TEST_F(ChangeLowering32Test, ChangeInt32ToTagged) {
|
2015-03-18 07:27:31 +00:00
|
|
|
Node* value = Parameter(Type::Integral32());
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), value);
|
|
|
|
Reduction r = Reduce(node);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2014-08-18 11:36:06 +00:00
|
|
|
Capture<Node*> add, branch, heap_number, if_true;
|
|
|
|
EXPECT_THAT(
|
2015-03-18 07:27:31 +00:00
|
|
|
r.replacement(),
|
2014-09-05 11:44:31 +00:00
|
|
|
IsPhi(kMachAnyTagged,
|
2015-10-14 14:53:04 +00:00
|
|
|
IsFinishRegion(
|
|
|
|
AllOf(CaptureEq(&heap_number),
|
|
|
|
IsAllocateHeapNumber(_, CaptureEq(&if_true))),
|
|
|
|
IsStore(
|
|
|
|
StoreRepresentation(kMachFloat64, kNoWriteBarrier),
|
|
|
|
CaptureEq(&heap_number),
|
|
|
|
IsIntPtrConstant(HeapNumber::kValueOffset - kHeapObjectTag),
|
|
|
|
IsChangeInt32ToFloat64(value), CaptureEq(&heap_number),
|
|
|
|
CaptureEq(&if_true))),
|
2015-03-18 07:27:31 +00:00
|
|
|
IsProjection(0, AllOf(CaptureEq(&add),
|
|
|
|
IsInt32AddWithOverflow(value, value))),
|
2014-08-19 04:54:06 +00:00
|
|
|
IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))),
|
|
|
|
IsIfFalse(AllOf(CaptureEq(&branch),
|
|
|
|
IsBranch(IsProjection(1, CaptureEq(&add)),
|
|
|
|
graph()->start()))))));
|
2014-08-12 08:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-12 09:52:39 +00:00
|
|
|
TARGET_TEST_F(ChangeLowering32Test, ChangeTaggedToFloat64) {
|
2014-08-18 06:54:07 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
|
2015-03-18 07:27:31 +00:00
|
|
|
Node* value = Parameter(Type::Number());
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), value);
|
|
|
|
Reduction r = Reduce(node);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2014-08-18 11:36:06 +00:00
|
|
|
Capture<Node*> branch, if_true;
|
2014-08-18 06:54:07 +00:00
|
|
|
EXPECT_THAT(
|
2015-03-18 07:27:31 +00:00
|
|
|
r.replacement(),
|
|
|
|
IsPhi(kMachFloat64, IsLoadHeapNumber(value, CaptureEq(&if_true)),
|
|
|
|
IsChangeInt32ToFloat64(IsWord32Sar(
|
|
|
|
value, IsInt32Constant(kSmiTagSize + kSmiShiftSize))),
|
|
|
|
IsMerge(AllOf(CaptureEq(&if_true),
|
|
|
|
IsIfTrue(AllOf(
|
|
|
|
CaptureEq(&branch),
|
|
|
|
IsBranch(IsWord32And(
|
|
|
|
value, IsInt32Constant(kSmiTagMask)),
|
|
|
|
graph()->start())))),
|
|
|
|
IsIfFalse(CaptureEq(&branch)))));
|
2014-08-12 08:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 04:54:06 +00:00
|
|
|
TARGET_TEST_F(ChangeLowering32Test, ChangeTaggedToInt32) {
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
2014-08-12 08:24:20 +00:00
|
|
|
|
2015-03-18 07:27:31 +00:00
|
|
|
Node* value = Parameter(Type::Signed32());
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeTaggedToInt32(), value);
|
|
|
|
Reduction r = Reduce(node);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2014-08-19 04:54:06 +00:00
|
|
|
Capture<Node*> branch, if_true;
|
|
|
|
EXPECT_THAT(
|
2015-03-18 07:27:31 +00:00
|
|
|
r.replacement(),
|
|
|
|
IsPhi(
|
|
|
|
kMachInt32,
|
|
|
|
IsChangeFloat64ToInt32(IsLoadHeapNumber(value, CaptureEq(&if_true))),
|
|
|
|
IsWord32Sar(value, IsInt32Constant(kSmiTagSize + kSmiShiftSize)),
|
|
|
|
IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))),
|
|
|
|
IsIfFalse(AllOf(
|
|
|
|
CaptureEq(&branch),
|
|
|
|
IsBranch(IsWord32And(value, IsInt32Constant(kSmiTagMask)),
|
|
|
|
graph()->start()))))));
|
2014-08-12 08:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-20 08:13:00 +00:00
|
|
|
TARGET_TEST_F(ChangeLowering32Test, ChangeTaggedToUint32) {
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
|
2015-03-18 07:27:31 +00:00
|
|
|
Node* value = Parameter(Type::Unsigned32());
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeTaggedToUint32(), value);
|
|
|
|
Reduction r = Reduce(node);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2014-08-20 08:13:00 +00:00
|
|
|
Capture<Node*> branch, if_true;
|
|
|
|
EXPECT_THAT(
|
2015-03-18 07:27:31 +00:00
|
|
|
r.replacement(),
|
|
|
|
IsPhi(
|
|
|
|
kMachUint32,
|
|
|
|
IsChangeFloat64ToUint32(IsLoadHeapNumber(value, CaptureEq(&if_true))),
|
|
|
|
IsWord32Sar(value, IsInt32Constant(kSmiTagSize + kSmiShiftSize)),
|
|
|
|
IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))),
|
|
|
|
IsIfFalse(AllOf(
|
|
|
|
CaptureEq(&branch),
|
|
|
|
IsBranch(IsWord32And(value, IsInt32Constant(kSmiTagMask)),
|
|
|
|
graph()->start()))))));
|
2014-08-20 08:13:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-20 04:01:36 +00:00
|
|
|
TARGET_TEST_F(ChangeLowering32Test, ChangeUint32ToTagged) {
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
|
2015-03-18 07:27:31 +00:00
|
|
|
Node* value = Parameter(Type::Number());
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeUint32ToTagged(), value);
|
|
|
|
Reduction r = Reduce(node);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2014-08-20 04:01:36 +00:00
|
|
|
Capture<Node*> branch, heap_number, if_false;
|
|
|
|
EXPECT_THAT(
|
2015-03-18 07:27:31 +00:00
|
|
|
r.replacement(),
|
2014-08-20 04:01:36 +00:00
|
|
|
IsPhi(
|
2015-03-18 07:27:31 +00:00
|
|
|
kMachAnyTagged,
|
|
|
|
IsWord32Shl(value, IsInt32Constant(kSmiTagSize + kSmiShiftSize)),
|
2015-10-14 14:53:04 +00:00
|
|
|
IsFinishRegion(
|
|
|
|
AllOf(CaptureEq(&heap_number),
|
|
|
|
IsAllocateHeapNumber(_, CaptureEq(&if_false))),
|
|
|
|
IsStore(
|
|
|
|
StoreRepresentation(kMachFloat64, kNoWriteBarrier),
|
|
|
|
CaptureEq(&heap_number),
|
|
|
|
IsInt32Constant(HeapNumber::kValueOffset - kHeapObjectTag),
|
|
|
|
IsChangeUint32ToFloat64(value), CaptureEq(&heap_number),
|
|
|
|
CaptureEq(&if_false))),
|
2015-03-18 07:27:31 +00:00
|
|
|
IsMerge(IsIfTrue(AllOf(
|
|
|
|
CaptureEq(&branch),
|
|
|
|
IsBranch(IsUint32LessThanOrEqual(
|
|
|
|
value, IsInt32Constant(Smi::kMaxValue)),
|
|
|
|
graph()->start()))),
|
|
|
|
AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch))))));
|
2014-08-20 04:01:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 04:54:06 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// 64-bit
|
|
|
|
|
|
|
|
|
|
|
|
class ChangeLowering64Test : public ChangeLoweringTest {
|
|
|
|
public:
|
2015-04-20 13:08:11 +00:00
|
|
|
~ChangeLowering64Test() override {}
|
|
|
|
MachineType WordRepresentation() const final { return kRepWord64; }
|
2014-08-19 04:54:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-12 09:52:39 +00:00
|
|
|
TARGET_TEST_F(ChangeLowering64Test, ChangeInt32ToTagged) {
|
2015-03-18 07:27:31 +00:00
|
|
|
Node* value = Parameter(Type::Signed32());
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), value);
|
|
|
|
Reduction r = Reduce(node);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsChangeInt32ToSmi(value));
|
2014-08-12 08:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-12 09:52:39 +00:00
|
|
|
TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToFloat64) {
|
2014-08-18 06:54:07 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
|
2015-03-18 07:27:31 +00:00
|
|
|
Node* value = Parameter(Type::Number());
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), value);
|
|
|
|
Reduction r = Reduce(node);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2014-08-18 11:36:06 +00:00
|
|
|
Capture<Node*> branch, if_true;
|
2014-08-18 06:54:07 +00:00
|
|
|
EXPECT_THAT(
|
2015-03-18 07:27:31 +00:00
|
|
|
r.replacement(),
|
|
|
|
IsPhi(kMachFloat64, IsLoadHeapNumber(value, CaptureEq(&if_true)),
|
|
|
|
IsChangeInt32ToFloat64(IsTruncateInt64ToInt32(IsWord64Sar(
|
|
|
|
value, IsInt64Constant(kSmiTagSize + kSmiShiftSize)))),
|
|
|
|
IsMerge(AllOf(CaptureEq(&if_true),
|
|
|
|
IsIfTrue(AllOf(
|
|
|
|
CaptureEq(&branch),
|
|
|
|
IsBranch(IsWord64And(
|
|
|
|
value, IsInt64Constant(kSmiTagMask)),
|
|
|
|
graph()->start())))),
|
|
|
|
IsIfFalse(CaptureEq(&branch)))));
|
2014-08-12 08:24:20 +00:00
|
|
|
}
|
|
|
|
|
2014-08-19 04:54:06 +00:00
|
|
|
|
|
|
|
TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToInt32) {
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
|
2015-03-18 07:27:31 +00:00
|
|
|
Node* value = Parameter(Type::Signed32());
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeTaggedToInt32(), value);
|
|
|
|
Reduction r = Reduce(node);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2014-08-20 08:13:00 +00:00
|
|
|
Capture<Node*> branch, if_true;
|
|
|
|
EXPECT_THAT(
|
2015-03-18 07:27:31 +00:00
|
|
|
r.replacement(),
|
|
|
|
IsPhi(
|
|
|
|
kMachInt32,
|
|
|
|
IsChangeFloat64ToInt32(IsLoadHeapNumber(value, CaptureEq(&if_true))),
|
|
|
|
IsTruncateInt64ToInt32(
|
|
|
|
IsWord64Sar(value, IsInt64Constant(kSmiTagSize + kSmiShiftSize))),
|
|
|
|
IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))),
|
|
|
|
IsIfFalse(AllOf(
|
|
|
|
CaptureEq(&branch),
|
|
|
|
IsBranch(IsWord64And(value, IsInt64Constant(kSmiTagMask)),
|
|
|
|
graph()->start()))))));
|
2014-08-20 08:13:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToUint32) {
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
|
2015-03-18 07:27:31 +00:00
|
|
|
Node* value = Parameter(Type::Unsigned32());
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeTaggedToUint32(), value);
|
|
|
|
Reduction r = Reduce(node);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2014-08-19 04:54:06 +00:00
|
|
|
Capture<Node*> branch, if_true;
|
|
|
|
EXPECT_THAT(
|
2015-03-18 07:27:31 +00:00
|
|
|
r.replacement(),
|
|
|
|
IsPhi(
|
|
|
|
kMachUint32,
|
|
|
|
IsChangeFloat64ToUint32(IsLoadHeapNumber(value, CaptureEq(&if_true))),
|
|
|
|
IsTruncateInt64ToInt32(
|
|
|
|
IsWord64Sar(value, IsInt64Constant(kSmiTagSize + kSmiShiftSize))),
|
|
|
|
IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))),
|
|
|
|
IsIfFalse(AllOf(
|
|
|
|
CaptureEq(&branch),
|
|
|
|
IsBranch(IsWord64And(value, IsInt64Constant(kSmiTagMask)),
|
|
|
|
graph()->start()))))));
|
2014-08-19 04:54:06 +00:00
|
|
|
}
|
|
|
|
|
2014-08-20 04:01:36 +00:00
|
|
|
|
|
|
|
TARGET_TEST_F(ChangeLowering64Test, ChangeUint32ToTagged) {
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
|
2015-03-18 07:27:31 +00:00
|
|
|
Node* value = Parameter(Type::Number());
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeUint32ToTagged(), value);
|
|
|
|
Reduction r = Reduce(node);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2014-08-20 04:01:36 +00:00
|
|
|
Capture<Node*> branch, heap_number, if_false;
|
|
|
|
EXPECT_THAT(
|
2015-03-18 07:27:31 +00:00
|
|
|
r.replacement(),
|
2014-08-20 04:01:36 +00:00
|
|
|
IsPhi(
|
2015-03-18 07:27:31 +00:00
|
|
|
kMachAnyTagged,
|
|
|
|
IsWord64Shl(IsChangeUint32ToUint64(value),
|
|
|
|
IsInt64Constant(kSmiTagSize + kSmiShiftSize)),
|
2015-10-14 14:53:04 +00:00
|
|
|
IsFinishRegion(
|
|
|
|
AllOf(CaptureEq(&heap_number),
|
|
|
|
IsAllocateHeapNumber(_, CaptureEq(&if_false))),
|
|
|
|
IsStore(
|
|
|
|
StoreRepresentation(kMachFloat64, kNoWriteBarrier),
|
|
|
|
CaptureEq(&heap_number),
|
|
|
|
IsInt64Constant(HeapNumber::kValueOffset - kHeapObjectTag),
|
|
|
|
IsChangeUint32ToFloat64(value), CaptureEq(&heap_number),
|
|
|
|
CaptureEq(&if_false))),
|
2015-03-18 07:27:31 +00:00
|
|
|
IsMerge(IsIfTrue(AllOf(
|
|
|
|
CaptureEq(&branch),
|
|
|
|
IsBranch(IsUint32LessThanOrEqual(
|
|
|
|
value, IsInt32Constant(Smi::kMaxValue)),
|
|
|
|
graph()->start()))),
|
|
|
|
AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch))))));
|
2014-08-20 04:01:36 +00:00
|
|
|
}
|
|
|
|
|
2014-08-12 08:24:20 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|