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 {
|
|
|
|
|
2014-08-18 06:54:07 +00:00
|
|
|
class ChangeLoweringTest : public GraphTest {
|
2014-08-12 08:24:20 +00:00
|
|
|
public:
|
2014-08-18 06:54:07 +00:00
|
|
|
ChangeLoweringTest() : simplified_(zone()) {}
|
2014-12-22 13:47:54 +00:00
|
|
|
~ChangeLoweringTest() OVERRIDE {}
|
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
|
|
|
int HeapNumberValueOffset() const {
|
|
|
|
STATIC_ASSERT(HeapNumber::kValueOffset % kApiPointerSize == 0);
|
|
|
|
return (HeapNumber::kValueOffset / kApiPointerSize) * PointerSize() -
|
|
|
|
kHeapObjectTag;
|
|
|
|
}
|
|
|
|
bool Is32() const { return WordRepresentation() == kRepWord32; }
|
|
|
|
int PointerSize() const {
|
|
|
|
switch (WordRepresentation()) {
|
|
|
|
case kRepWord32:
|
|
|
|
return 4;
|
|
|
|
case kRepWord64:
|
|
|
|
return 8;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
UNREACHABLE();
|
|
|
|
return 0;
|
|
|
|
}
|
2014-08-20 04:01:36 +00:00
|
|
|
int SmiMaxValue() const { return -(SmiMinValue() + 1); }
|
|
|
|
int SmiMinValue() const {
|
|
|
|
return static_cast<int>(0xffffffffu << (SmiValueSize() - 1));
|
|
|
|
}
|
2014-08-19 04:54:06 +00:00
|
|
|
int SmiShiftAmount() const { return kSmiTagSize + SmiShiftSize(); }
|
|
|
|
int SmiShiftSize() const {
|
2014-09-01 10:24:04 +00:00
|
|
|
return Is32() ? SmiTagging<4>::SmiShiftSize()
|
|
|
|
: SmiTagging<8>::SmiShiftSize();
|
2014-08-19 04:54:06 +00:00
|
|
|
}
|
2014-08-20 04:01:36 +00:00
|
|
|
int SmiValueSize() const {
|
2014-09-01 10:24:04 +00:00
|
|
|
return Is32() ? SmiTagging<4>::SmiValueSize()
|
|
|
|
: SmiTagging<8>::SmiValueSize();
|
2014-08-20 04:01:36 +00:00
|
|
|
}
|
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-01-23 15:19:34 +00:00
|
|
|
JSGraph jsgraph(isolate(), graph(), common(), &javascript, &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) {
|
2014-11-04 12:58:17 +00:00
|
|
|
return IsCall(_, IsHeapConstant(Unique<HeapObject>::CreateImmovable(
|
|
|
|
AllocateHeapNumberStub(isolate()).GetCode())),
|
2015-01-05 12:29:04 +00:00
|
|
|
IsNumberConstant(BitEq(0.0)), effect_matcher,
|
|
|
|
control_matcher);
|
2014-08-12 08:24:20 +00:00
|
|
|
}
|
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,
|
2014-10-31 06:41:07 +00:00
|
|
|
IsIntPtrConstant(HeapNumberValueOffset()), graph()->start(),
|
2014-10-01 11:08:37 +00:00
|
|
|
control_matcher);
|
|
|
|
}
|
2014-10-31 06:41:07 +00:00
|
|
|
Matcher<Node*> IsIntPtrConstant(int value) {
|
|
|
|
return Is32() ? IsInt32Constant(value) : IsInt64Constant(value);
|
|
|
|
}
|
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:
|
2014-12-22 13:47:54 +00:00
|
|
|
~ChangeLoweringCommonTest() OVERRIDE {}
|
2014-08-19 04:54:06 +00:00
|
|
|
|
2014-12-22 13:47:54 +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) {
|
2014-08-19 04:54:06 +00:00
|
|
|
Node* val = Parameter(0);
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeBitToBool(), val);
|
|
|
|
Reduction reduction = Reduce(node);
|
2014-08-12 08:24:20 +00:00
|
|
|
ASSERT_TRUE(reduction.Changed());
|
2014-11-06 09:09:50 +00:00
|
|
|
EXPECT_THAT(reduction.replacement(),
|
|
|
|
IsSelect(static_cast<MachineType>(kTypeBool | kRepTagged), val,
|
|
|
|
IsTrueConstant(), IsFalseConstant()));
|
2014-08-12 08:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 05:24:32 +00:00
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, ChangeBoolToBit) {
|
2014-08-19 04:54:06 +00:00
|
|
|
Node* val = Parameter(0);
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeBoolToBit(), val);
|
|
|
|
Reduction reduction = Reduce(node);
|
|
|
|
ASSERT_TRUE(reduction.Changed());
|
2014-08-12 08:24:20 +00:00
|
|
|
|
2015-01-14 12:06:41 +00:00
|
|
|
EXPECT_THAT(reduction.replacement(), IsWordEqual(val, IsTrueConstant()));
|
2015-01-08 09:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 05:24:32 +00:00
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, ChangeFloat64ToTagged) {
|
2014-08-12 08:24:20 +00:00
|
|
|
Node* val = Parameter(0);
|
2014-08-19 04:54:06 +00:00
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeFloat64ToTagged(), val);
|
2014-08-12 08:24:20 +00:00
|
|
|
Reduction reduction = Reduce(node);
|
|
|
|
ASSERT_TRUE(reduction.Changed());
|
|
|
|
|
2014-08-19 04:54:06 +00:00
|
|
|
Node* finish = reduction.replacement();
|
|
|
|
Capture<Node*> heap_number;
|
|
|
|
EXPECT_THAT(
|
|
|
|
finish,
|
|
|
|
IsFinish(
|
|
|
|
AllOf(CaptureEq(&heap_number),
|
|
|
|
IsAllocateHeapNumber(IsValueEffect(val), graph()->start())),
|
2014-10-09 12:20:45 +00:00
|
|
|
IsStore(StoreRepresentation(kMachFloat64, kNoWriteBarrier),
|
|
|
|
CaptureEq(&heap_number),
|
2014-10-31 06:41:07 +00:00
|
|
|
IsIntPtrConstant(HeapNumberValueOffset()), val,
|
2014-08-19 04:54:06 +00:00
|
|
|
CaptureEq(&heap_number), graph()->start())));
|
2014-08-12 08:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 05:24:32 +00:00
|
|
|
TARGET_TEST_P(ChangeLoweringCommonTest, StringAdd) {
|
2014-08-19 04:54:06 +00:00
|
|
|
Node* node =
|
|
|
|
graph()->NewNode(simplified()->StringAdd(), Parameter(0), Parameter(1));
|
|
|
|
Reduction reduction = Reduce(node);
|
|
|
|
EXPECT_FALSE(reduction.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:
|
2014-12-22 13:47:54 +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) {
|
2014-08-12 08:24:20 +00:00
|
|
|
Node* val = Parameter(0);
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val);
|
2014-11-17 13:55:27 +00:00
|
|
|
NodeProperties::SetBounds(val, Bounds(Type::None(), Type::Signed32()));
|
2014-08-12 08:24:20 +00:00
|
|
|
Reduction reduction = Reduce(node);
|
|
|
|
ASSERT_TRUE(reduction.Changed());
|
|
|
|
|
|
|
|
Node* phi = reduction.replacement();
|
2014-08-18 11:36:06 +00:00
|
|
|
Capture<Node*> add, branch, heap_number, if_true;
|
|
|
|
EXPECT_THAT(
|
|
|
|
phi,
|
2014-09-05 11:44:31 +00:00
|
|
|
IsPhi(kMachAnyTagged,
|
2014-10-09 12:20:45 +00:00
|
|
|
IsFinish(AllOf(CaptureEq(&heap_number),
|
|
|
|
IsAllocateHeapNumber(_, CaptureEq(&if_true))),
|
|
|
|
IsStore(StoreRepresentation(kMachFloat64, kNoWriteBarrier),
|
|
|
|
CaptureEq(&heap_number),
|
2014-10-31 06:41:07 +00:00
|
|
|
IsIntPtrConstant(HeapNumberValueOffset()),
|
2014-10-09 12:20:45 +00:00
|
|
|
IsChangeInt32ToFloat64(val),
|
|
|
|
CaptureEq(&heap_number), CaptureEq(&if_true))),
|
2014-08-19 04:54:06 +00:00
|
|
|
IsProjection(
|
|
|
|
0, AllOf(CaptureEq(&add), IsInt32AddWithOverflow(val, val))),
|
|
|
|
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-11-17 13:55:27 +00:00
|
|
|
TARGET_TEST_F(ChangeLowering32Test, ChangeInt32ToTaggedSmall) {
|
|
|
|
Node* val = Parameter(0);
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val);
|
2015-01-28 08:42:15 +00:00
|
|
|
NodeProperties::SetBounds(val, Bounds(Type::None(), Type::Signed31()));
|
2014-11-17 13:55:27 +00:00
|
|
|
Reduction reduction = Reduce(node);
|
|
|
|
ASSERT_TRUE(reduction.Changed());
|
|
|
|
|
|
|
|
Node* change = reduction.replacement();
|
|
|
|
Capture<Node*> add, branch, heap_number, if_true;
|
|
|
|
EXPECT_THAT(change, IsWord32Shl(val, IsInt32Constant(SmiShiftAmount())));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2014-08-12 08:24:20 +00:00
|
|
|
Node* val = Parameter(0);
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val);
|
|
|
|
Reduction reduction = Reduce(node);
|
|
|
|
ASSERT_TRUE(reduction.Changed());
|
|
|
|
|
|
|
|
Node* phi = reduction.replacement();
|
2014-08-18 11:36:06 +00:00
|
|
|
Capture<Node*> branch, if_true;
|
2014-08-18 06:54:07 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
phi,
|
2014-08-18 11:36:06 +00:00
|
|
|
IsPhi(
|
2014-10-01 11:08:37 +00:00
|
|
|
kMachFloat64, IsLoadHeapNumber(val, CaptureEq(&if_true)),
|
2014-08-18 11:36:06 +00:00
|
|
|
IsChangeInt32ToFloat64(
|
2014-08-19 04:54:06 +00:00
|
|
|
IsWord32Sar(val, IsInt32Constant(SmiShiftAmount()))),
|
2014-08-18 11:36:06 +00:00
|
|
|
IsMerge(
|
|
|
|
AllOf(CaptureEq(&if_true),
|
|
|
|
IsIfTrue(AllOf(
|
2014-08-18 06:54:07 +00:00
|
|
|
CaptureEq(&branch),
|
|
|
|
IsBranch(IsWord32And(val, IsInt32Constant(kSmiTagMask)),
|
2014-08-18 11:36:06 +00:00
|
|
|
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
|
|
|
|
|
|
|
Node* val = Parameter(0);
|
2014-08-19 04:54:06 +00:00
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeTaggedToInt32(), val);
|
2014-08-12 08:24:20 +00:00
|
|
|
Reduction reduction = Reduce(node);
|
|
|
|
ASSERT_TRUE(reduction.Changed());
|
|
|
|
|
2014-08-19 04:54:06 +00:00
|
|
|
Node* phi = reduction.replacement();
|
|
|
|
Capture<Node*> branch, if_true;
|
|
|
|
EXPECT_THAT(
|
|
|
|
phi,
|
2014-09-05 11:44:31 +00:00
|
|
|
IsPhi(kMachInt32,
|
2014-10-01 11:08:37 +00:00
|
|
|
IsChangeFloat64ToInt32(IsLoadHeapNumber(val, CaptureEq(&if_true))),
|
2014-08-19 04:54:06 +00:00
|
|
|
IsWord32Sar(val, IsInt32Constant(SmiShiftAmount())),
|
|
|
|
IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))),
|
|
|
|
IsIfFalse(AllOf(
|
|
|
|
CaptureEq(&branch),
|
|
|
|
IsBranch(IsWord32And(val, 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);
|
|
|
|
|
|
|
|
Node* val = Parameter(0);
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeTaggedToUint32(), val);
|
|
|
|
Reduction reduction = Reduce(node);
|
|
|
|
ASSERT_TRUE(reduction.Changed());
|
|
|
|
|
|
|
|
Node* phi = reduction.replacement();
|
|
|
|
Capture<Node*> branch, if_true;
|
|
|
|
EXPECT_THAT(
|
|
|
|
phi,
|
2014-09-05 11:44:31 +00:00
|
|
|
IsPhi(kMachUint32,
|
2014-10-01 11:08:37 +00:00
|
|
|
IsChangeFloat64ToUint32(IsLoadHeapNumber(val, CaptureEq(&if_true))),
|
2014-08-20 08:13:00 +00:00
|
|
|
IsWord32Sar(val, IsInt32Constant(SmiShiftAmount())),
|
|
|
|
IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))),
|
|
|
|
IsIfFalse(AllOf(
|
|
|
|
CaptureEq(&branch),
|
|
|
|
IsBranch(IsWord32And(val, IsInt32Constant(kSmiTagMask)),
|
|
|
|
graph()->start()))))));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-20 04:01:36 +00:00
|
|
|
TARGET_TEST_F(ChangeLowering32Test, ChangeUint32ToTagged) {
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
|
|
|
|
Node* val = Parameter(0);
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeUint32ToTagged(), val);
|
|
|
|
Reduction reduction = Reduce(node);
|
|
|
|
ASSERT_TRUE(reduction.Changed());
|
|
|
|
|
|
|
|
Node* phi = reduction.replacement();
|
|
|
|
Capture<Node*> branch, heap_number, if_false;
|
|
|
|
EXPECT_THAT(
|
|
|
|
phi,
|
|
|
|
IsPhi(
|
2014-09-05 11:44:31 +00:00
|
|
|
kMachAnyTagged, IsWord32Shl(val, IsInt32Constant(SmiShiftAmount())),
|
2014-10-09 12:20:45 +00:00
|
|
|
IsFinish(AllOf(CaptureEq(&heap_number),
|
|
|
|
IsAllocateHeapNumber(_, CaptureEq(&if_false))),
|
|
|
|
IsStore(StoreRepresentation(kMachFloat64, kNoWriteBarrier),
|
|
|
|
CaptureEq(&heap_number),
|
|
|
|
IsInt32Constant(HeapNumberValueOffset()),
|
|
|
|
IsChangeUint32ToFloat64(val),
|
|
|
|
CaptureEq(&heap_number), CaptureEq(&if_false))),
|
2014-08-20 04:01:36 +00:00
|
|
|
IsMerge(
|
|
|
|
IsIfTrue(AllOf(CaptureEq(&branch),
|
|
|
|
IsBranch(IsUint32LessThanOrEqual(
|
|
|
|
val, IsInt32Constant(SmiMaxValue())),
|
|
|
|
graph()->start()))),
|
|
|
|
AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch))))));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 04:54:06 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// 64-bit
|
|
|
|
|
|
|
|
|
|
|
|
class ChangeLowering64Test : public ChangeLoweringTest {
|
|
|
|
public:
|
2014-12-22 13:47:54 +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) {
|
2014-08-12 08:24:20 +00:00
|
|
|
Node* val = Parameter(0);
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val);
|
|
|
|
Reduction reduction = Reduce(node);
|
|
|
|
ASSERT_TRUE(reduction.Changed());
|
|
|
|
|
|
|
|
EXPECT_THAT(reduction.replacement(),
|
2014-08-19 08:48:41 +00:00
|
|
|
IsWord64Shl(IsChangeInt32ToInt64(val),
|
2014-10-31 06:41:07 +00:00
|
|
|
IsInt64Constant(SmiShiftAmount())));
|
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);
|
|
|
|
|
2014-08-12 08:24:20 +00:00
|
|
|
Node* val = Parameter(0);
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val);
|
|
|
|
Reduction reduction = Reduce(node);
|
|
|
|
ASSERT_TRUE(reduction.Changed());
|
|
|
|
|
|
|
|
Node* phi = reduction.replacement();
|
2014-08-18 11:36:06 +00:00
|
|
|
Capture<Node*> branch, if_true;
|
2014-08-18 06:54:07 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
phi,
|
2014-08-18 11:36:06 +00:00
|
|
|
IsPhi(
|
2014-10-01 11:08:37 +00:00
|
|
|
kMachFloat64, IsLoadHeapNumber(val, CaptureEq(&if_true)),
|
2014-08-19 08:48:41 +00:00
|
|
|
IsChangeInt32ToFloat64(IsTruncateInt64ToInt32(
|
2014-10-31 06:41:07 +00:00
|
|
|
IsWord64Sar(val, IsInt64Constant(SmiShiftAmount())))),
|
2014-08-18 11:36:06 +00:00
|
|
|
IsMerge(
|
|
|
|
AllOf(CaptureEq(&if_true),
|
|
|
|
IsIfTrue(AllOf(
|
2014-08-18 06:54:07 +00:00
|
|
|
CaptureEq(&branch),
|
2014-10-31 06:41:07 +00:00
|
|
|
IsBranch(IsWord64And(val, IsInt64Constant(kSmiTagMask)),
|
2014-08-18 11:36:06 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
Node* val = Parameter(0);
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeTaggedToInt32(), val);
|
|
|
|
Reduction reduction = Reduce(node);
|
|
|
|
ASSERT_TRUE(reduction.Changed());
|
2014-08-20 08:13:00 +00:00
|
|
|
|
|
|
|
Node* phi = reduction.replacement();
|
|
|
|
Capture<Node*> branch, if_true;
|
|
|
|
EXPECT_THAT(
|
|
|
|
phi,
|
2014-09-05 11:44:31 +00:00
|
|
|
IsPhi(kMachInt32,
|
2014-10-01 11:08:37 +00:00
|
|
|
IsChangeFloat64ToInt32(IsLoadHeapNumber(val, CaptureEq(&if_true))),
|
2014-08-20 08:13:00 +00:00
|
|
|
IsTruncateInt64ToInt32(
|
2014-10-31 06:41:07 +00:00
|
|
|
IsWord64Sar(val, IsInt64Constant(SmiShiftAmount()))),
|
2014-08-20 08:13:00 +00:00
|
|
|
IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))),
|
|
|
|
IsIfFalse(AllOf(
|
|
|
|
CaptureEq(&branch),
|
2014-10-31 06:41:07 +00:00
|
|
|
IsBranch(IsWord64And(val, IsInt64Constant(kSmiTagMask)),
|
2014-08-20 08:13:00 +00:00
|
|
|
graph()->start()))))));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToUint32) {
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
|
|
|
|
Node* val = Parameter(0);
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeTaggedToUint32(), val);
|
|
|
|
Reduction reduction = Reduce(node);
|
|
|
|
ASSERT_TRUE(reduction.Changed());
|
2014-08-19 04:54:06 +00:00
|
|
|
|
|
|
|
Node* phi = reduction.replacement();
|
|
|
|
Capture<Node*> branch, if_true;
|
|
|
|
EXPECT_THAT(
|
|
|
|
phi,
|
2014-09-05 11:44:31 +00:00
|
|
|
IsPhi(kMachUint32,
|
2014-10-01 11:08:37 +00:00
|
|
|
IsChangeFloat64ToUint32(IsLoadHeapNumber(val, CaptureEq(&if_true))),
|
2014-08-19 08:48:41 +00:00
|
|
|
IsTruncateInt64ToInt32(
|
2014-10-31 06:41:07 +00:00
|
|
|
IsWord64Sar(val, IsInt64Constant(SmiShiftAmount()))),
|
2014-08-19 04:54:06 +00:00
|
|
|
IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))),
|
|
|
|
IsIfFalse(AllOf(
|
|
|
|
CaptureEq(&branch),
|
2014-10-31 06:41:07 +00:00
|
|
|
IsBranch(IsWord64And(val, IsInt64Constant(kSmiTagMask)),
|
2014-08-19 04:54:06 +00:00
|
|
|
graph()->start()))))));
|
|
|
|
}
|
|
|
|
|
2014-08-20 04:01:36 +00:00
|
|
|
|
|
|
|
TARGET_TEST_F(ChangeLowering64Test, ChangeUint32ToTagged) {
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagSize == 1);
|
|
|
|
|
|
|
|
Node* val = Parameter(0);
|
|
|
|
Node* node = graph()->NewNode(simplified()->ChangeUint32ToTagged(), val);
|
|
|
|
Reduction reduction = Reduce(node);
|
|
|
|
ASSERT_TRUE(reduction.Changed());
|
|
|
|
|
|
|
|
Node* phi = reduction.replacement();
|
|
|
|
Capture<Node*> branch, heap_number, if_false;
|
|
|
|
EXPECT_THAT(
|
|
|
|
phi,
|
|
|
|
IsPhi(
|
2014-09-05 11:44:31 +00:00
|
|
|
kMachAnyTagged, IsWord64Shl(IsChangeUint32ToUint64(val),
|
2014-10-31 06:41:07 +00:00
|
|
|
IsInt64Constant(SmiShiftAmount())),
|
2014-10-09 12:20:45 +00:00
|
|
|
IsFinish(AllOf(CaptureEq(&heap_number),
|
|
|
|
IsAllocateHeapNumber(_, CaptureEq(&if_false))),
|
|
|
|
IsStore(StoreRepresentation(kMachFloat64, kNoWriteBarrier),
|
|
|
|
CaptureEq(&heap_number),
|
2014-10-31 06:41:07 +00:00
|
|
|
IsInt64Constant(HeapNumberValueOffset()),
|
2014-10-09 12:20:45 +00:00
|
|
|
IsChangeUint32ToFloat64(val),
|
|
|
|
CaptureEq(&heap_number), CaptureEq(&if_false))),
|
2014-08-20 04:01:36 +00:00
|
|
|
IsMerge(
|
|
|
|
IsIfTrue(AllOf(CaptureEq(&branch),
|
|
|
|
IsBranch(IsUint32LessThanOrEqual(
|
2014-11-03 10:04:37 +00:00
|
|
|
val, IsInt32Constant(SmiMaxValue())),
|
2014-08-20 04:01:36 +00:00
|
|
|
graph()->start()))),
|
|
|
|
AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch))))));
|
|
|
|
}
|
|
|
|
|
2014-08-12 08:24:20 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|