2014-08-19 08:48:41 +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-01 08:34:25 +00:00
|
|
|
#include "test/unittests/compiler/instruction-selector-unittest.h"
|
|
|
|
|
2014-09-30 09:46:30 +00:00
|
|
|
#include "src/compiler/node-matchers.h"
|
2014-08-19 08:48:41 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Conversions.
|
|
|
|
|
|
|
|
|
2014-09-24 11:08:35 +00:00
|
|
|
TEST_F(InstructionSelectorTest, ChangeFloat32ToFloat64WithParameter) {
|
|
|
|
StreamBuilder m(this, kMachFloat32, kMachFloat64);
|
|
|
|
m.Return(m.ChangeFloat32ToFloat64(m.Parameter(0)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kSSECvtss2sd, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(1U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(1U, s[0]->OutputCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 08:48:41 +00:00
|
|
|
TEST_F(InstructionSelectorTest, ChangeInt32ToInt64WithParameter) {
|
|
|
|
StreamBuilder m(this, kMachInt64, kMachInt32);
|
|
|
|
m.Return(m.ChangeInt32ToInt64(m.Parameter(0)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Movsxlq, s[0]->arch_opcode());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-30 10:24:11 +00:00
|
|
|
TEST_F(InstructionSelectorTest, ChangeUint32ToFloat64WithParameter) {
|
|
|
|
StreamBuilder m(this, kMachFloat64, kMachUint32);
|
|
|
|
m.Return(m.ChangeUint32ToFloat64(m.Parameter(0)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kSSEUint32ToFloat64, s[0]->arch_opcode());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 08:48:41 +00:00
|
|
|
TEST_F(InstructionSelectorTest, ChangeUint32ToUint64WithParameter) {
|
|
|
|
StreamBuilder m(this, kMachUint64, kMachUint32);
|
|
|
|
m.Return(m.ChangeUint32ToUint64(m.Parameter(0)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Movl, s[0]->arch_opcode());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-24 11:08:35 +00:00
|
|
|
TEST_F(InstructionSelectorTest, TruncateFloat64ToFloat32WithParameter) {
|
|
|
|
StreamBuilder m(this, kMachFloat64, kMachFloat32);
|
|
|
|
m.Return(m.TruncateFloat64ToFloat32(m.Parameter(0)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kSSECvtsd2ss, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(1U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(1U, s[0]->OutputCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-19 08:48:41 +00:00
|
|
|
TEST_F(InstructionSelectorTest, TruncateInt64ToInt32WithParameter) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt64);
|
|
|
|
m.Return(m.TruncateInt64ToInt32(m.Parameter(0)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Movl, s[0]->arch_opcode());
|
|
|
|
}
|
|
|
|
|
2014-08-25 10:35:38 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Loads and stores
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct MemoryAccess {
|
|
|
|
MachineType type;
|
|
|
|
ArchOpcode load_opcode;
|
|
|
|
ArchOpcode store_opcode;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& os, const MemoryAccess& memacc) {
|
2014-09-30 10:29:32 +00:00
|
|
|
return os << memacc.type;
|
2014-08-25 10:35:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const MemoryAccess kMemoryAccesses[] = {
|
|
|
|
{kMachInt8, kX64Movsxbl, kX64Movb},
|
|
|
|
{kMachUint8, kX64Movzxbl, kX64Movb},
|
|
|
|
{kMachInt16, kX64Movsxwl, kX64Movw},
|
|
|
|
{kMachUint16, kX64Movzxwl, kX64Movw},
|
|
|
|
{kMachInt32, kX64Movl, kX64Movl},
|
|
|
|
{kMachUint32, kX64Movl, kX64Movl},
|
|
|
|
{kMachInt64, kX64Movq, kX64Movq},
|
|
|
|
{kMachUint64, kX64Movq, kX64Movq},
|
2014-08-26 08:29:12 +00:00
|
|
|
{kMachFloat32, kX64Movss, kX64Movss},
|
2014-08-25 10:35:38 +00:00
|
|
|
{kMachFloat64, kX64Movsd, kX64Movsd}};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
typedef InstructionSelectorTestWithParam<MemoryAccess>
|
|
|
|
InstructionSelectorMemoryAccessTest;
|
|
|
|
|
|
|
|
|
|
|
|
TEST_P(InstructionSelectorMemoryAccessTest, LoadWithParameters) {
|
|
|
|
const MemoryAccess memacc = GetParam();
|
|
|
|
StreamBuilder m(this, memacc.type, kMachPtr, kMachInt32);
|
|
|
|
m.Return(m.Load(memacc.type, m.Parameter(0), m.Parameter(1)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(memacc.load_opcode, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(1U, s[0]->OutputCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_P(InstructionSelectorMemoryAccessTest, StoreWithParameters) {
|
|
|
|
const MemoryAccess memacc = GetParam();
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachPtr, kMachInt32, memacc.type);
|
|
|
|
m.Store(memacc.type, m.Parameter(0), m.Parameter(1), m.Parameter(2));
|
|
|
|
m.Return(m.Int32Constant(0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(memacc.store_opcode, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(3U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(0U, s[0]->OutputCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(InstructionSelectorTest,
|
|
|
|
InstructionSelectorMemoryAccessTest,
|
|
|
|
::testing::ValuesIn(kMemoryAccesses));
|
|
|
|
|
2014-09-29 08:11:03 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
2014-10-31 06:41:07 +00:00
|
|
|
// ChangeUint32ToUint64.
|
2014-09-29 08:11:03 +00:00
|
|
|
|
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
namespace {
|
2014-09-29 08:11:03 +00:00
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
typedef Node* (RawMachineAssembler::*Constructor)(Node*, Node*);
|
2014-09-29 08:11:03 +00:00
|
|
|
|
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
struct BinaryOperation {
|
|
|
|
Constructor constructor;
|
|
|
|
const char* constructor_name;
|
|
|
|
};
|
2014-09-29 08:11:03 +00:00
|
|
|
|
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
std::ostream& operator<<(std::ostream& os, const BinaryOperation& bop) {
|
|
|
|
return os << bop.constructor_name;
|
2014-09-29 08:11:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
const BinaryOperation kWord32BinaryOperations[] = {
|
|
|
|
{&RawMachineAssembler::Word32And, "Word32And"},
|
|
|
|
{&RawMachineAssembler::Word32Or, "Word32Or"},
|
|
|
|
{&RawMachineAssembler::Word32Xor, "Word32Xor"},
|
|
|
|
{&RawMachineAssembler::Word32Shl, "Word32Shl"},
|
|
|
|
{&RawMachineAssembler::Word32Shr, "Word32Shr"},
|
|
|
|
{&RawMachineAssembler::Word32Sar, "Word32Sar"},
|
|
|
|
{&RawMachineAssembler::Word32Ror, "Word32Ror"},
|
|
|
|
{&RawMachineAssembler::Word32Equal, "Word32Equal"},
|
|
|
|
{&RawMachineAssembler::Int32Add, "Int32Add"},
|
|
|
|
{&RawMachineAssembler::Int32Sub, "Int32Sub"},
|
|
|
|
{&RawMachineAssembler::Int32Mul, "Int32Mul"},
|
|
|
|
{&RawMachineAssembler::Int32MulHigh, "Int32MulHigh"},
|
|
|
|
{&RawMachineAssembler::Int32Div, "Int32Div"},
|
|
|
|
{&RawMachineAssembler::Int32LessThan, "Int32LessThan"},
|
|
|
|
{&RawMachineAssembler::Int32LessThanOrEqual, "Int32LessThanOrEqual"},
|
|
|
|
{&RawMachineAssembler::Int32Mod, "Int32Mod"},
|
|
|
|
{&RawMachineAssembler::Uint32Div, "Uint32Div"},
|
|
|
|
{&RawMachineAssembler::Uint32LessThan, "Uint32LessThan"},
|
|
|
|
{&RawMachineAssembler::Uint32LessThanOrEqual, "Uint32LessThanOrEqual"},
|
|
|
|
{&RawMachineAssembler::Uint32Mod, "Uint32Mod"}};
|
2014-09-29 08:11:03 +00:00
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
} // namespace
|
2014-09-29 08:11:03 +00:00
|
|
|
|
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
typedef InstructionSelectorTestWithParam<BinaryOperation>
|
|
|
|
InstructionSelectorChangeUint32ToUint64Test;
|
2014-09-29 08:11:03 +00:00
|
|
|
|
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
TEST_P(InstructionSelectorChangeUint32ToUint64Test, ChangeUint32ToUint64) {
|
|
|
|
const BinaryOperation& bop = GetParam();
|
|
|
|
StreamBuilder m(this, kMachUint64, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
m.Return(m.ChangeUint32ToUint64((m.*bop.constructor)(p0, p1)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
2014-09-29 08:11:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
INSTANTIATE_TEST_CASE_P(InstructionSelectorTest,
|
|
|
|
InstructionSelectorChangeUint32ToUint64Test,
|
|
|
|
::testing::ValuesIn(kWord32BinaryOperations));
|
2014-09-29 08:11:03 +00:00
|
|
|
|
2014-09-30 09:46:30 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2014-10-31 06:41:07 +00:00
|
|
|
// TruncateInt64ToInt32.
|
2014-09-30 09:46:30 +00:00
|
|
|
|
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
TEST_F(InstructionSelectorTest, TruncateInt64ToInt32WithWord64Sar) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt64);
|
|
|
|
Node* const p = m.Parameter(0);
|
|
|
|
Node* const t = m.TruncateInt64ToInt32(m.Word64Sar(p, m.Int64Constant(32)));
|
|
|
|
m.Return(t);
|
2014-09-30 09:46:30 +00:00
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
2014-10-31 06:41:07 +00:00
|
|
|
EXPECT_EQ(kX64Shr, s[0]->arch_opcode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(32, s.ToInt32(s[0]->InputAt(1)));
|
|
|
|
ASSERT_EQ(1U, s[0]->OutputCount());
|
|
|
|
EXPECT_TRUE(s.IsSameAsFirst(s[0]->OutputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(t), s.ToVreg(s[0]->OutputAt(0)));
|
2014-09-30 09:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
TEST_F(InstructionSelectorTest, TruncateInt64ToInt32WithWord64Shr) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt64);
|
|
|
|
Node* const p = m.Parameter(0);
|
|
|
|
Node* const t = m.TruncateInt64ToInt32(m.Word64Shr(p, m.Int64Constant(32)));
|
|
|
|
m.Return(t);
|
2014-09-30 09:46:30 +00:00
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
2014-10-31 06:41:07 +00:00
|
|
|
EXPECT_EQ(kX64Shr, s[0]->arch_opcode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(32, s.ToInt32(s[0]->InputAt(1)));
|
|
|
|
ASSERT_EQ(1U, s[0]->OutputCount());
|
|
|
|
EXPECT_TRUE(s.IsSameAsFirst(s[0]->OutputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(t), s.ToVreg(s[0]->OutputAt(0)));
|
2014-09-30 09:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Addition.
|
2014-10-01 10:47:14 +00:00
|
|
|
|
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
TEST_F(InstructionSelectorTest, Int32AddWithInt32AddWithParameters) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const a0 = m.Int32Add(p0, p1);
|
|
|
|
m.Return(m.Int32Add(a0, p0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(2U, s.size());
|
2014-11-07 16:47:25 +00:00
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
2014-10-31 06:41:07 +00:00
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
2014-11-07 16:47:25 +00:00
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddConstantAsLea) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const c0 = m.Int32Constant(15);
|
|
|
|
m.Return(m.Int32Add(p0, c0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MRI, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddCommutedConstantAsLea) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const c0 = m.Int32Constant(15);
|
|
|
|
m.Return(m.Int32Add(c0, p0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MRI, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_TRUE(s[0]->InputAt(1)->IsImmediate());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled2Mul) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Int32Mul(p1, m.Int32Constant(2));
|
|
|
|
m.Return(m.Int32Add(p0, s0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR2, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddCommutedScaled2Mul) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Int32Mul(p1, m.Int32Constant(2));
|
|
|
|
m.Return(m.Int32Add(s0, p0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR2, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled2Shl) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Word32Shl(p1, m.Int32Constant(1));
|
|
|
|
m.Return(m.Int32Add(p0, s0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR2, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddCommutedScaled2Shl) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Word32Shl(p1, m.Int32Constant(1));
|
|
|
|
m.Return(m.Int32Add(s0, p0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR2, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled4Mul) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Int32Mul(p1, m.Int32Constant(4));
|
|
|
|
m.Return(m.Int32Add(p0, s0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR4, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled4Shl) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Word32Shl(p1, m.Int32Constant(2));
|
|
|
|
m.Return(m.Int32Add(p0, s0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR4, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled8Mul) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Int32Mul(p1, m.Int32Constant(8));
|
|
|
|
m.Return(m.Int32Add(p0, s0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR8, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled8Shl) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Word32Shl(p1, m.Int32Constant(3));
|
|
|
|
m.Return(m.Int32Add(p0, s0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR8, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled2MulWithConstant) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Int32Mul(p1, m.Int32Constant(2));
|
|
|
|
Node* const c0 = m.Int32Constant(15);
|
|
|
|
m.Return(m.Int32Add(c0, m.Int32Add(p0, s0)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR2I, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(3U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
EXPECT_TRUE(s[0]->InputAt(2)->IsImmediate());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled2MulWithConstantShuffle1) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Int32Mul(p1, m.Int32Constant(2));
|
|
|
|
Node* const c0 = m.Int32Constant(15);
|
|
|
|
m.Return(m.Int32Add(p0, m.Int32Add(s0, c0)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR2I, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(3U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
EXPECT_TRUE(s[0]->InputAt(2)->IsImmediate());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled2MulWithConstantShuffle2) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Int32Mul(p1, m.Int32Constant(2));
|
|
|
|
Node* const c0 = m.Int32Constant(15);
|
|
|
|
m.Return(m.Int32Add(s0, m.Int32Add(c0, p0)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR2I, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(3U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
EXPECT_TRUE(s[0]->InputAt(2)->IsImmediate());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled2MulWithConstantShuffle3) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Int32Mul(p1, m.Int32Constant(2));
|
|
|
|
Node* const c0 = m.Int32Constant(15);
|
|
|
|
m.Return(m.Int32Add(m.Int32Add(s0, c0), p0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR2I, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(3U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
EXPECT_TRUE(s[0]->InputAt(2)->IsImmediate());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled2MulWithConstantShuffle4) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Int32Mul(p1, m.Int32Constant(2));
|
|
|
|
Node* const c0 = m.Int32Constant(15);
|
|
|
|
m.Return(m.Int32Add(m.Int32Add(c0, p0), s0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR2I, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(3U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
EXPECT_TRUE(s[0]->InputAt(2)->IsImmediate());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled2MulWithConstantShuffle5) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Int32Mul(p1, m.Int32Constant(2));
|
|
|
|
Node* const c0 = m.Int32Constant(15);
|
|
|
|
m.Return(m.Int32Add(m.Int32Add(p0, s0), c0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR2I, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(3U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
EXPECT_TRUE(s[0]->InputAt(2)->IsImmediate());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled2ShlWithConstant) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Word32Shl(p1, m.Int32Constant(1));
|
|
|
|
Node* const c0 = m.Int32Constant(15);
|
|
|
|
m.Return(m.Int32Add(c0, m.Int32Add(p0, s0)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR2I, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(3U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
EXPECT_TRUE(s[0]->InputAt(2)->IsImmediate());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled4MulWithConstant) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Int32Mul(p1, m.Int32Constant(4));
|
|
|
|
Node* const c0 = m.Int32Constant(15);
|
|
|
|
m.Return(m.Int32Add(c0, m.Int32Add(p0, s0)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR4I, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(3U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
EXPECT_TRUE(s[0]->InputAt(2)->IsImmediate());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled4ShlWithConstant) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Word32Shl(p1, m.Int32Constant(2));
|
|
|
|
Node* const c0 = m.Int32Constant(15);
|
|
|
|
m.Return(m.Int32Add(c0, m.Int32Add(p0, s0)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR4I, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(3U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
EXPECT_TRUE(s[0]->InputAt(2)->IsImmediate());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled8MulWithConstant) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Int32Mul(p1, m.Int32Constant(8));
|
|
|
|
Node* const c0 = m.Int32Constant(15);
|
|
|
|
m.Return(m.Int32Add(c0, m.Int32Add(p0, s0)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR8I, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(3U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
EXPECT_TRUE(s[0]->InputAt(2)->IsImmediate());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32AddScaled8ShlWithConstant) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const s0 = m.Word32Shl(p1, m.Int32Constant(3));
|
|
|
|
Node* const c0 = m.Int32Constant(15);
|
|
|
|
m.Return(m.Int32Add(c0, m.Int32Add(p0, s0)));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Lea32, s[0]->arch_opcode());
|
|
|
|
EXPECT_EQ(kMode_MR8I, s[0]->addressing_mode());
|
|
|
|
ASSERT_EQ(3U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
EXPECT_TRUE(s[0]->InputAt(2)->IsImmediate());
|
2014-10-01 10:47:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-31 06:41:07 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Multiplication.
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32MulWithInt32MulWithParameters) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const m0 = m.Int32Mul(p0, p1);
|
|
|
|
m.Return(m.Int32Mul(m0, p0));
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(2U, s.size());
|
|
|
|
EXPECT_EQ(kX64Imul32, s[0]->arch_opcode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
ASSERT_EQ(1U, s[0]->OutputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(m0), s.ToVreg(s[0]->OutputAt(0)));
|
|
|
|
EXPECT_EQ(kX64Imul32, s[1]->arch_opcode());
|
|
|
|
ASSERT_EQ(2U, s[1]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[1]->InputAt(0)));
|
|
|
|
EXPECT_EQ(s.ToVreg(m0), s.ToVreg(s[1]->InputAt(1)));
|
|
|
|
}
|
2014-09-30 09:46:30 +00:00
|
|
|
|
2014-10-14 11:57:06 +00:00
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Int32MulHigh) {
|
|
|
|
StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const n = m.Int32MulHigh(p0, p1);
|
|
|
|
m.Return(n);
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64ImulHigh32, s[0]->arch_opcode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
2014-10-24 09:36:40 +00:00
|
|
|
EXPECT_TRUE(s.IsFixed(s[0]->InputAt(0), rax));
|
2014-10-14 11:57:06 +00:00
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
2014-10-24 09:36:40 +00:00
|
|
|
EXPECT_TRUE(!s.IsUsedAtStart(s[0]->InputAt(1)));
|
2014-11-03 10:04:37 +00:00
|
|
|
ASSERT_LE(1U, s[0]->OutputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
|
|
|
|
EXPECT_TRUE(s.IsFixed(s[0]->OutputAt(0), rdx));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Uint32MulHigh) {
|
|
|
|
StreamBuilder m(this, kMachUint32, kMachUint32, kMachUint32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const p1 = m.Parameter(1);
|
|
|
|
Node* const n = m.Uint32MulHigh(p0, p1);
|
|
|
|
m.Return(n);
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64UmulHigh32, s[0]->arch_opcode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_TRUE(s.IsFixed(s[0]->InputAt(0), rax));
|
|
|
|
EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
|
|
|
|
EXPECT_TRUE(!s.IsUsedAtStart(s[0]->InputAt(1)));
|
|
|
|
ASSERT_LE(1U, s[0]->OutputCount());
|
2014-10-14 11:57:06 +00:00
|
|
|
EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
|
2014-10-24 09:36:40 +00:00
|
|
|
EXPECT_TRUE(s.IsFixed(s[0]->OutputAt(0), rdx));
|
2014-10-14 11:57:06 +00:00
|
|
|
}
|
|
|
|
|
2014-11-05 05:57:56 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Word64Shl.
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Word64ShlWithChangeInt32ToInt64) {
|
|
|
|
TRACED_FORRANGE(int64_t, x, 32, 63) {
|
|
|
|
StreamBuilder m(this, kMachInt64, kMachInt32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const n = m.Word64Shl(m.ChangeInt32ToInt64(p0), m.Int64Constant(x));
|
|
|
|
m.Return(n);
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Shl, s[0]->arch_opcode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(x, s.ToInt32(s[0]->InputAt(1)));
|
|
|
|
ASSERT_EQ(1U, s[0]->OutputCount());
|
|
|
|
EXPECT_TRUE(s.IsSameAsFirst(s[0]->Output()));
|
|
|
|
EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(InstructionSelectorTest, Word64ShlWithChangeUint32ToUint64) {
|
|
|
|
TRACED_FORRANGE(int64_t, x, 32, 63) {
|
|
|
|
StreamBuilder m(this, kMachInt64, kMachUint32);
|
|
|
|
Node* const p0 = m.Parameter(0);
|
|
|
|
Node* const n = m.Word64Shl(m.ChangeUint32ToUint64(p0), m.Int64Constant(x));
|
|
|
|
m.Return(n);
|
|
|
|
Stream s = m.Build();
|
|
|
|
ASSERT_EQ(1U, s.size());
|
|
|
|
EXPECT_EQ(kX64Shl, s[0]->arch_opcode());
|
|
|
|
ASSERT_EQ(2U, s[0]->InputCount());
|
|
|
|
EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
|
|
|
|
EXPECT_EQ(x, s.ToInt32(s[0]->InputAt(1)));
|
|
|
|
ASSERT_EQ(1U, s[0]->OutputCount());
|
|
|
|
EXPECT_TRUE(s.IsSameAsFirst(s[0]->Output()));
|
|
|
|
EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-19 08:48:41 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|