Index: test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc |
diff --git a/test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc b/test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc |
index 68a5b3359dd972f3a3214c5426b57ffc18f681eb..e52d1d583562c82796cde1f8f011f08063da62be 100644 |
--- a/test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc |
+++ b/test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc |
@@ -1641,6 +1641,102 @@ TEST_F(InstructionSelectorTest, Int32MulWithImmediate) { |
EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2))); |
EXPECT_EQ(1U, s[0]->OutputCount()); |
} |
+ // x * (2^k + 1) + c -> x + (x << k) + c |
+ TRACED_FORRANGE(int32_t, k, 1, 30) { |
+ StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
+ m.Return( |
+ m.Int32Add(m.Int32Mul(m.Parameter(0), m.Int32Constant((1 << k) + 1)), |
+ m.Parameter(1))); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(2U, s.size()); |
+ EXPECT_EQ(kArm64Add32, s[0]->arch_opcode()); |
+ EXPECT_EQ(kArm64Add32, s[1]->arch_opcode()); |
+ EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); |
+ ASSERT_EQ(3U, s[0]->InputCount()); |
+ EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); |
+ EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2))); |
+ EXPECT_EQ(1U, s[0]->OutputCount()); |
+ } |
+ // (2^k + 1) * x + c -> x + (x << k) + c |
+ TRACED_FORRANGE(int32_t, k, 1, 30) { |
+ StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
+ m.Return( |
+ m.Int32Add(m.Int32Mul(m.Int32Constant((1 << k) + 1), m.Parameter(0)), |
+ m.Parameter(1))); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(2U, s.size()); |
+ EXPECT_EQ(kArm64Add32, s[0]->arch_opcode()); |
+ EXPECT_EQ(kArm64Add32, s[1]->arch_opcode()); |
+ EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); |
+ ASSERT_EQ(3U, s[0]->InputCount()); |
+ EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); |
+ EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2))); |
+ EXPECT_EQ(1U, s[0]->OutputCount()); |
+ } |
+ // c + x * (2^k + 1) -> c + x + (x << k) |
+ TRACED_FORRANGE(int32_t, k, 1, 30) { |
+ StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
+ m.Return( |
+ m.Int32Add(m.Parameter(0), |
+ m.Int32Mul(m.Parameter(1), m.Int32Constant((1 << k) + 1)))); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(2U, s.size()); |
+ EXPECT_EQ(kArm64Add32, s[0]->arch_opcode()); |
+ EXPECT_EQ(kArm64Add32, s[1]->arch_opcode()); |
+ EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); |
+ ASSERT_EQ(3U, s[0]->InputCount()); |
+ EXPECT_EQ(s.ToVreg(s[0]->InputAt(1)), s.ToVreg(s[0]->InputAt(1))); |
+ EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2))); |
+ EXPECT_EQ(1U, s[0]->OutputCount()); |
+ } |
+ // c + (2^k + 1) * x -> c + x + (x << k) |
+ TRACED_FORRANGE(int32_t, k, 1, 30) { |
+ StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
+ m.Return( |
+ m.Int32Add(m.Parameter(0), |
+ m.Int32Mul(m.Int32Constant((1 << k) + 1), m.Parameter(1)))); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(2U, s.size()); |
+ EXPECT_EQ(kArm64Add32, s[0]->arch_opcode()); |
+ EXPECT_EQ(kArm64Add32, s[1]->arch_opcode()); |
+ EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); |
+ ASSERT_EQ(3U, s[0]->InputCount()); |
+ EXPECT_EQ(s.ToVreg(s[0]->InputAt(1)), s.ToVreg(s[0]->InputAt(1))); |
+ EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2))); |
+ EXPECT_EQ(1U, s[0]->OutputCount()); |
+ } |
+ // c - x * (2^k + 1) -> c - x + (x << k) |
+ TRACED_FORRANGE(int32_t, k, 1, 30) { |
+ StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
+ m.Return( |
+ m.Int32Sub(m.Parameter(0), |
+ m.Int32Mul(m.Parameter(1), m.Int32Constant((1 << k) + 1)))); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(2U, s.size()); |
+ EXPECT_EQ(kArm64Add32, s[0]->arch_opcode()); |
+ EXPECT_EQ(kArm64Sub32, s[1]->arch_opcode()); |
+ EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); |
+ ASSERT_EQ(3U, s[0]->InputCount()); |
+ EXPECT_EQ(s.ToVreg(s[0]->InputAt(1)), s.ToVreg(s[0]->InputAt(1))); |
+ EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2))); |
+ EXPECT_EQ(1U, s[0]->OutputCount()); |
+ } |
+ // c - (2^k + 1) * x -> c - x + (x << k) |
+ TRACED_FORRANGE(int32_t, k, 1, 30) { |
+ StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
+ m.Return( |
+ m.Int32Sub(m.Parameter(0), |
+ m.Int32Mul(m.Int32Constant((1 << k) + 1), m.Parameter(1)))); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(2U, s.size()); |
+ EXPECT_EQ(kArm64Add32, s[0]->arch_opcode()); |
+ EXPECT_EQ(kArm64Sub32, s[1]->arch_opcode()); |
+ EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); |
+ ASSERT_EQ(3U, s[0]->InputCount()); |
+ EXPECT_EQ(s.ToVreg(s[0]->InputAt(1)), s.ToVreg(s[0]->InputAt(1))); |
+ EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2))); |
+ EXPECT_EQ(1U, s[0]->OutputCount()); |
+ } |
} |
@@ -1671,6 +1767,102 @@ TEST_F(InstructionSelectorTest, Int64MulWithImmediate) { |
EXPECT_EQ(k, s.ToInt64(s[0]->InputAt(2))); |
EXPECT_EQ(1U, s[0]->OutputCount()); |
} |
+ // x * (2^k + 1) + c -> x + (x << k) + c |
+ TRACED_FORRANGE(int64_t, k, 1, 62) { |
+ StreamBuilder m(this, kMachInt64, kMachInt64, kMachInt64); |
+ m.Return( |
+ m.Int64Add(m.Int64Mul(m.Parameter(0), m.Int64Constant((1L << k) + 1)), |
+ m.Parameter(1))); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(2U, s.size()); |
+ EXPECT_EQ(kArm64Add, s[0]->arch_opcode()); |
+ EXPECT_EQ(kArm64Add, s[1]->arch_opcode()); |
+ EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); |
+ ASSERT_EQ(3U, s[0]->InputCount()); |
+ EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); |
+ EXPECT_EQ(k, s.ToInt64(s[0]->InputAt(2))); |
+ EXPECT_EQ(1U, s[0]->OutputCount()); |
+ } |
+ // (2^k + 1) * x + c -> x + (x << k) + c |
+ TRACED_FORRANGE(int64_t, k, 1, 62) { |
+ StreamBuilder m(this, kMachInt64, kMachInt64, kMachInt64); |
+ m.Return( |
+ m.Int64Add(m.Int64Mul(m.Int64Constant((1L << k) + 1), m.Parameter(0)), |
+ m.Parameter(1))); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(2U, s.size()); |
+ EXPECT_EQ(kArm64Add, s[0]->arch_opcode()); |
+ EXPECT_EQ(kArm64Add, s[1]->arch_opcode()); |
+ EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); |
+ ASSERT_EQ(3U, s[0]->InputCount()); |
+ EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); |
+ EXPECT_EQ(k, s.ToInt64(s[0]->InputAt(2))); |
+ EXPECT_EQ(1U, s[0]->OutputCount()); |
+ } |
+ // c + x * (2^k + 1) -> c + x + (x << k) |
+ TRACED_FORRANGE(int64_t, k, 1, 62) { |
+ StreamBuilder m(this, kMachInt64, kMachInt64, kMachInt64); |
+ m.Return( |
+ m.Int64Add(m.Parameter(0), |
+ m.Int64Mul(m.Parameter(1), m.Int64Constant((1L << k) + 1)))); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(2U, s.size()); |
+ EXPECT_EQ(kArm64Add, s[0]->arch_opcode()); |
+ EXPECT_EQ(kArm64Add, s[1]->arch_opcode()); |
+ EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); |
+ ASSERT_EQ(3U, s[0]->InputCount()); |
+ EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); |
+ EXPECT_EQ(k, s.ToInt64(s[0]->InputAt(2))); |
+ EXPECT_EQ(1U, s[0]->OutputCount()); |
+ } |
+ // c + (2^k + 1) * x -> c + x + (x << k) |
+ TRACED_FORRANGE(int64_t, k, 1, 62) { |
+ StreamBuilder m(this, kMachInt64, kMachInt64, kMachInt64); |
+ m.Return( |
+ m.Int64Add(m.Parameter(0), |
+ m.Int64Mul(m.Int64Constant((1L << k) + 1), m.Parameter(1)))); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(2U, s.size()); |
+ EXPECT_EQ(kArm64Add, s[0]->arch_opcode()); |
+ EXPECT_EQ(kArm64Add, s[1]->arch_opcode()); |
+ EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); |
+ ASSERT_EQ(3U, s[0]->InputCount()); |
+ EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); |
+ EXPECT_EQ(k, s.ToInt64(s[0]->InputAt(2))); |
+ EXPECT_EQ(1U, s[0]->OutputCount()); |
+ } |
+ // c - x * (2^k + 1) -> c - x + (x << k) |
+ TRACED_FORRANGE(int64_t, k, 1, 62) { |
+ StreamBuilder m(this, kMachInt64, kMachInt64, kMachInt64); |
+ m.Return( |
+ m.Int64Sub(m.Parameter(0), |
+ m.Int64Mul(m.Parameter(1), m.Int64Constant((1L << k) + 1)))); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(2U, s.size()); |
+ EXPECT_EQ(kArm64Add, s[0]->arch_opcode()); |
+ EXPECT_EQ(kArm64Sub, s[1]->arch_opcode()); |
+ EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); |
+ ASSERT_EQ(3U, s[0]->InputCount()); |
+ EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); |
+ EXPECT_EQ(k, s.ToInt64(s[0]->InputAt(2))); |
+ EXPECT_EQ(1U, s[0]->OutputCount()); |
+ } |
+ // c - (2^k + 1) * x -> c - x + (x << k) |
+ TRACED_FORRANGE(int64_t, k, 1, 62) { |
+ StreamBuilder m(this, kMachInt64, kMachInt64, kMachInt64); |
+ m.Return( |
+ m.Int64Sub(m.Parameter(0), |
+ m.Int64Mul(m.Int64Constant((1L << k) + 1), m.Parameter(1)))); |
+ Stream s = m.Build(); |
+ ASSERT_EQ(2U, s.size()); |
+ EXPECT_EQ(kArm64Add, s[0]->arch_opcode()); |
+ EXPECT_EQ(kArm64Sub, s[1]->arch_opcode()); |
+ EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); |
+ ASSERT_EQ(3U, s[0]->InputCount()); |
+ EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); |
+ EXPECT_EQ(k, s.ToInt64(s[0]->InputAt(2))); |
+ EXPECT_EQ(1U, s[0]->OutputCount()); |
+ } |
} |