1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "test/unittests/compiler/instruction-selector-unittest.h"
13 // Immediates (random subset).
14 const int32_t kImmediates[] = {kMinInt, -42, -1, 0, 1, 2,
16 16, 42, 0xff, 0xffff, 0x0f0f0f0f, kMaxInt};
21 TEST_F(InstructionSelectorTest, Int32AddWithParameter) {
22 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
23 m.Return(m.Int32Add(m.Parameter(0), m.Parameter(1)));
25 ASSERT_EQ(1U, s.size());
26 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode());
30 TEST_F(InstructionSelectorTest, Int32AddWithImmediate) {
31 TRACED_FOREACH(int32_t, imm, kImmediates) {
33 StreamBuilder m(this, kMachInt32, kMachInt32);
34 m.Return(m.Int32Add(m.Parameter(0), m.Int32Constant(imm)));
36 ASSERT_EQ(1U, s.size());
37 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode());
39 ASSERT_EQ(1U, s[0]->InputCount());
41 ASSERT_EQ(2U, s[0]->InputCount());
42 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1)));
46 StreamBuilder m(this, kMachInt32, kMachInt32);
47 m.Return(m.Int32Add(m.Int32Constant(imm), m.Parameter(0)));
49 ASSERT_EQ(1U, s.size());
50 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode());
52 ASSERT_EQ(1U, s[0]->InputCount());
54 ASSERT_EQ(2U, s[0]->InputCount());
55 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1)));
62 TEST_F(InstructionSelectorTest, Int32SubWithParameter) {
63 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
64 m.Return(m.Int32Sub(m.Parameter(0), m.Parameter(1)));
66 ASSERT_EQ(1U, s.size());
67 EXPECT_EQ(kIA32Sub, s[0]->arch_opcode());
68 EXPECT_EQ(1U, s[0]->OutputCount());
72 TEST_F(InstructionSelectorTest, Int32SubWithImmediate) {
73 TRACED_FOREACH(int32_t, imm, kImmediates) {
74 StreamBuilder m(this, kMachInt32, kMachInt32);
75 m.Return(m.Int32Sub(m.Parameter(0), m.Int32Constant(imm)));
77 ASSERT_EQ(1U, s.size());
78 EXPECT_EQ(kIA32Sub, s[0]->arch_opcode());
79 ASSERT_EQ(2U, s[0]->InputCount());
80 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1)));
85 // -----------------------------------------------------------------------------
89 TEST_F(InstructionSelectorTest, ChangeFloat32ToFloat64WithParameter) {
90 StreamBuilder m(this, kMachFloat32, kMachFloat64);
91 m.Return(m.ChangeFloat32ToFloat64(m.Parameter(0)));
93 ASSERT_EQ(1U, s.size());
94 EXPECT_EQ(kSSECvtss2sd, s[0]->arch_opcode());
95 EXPECT_EQ(1U, s[0]->InputCount());
96 EXPECT_EQ(1U, s[0]->OutputCount());
100 TEST_F(InstructionSelectorTest, TruncateFloat64ToFloat32WithParameter) {
101 StreamBuilder m(this, kMachFloat64, kMachFloat32);
102 m.Return(m.TruncateFloat64ToFloat32(m.Parameter(0)));
103 Stream s = m.Build();
104 ASSERT_EQ(1U, s.size());
105 EXPECT_EQ(kSSECvtsd2ss, s[0]->arch_opcode());
106 EXPECT_EQ(1U, s[0]->InputCount());
107 EXPECT_EQ(1U, s[0]->OutputCount());
111 // -----------------------------------------------------------------------------
112 // Better left operand for commutative binops
115 TEST_F(InstructionSelectorTest, BetterLeftOperandTestAddBinop) {
116 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
117 Node* param1 = m.Parameter(0);
118 Node* param2 = m.Parameter(1);
119 Node* add = m.Int32Add(param1, param2);
120 m.Return(m.Int32Add(add, param1));
121 Stream s = m.Build();
122 ASSERT_EQ(2U, s.size());
123 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode());
124 ASSERT_EQ(2U, s[0]->InputCount());
125 ASSERT_TRUE(s[0]->InputAt(0)->IsUnallocated());
126 EXPECT_EQ(s.ToVreg(param1), s.ToVreg(s[0]->InputAt(0)));
127 EXPECT_EQ(s.ToVreg(param2), s.ToVreg(s[0]->InputAt(1)));
128 ASSERT_EQ(2U, s[1]->InputCount());
129 EXPECT_EQ(s.ToVreg(param1), s.ToVreg(s[0]->InputAt(0)));
133 TEST_F(InstructionSelectorTest, BetterLeftOperandTestMulBinop) {
134 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
135 Node* param1 = m.Parameter(0);
136 Node* param2 = m.Parameter(1);
137 Node* mul = m.Int32Mul(param1, param2);
138 m.Return(m.Int32Mul(mul, param1));
139 Stream s = m.Build();
140 ASSERT_EQ(2U, s.size());
141 EXPECT_EQ(kIA32Imul, s[0]->arch_opcode());
142 ASSERT_EQ(2U, s[0]->InputCount());
143 ASSERT_TRUE(s[0]->InputAt(0)->IsUnallocated());
144 EXPECT_EQ(s.ToVreg(param2), s.ToVreg(s[0]->InputAt(0)));
145 EXPECT_EQ(s.ToVreg(param1), s.ToVreg(s[0]->InputAt(1)));
149 // -----------------------------------------------------------------------------
153 TEST_F(InstructionSelectorTest, ChangeUint32ToFloat64WithParameter) {
154 StreamBuilder m(this, kMachFloat64, kMachUint32);
155 m.Return(m.ChangeUint32ToFloat64(m.Parameter(0)));
156 Stream s = m.Build();
157 ASSERT_EQ(1U, s.size());
158 EXPECT_EQ(kSSEUint32ToFloat64, s[0]->arch_opcode());
162 // -----------------------------------------------------------------------------
168 struct MemoryAccess {
170 ArchOpcode load_opcode;
171 ArchOpcode store_opcode;
175 std::ostream& operator<<(std::ostream& os, const MemoryAccess& memacc) {
176 return os << memacc.type;
180 static const MemoryAccess kMemoryAccesses[] = {
181 {kMachInt8, kIA32Movsxbl, kIA32Movb},
182 {kMachUint8, kIA32Movzxbl, kIA32Movb},
183 {kMachInt16, kIA32Movsxwl, kIA32Movw},
184 {kMachUint16, kIA32Movzxwl, kIA32Movw},
185 {kMachInt32, kIA32Movl, kIA32Movl},
186 {kMachUint32, kIA32Movl, kIA32Movl},
187 {kMachFloat32, kIA32Movss, kIA32Movss},
188 {kMachFloat64, kIA32Movsd, kIA32Movsd}};
193 typedef InstructionSelectorTestWithParam<MemoryAccess>
194 InstructionSelectorMemoryAccessTest;
197 TEST_P(InstructionSelectorMemoryAccessTest, LoadWithParameters) {
198 const MemoryAccess memacc = GetParam();
199 StreamBuilder m(this, memacc.type, kMachPtr, kMachInt32);
200 m.Return(m.Load(memacc.type, m.Parameter(0), m.Parameter(1)));
201 Stream s = m.Build();
202 ASSERT_EQ(1U, s.size());
203 EXPECT_EQ(memacc.load_opcode, s[0]->arch_opcode());
204 EXPECT_EQ(2U, s[0]->InputCount());
205 EXPECT_EQ(1U, s[0]->OutputCount());
209 TEST_P(InstructionSelectorMemoryAccessTest, LoadWithImmediateBase) {
210 const MemoryAccess memacc = GetParam();
211 TRACED_FOREACH(int32_t, base, kImmediates) {
212 StreamBuilder m(this, memacc.type, kMachPtr);
213 m.Return(m.Load(memacc.type, m.Int32Constant(base), m.Parameter(0)));
214 Stream s = m.Build();
215 ASSERT_EQ(1U, s.size());
216 EXPECT_EQ(memacc.load_opcode, s[0]->arch_opcode());
218 ASSERT_EQ(1U, s[0]->InputCount());
220 ASSERT_EQ(2U, s[0]->InputCount());
221 ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind());
222 EXPECT_EQ(base, s.ToInt32(s[0]->InputAt(1)));
224 EXPECT_EQ(1U, s[0]->OutputCount());
229 TEST_P(InstructionSelectorMemoryAccessTest, LoadWithImmediateIndex) {
230 const MemoryAccess memacc = GetParam();
231 TRACED_FOREACH(int32_t, index, kImmediates) {
232 StreamBuilder m(this, memacc.type, kMachPtr);
233 m.Return(m.Load(memacc.type, m.Parameter(0), m.Int32Constant(index)));
234 Stream s = m.Build();
235 ASSERT_EQ(1U, s.size());
236 EXPECT_EQ(memacc.load_opcode, s[0]->arch_opcode());
238 ASSERT_EQ(1U, s[0]->InputCount());
240 ASSERT_EQ(2U, s[0]->InputCount());
241 ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind());
242 EXPECT_EQ(index, s.ToInt32(s[0]->InputAt(1)));
244 EXPECT_EQ(1U, s[0]->OutputCount());
249 TEST_P(InstructionSelectorMemoryAccessTest, StoreWithParameters) {
250 const MemoryAccess memacc = GetParam();
251 StreamBuilder m(this, kMachInt32, kMachPtr, kMachInt32, memacc.type);
252 m.Store(memacc.type, m.Parameter(0), m.Parameter(1), m.Parameter(2));
253 m.Return(m.Int32Constant(0));
254 Stream s = m.Build();
255 ASSERT_EQ(1U, s.size());
256 EXPECT_EQ(memacc.store_opcode, s[0]->arch_opcode());
257 EXPECT_EQ(3U, s[0]->InputCount());
258 EXPECT_EQ(0U, s[0]->OutputCount());
262 TEST_P(InstructionSelectorMemoryAccessTest, StoreWithImmediateBase) {
263 const MemoryAccess memacc = GetParam();
264 TRACED_FOREACH(int32_t, base, kImmediates) {
265 StreamBuilder m(this, kMachInt32, kMachInt32, memacc.type);
266 m.Store(memacc.type, m.Int32Constant(base), m.Parameter(0), m.Parameter(1));
267 m.Return(m.Int32Constant(0));
268 Stream s = m.Build();
269 ASSERT_EQ(1U, s.size());
270 EXPECT_EQ(memacc.store_opcode, s[0]->arch_opcode());
272 ASSERT_EQ(2U, s[0]->InputCount());
274 ASSERT_EQ(3U, s[0]->InputCount());
275 ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind());
276 EXPECT_EQ(base, s.ToInt32(s[0]->InputAt(1)));
278 EXPECT_EQ(0U, s[0]->OutputCount());
283 TEST_P(InstructionSelectorMemoryAccessTest, StoreWithImmediateIndex) {
284 const MemoryAccess memacc = GetParam();
285 TRACED_FOREACH(int32_t, index, kImmediates) {
286 StreamBuilder m(this, kMachInt32, kMachPtr, memacc.type);
287 m.Store(memacc.type, m.Parameter(0), m.Int32Constant(index),
289 m.Return(m.Int32Constant(0));
290 Stream s = m.Build();
291 ASSERT_EQ(1U, s.size());
292 EXPECT_EQ(memacc.store_opcode, s[0]->arch_opcode());
294 ASSERT_EQ(2U, s[0]->InputCount());
296 ASSERT_EQ(3U, s[0]->InputCount());
297 ASSERT_EQ(InstructionOperand::IMMEDIATE, s[0]->InputAt(1)->kind());
298 EXPECT_EQ(index, s.ToInt32(s[0]->InputAt(1)));
300 EXPECT_EQ(0U, s[0]->OutputCount());
305 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest,
306 InstructionSelectorMemoryAccessTest,
307 ::testing::ValuesIn(kMemoryAccesses));
310 // -----------------------------------------------------------------------------
311 // AddressingMode for loads and stores.
314 class AddressingModeUnitTest : public InstructionSelectorTest {
316 AddressingModeUnitTest() : m(NULL) { Reset(); }
317 ~AddressingModeUnitTest() { delete m; }
319 void Run(Node* base, Node* load_index, Node* store_index,
320 AddressingMode mode) {
321 Node* load = m->Load(kMachInt32, base, load_index);
322 m->Store(kMachInt32, base, store_index, load);
323 m->Return(m->Int32Constant(0));
324 Stream s = m->Build();
325 ASSERT_EQ(2U, s.size());
326 EXPECT_EQ(mode, s[0]->addressing_mode());
327 EXPECT_EQ(mode, s[1]->addressing_mode());
333 Node* base_reg; // opaque value to generate base as register
334 Node* index_reg; // opaque value to generate index as register
340 m = new StreamBuilder(this, kMachInt32, kMachInt32, kMachInt32);
341 zero = m->Int32Constant(0);
342 null_ptr = m->Int32Constant(0);
343 non_zero = m->Int32Constant(127);
344 base_reg = m->Parameter(0);
345 index_reg = m->Parameter(0);
347 scales[0] = m->Int32Constant(1);
348 scales[1] = m->Int32Constant(2);
349 scales[2] = m->Int32Constant(4);
350 scales[3] = m->Int32Constant(8);
355 TEST_F(AddressingModeUnitTest, AddressingMode_MR) {
356 Node* base = base_reg;
358 Run(base, index, index, kMode_MR);
362 TEST_F(AddressingModeUnitTest, AddressingMode_MRI) {
363 Node* base = base_reg;
364 Node* index = non_zero;
365 Run(base, index, index, kMode_MRI);
369 TEST_F(AddressingModeUnitTest, AddressingMode_MR1) {
370 Node* base = base_reg;
371 Node* index = index_reg;
372 Run(base, index, index, kMode_MR1);
376 TEST_F(AddressingModeUnitTest, AddressingMode_MRN) {
377 AddressingMode expected[] = {kMode_MR1, kMode_MR2, kMode_MR4, kMode_MR8};
378 for (size_t i = 0; i < arraysize(scales); ++i) {
380 Node* base = base_reg;
381 Node* load_index = m->Int32Mul(index_reg, scales[i]);
382 Node* store_index = m->Int32Mul(index_reg, scales[i]);
383 Run(base, load_index, store_index, expected[i]);
388 TEST_F(AddressingModeUnitTest, AddressingMode_MR1I) {
389 Node* base = base_reg;
390 Node* load_index = m->Int32Add(index_reg, non_zero);
391 Node* store_index = m->Int32Add(index_reg, non_zero);
392 Run(base, load_index, store_index, kMode_MR1I);
396 TEST_F(AddressingModeUnitTest, AddressingMode_MRNI) {
397 AddressingMode expected[] = {kMode_MR1I, kMode_MR2I, kMode_MR4I, kMode_MR8I};
398 for (size_t i = 0; i < arraysize(scales); ++i) {
400 Node* base = base_reg;
401 Node* load_index = m->Int32Add(m->Int32Mul(index_reg, scales[i]), non_zero);
403 m->Int32Add(m->Int32Mul(index_reg, scales[i]), non_zero);
404 Run(base, load_index, store_index, expected[i]);
409 TEST_F(AddressingModeUnitTest, AddressingMode_M1ToMR) {
410 Node* base = null_ptr;
411 Node* index = index_reg;
413 Run(base, index, index, kMode_MR);
417 TEST_F(AddressingModeUnitTest, AddressingMode_MN) {
418 AddressingMode expected[] = {kMode_MR, kMode_M2, kMode_M4, kMode_M8};
419 for (size_t i = 0; i < arraysize(scales); ++i) {
421 Node* base = null_ptr;
422 Node* load_index = m->Int32Mul(index_reg, scales[i]);
423 Node* store_index = m->Int32Mul(index_reg, scales[i]);
424 Run(base, load_index, store_index, expected[i]);
429 TEST_F(AddressingModeUnitTest, AddressingMode_M1IToMRI) {
430 Node* base = null_ptr;
431 Node* load_index = m->Int32Add(index_reg, non_zero);
432 Node* store_index = m->Int32Add(index_reg, non_zero);
434 Run(base, load_index, store_index, kMode_MRI);
438 TEST_F(AddressingModeUnitTest, AddressingMode_MNI) {
439 AddressingMode expected[] = {kMode_MRI, kMode_M2I, kMode_M4I, kMode_M8I};
440 for (size_t i = 0; i < arraysize(scales); ++i) {
442 Node* base = null_ptr;
443 Node* load_index = m->Int32Add(m->Int32Mul(index_reg, scales[i]), non_zero);
445 m->Int32Add(m->Int32Mul(index_reg, scales[i]), non_zero);
446 Run(base, load_index, store_index, expected[i]);
451 TEST_F(AddressingModeUnitTest, AddressingMode_MI) {
452 Node* bases[] = {null_ptr, non_zero};
453 Node* indices[] = {zero, non_zero};
454 for (size_t i = 0; i < arraysize(bases); ++i) {
455 for (size_t j = 0; j < arraysize(indices); ++j) {
457 Node* base = bases[i];
458 Node* index = indices[j];
459 Run(base, index, index, kMode_MI);
465 // -----------------------------------------------------------------------------
474 AddressingMode addressing_mode;
478 std::ostream& operator<<(std::ostream& os, const MultParam& m) {
479 return os << m.value << "." << m.lea_expected << "." << m.addressing_mode;
483 const MultParam kMultParams[] = {{-1, false, kMode_None},
484 {0, false, kMode_None},
487 {3, true, kMode_MR2},
489 {5, true, kMode_MR4},
490 {6, false, kMode_None},
491 {7, false, kMode_None},
493 {9, true, kMode_MR8},
494 {10, false, kMode_None},
495 {11, false, kMode_None}};
500 typedef InstructionSelectorTestWithParam<MultParam> InstructionSelectorMultTest;
503 static unsigned InputCountForLea(AddressingMode mode) {
535 static AddressingMode AddressingModeForAddMult(int32_t imm,
536 const MultParam& m) {
537 if (imm == 0) return m.addressing_mode;
538 switch (m.addressing_mode) {
564 TEST_P(InstructionSelectorMultTest, Mult32) {
565 const MultParam m_param = GetParam();
566 StreamBuilder m(this, kMachInt32, kMachInt32);
567 Node* param = m.Parameter(0);
568 Node* mult = m.Int32Mul(param, m.Int32Constant(m_param.value));
570 Stream s = m.Build();
571 ASSERT_EQ(1U, s.size());
572 EXPECT_EQ(m_param.addressing_mode, s[0]->addressing_mode());
573 if (m_param.lea_expected) {
574 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode());
575 ASSERT_EQ(InputCountForLea(s[0]->addressing_mode()), s[0]->InputCount());
577 EXPECT_EQ(kIA32Imul, s[0]->arch_opcode());
578 ASSERT_EQ(2U, s[0]->InputCount());
580 EXPECT_EQ(s.ToVreg(param), s.ToVreg(s[0]->InputAt(0)));
584 TEST_P(InstructionSelectorMultTest, MultAdd32) {
585 TRACED_FOREACH(int32_t, imm, kImmediates) {
586 const MultParam m_param = GetParam();
587 StreamBuilder m(this, kMachInt32, kMachInt32);
588 Node* param = m.Parameter(0);
589 Node* mult = m.Int32Add(m.Int32Mul(param, m.Int32Constant(m_param.value)),
590 m.Int32Constant(imm));
592 Stream s = m.Build();
593 if (m_param.lea_expected) {
594 ASSERT_EQ(1U, s.size());
595 EXPECT_EQ(kIA32Lea, s[0]->arch_opcode());
596 EXPECT_EQ(AddressingModeForAddMult(imm, m_param),
597 s[0]->addressing_mode());
598 unsigned input_count = InputCountForLea(s[0]->addressing_mode());
599 ASSERT_EQ(input_count, s[0]->InputCount());
601 ASSERT_EQ(InstructionOperand::IMMEDIATE,
602 s[0]->InputAt(input_count - 1)->kind());
603 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(input_count - 1)));
606 ASSERT_EQ(2U, s.size());
607 EXPECT_EQ(kIA32Imul, s[0]->arch_opcode());
608 EXPECT_EQ(kIA32Lea, s[1]->arch_opcode());
614 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, InstructionSelectorMultTest,
615 ::testing::ValuesIn(kMultParams));
618 TEST_F(InstructionSelectorTest, Int32MulHigh) {
619 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
620 Node* const p0 = m.Parameter(0);
621 Node* const p1 = m.Parameter(1);
622 Node* const n = m.Int32MulHigh(p0, p1);
624 Stream s = m.Build();
625 ASSERT_EQ(1U, s.size());
626 EXPECT_EQ(kIA32ImulHigh, s[0]->arch_opcode());
627 ASSERT_EQ(2U, s[0]->InputCount());
628 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
629 EXPECT_TRUE(s.IsFixed(s[0]->InputAt(0), eax));
630 EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
631 EXPECT_TRUE(!s.IsUsedAtStart(s[0]->InputAt(1)));
632 ASSERT_EQ(1U, s[0]->OutputCount());
633 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
634 EXPECT_TRUE(s.IsFixed(s[0]->OutputAt(0), edx));
638 TEST_F(InstructionSelectorTest, Float64BinopArithmetic) {
640 StreamBuilder m(this, kMachFloat64, kMachFloat64, kMachFloat64);
641 Node* add = m.Float64Add(m.Parameter(0), m.Parameter(1));
642 Node* mul = m.Float64Mul(add, m.Parameter(1));
643 Node* sub = m.Float64Sub(mul, add);
644 Node* ret = m.Float64Div(mul, sub);
646 Stream s = m.Build(AVX);
647 ASSERT_EQ(4U, s.size());
648 EXPECT_EQ(kAVXFloat64Add, s[0]->arch_opcode());
649 EXPECT_EQ(kAVXFloat64Mul, s[1]->arch_opcode());
650 EXPECT_EQ(kAVXFloat64Sub, s[2]->arch_opcode());
651 EXPECT_EQ(kAVXFloat64Div, s[3]->arch_opcode());
654 StreamBuilder m(this, kMachFloat64, kMachFloat64, kMachFloat64);
655 Node* add = m.Float64Add(m.Parameter(0), m.Parameter(1));
656 Node* mul = m.Float64Mul(add, m.Parameter(1));
657 Node* sub = m.Float64Sub(mul, add);
658 Node* ret = m.Float64Div(mul, sub);
660 Stream s = m.Build();
661 ASSERT_EQ(4U, s.size());
662 EXPECT_EQ(kSSEFloat64Add, s[0]->arch_opcode());
663 EXPECT_EQ(kSSEFloat64Mul, s[1]->arch_opcode());
664 EXPECT_EQ(kSSEFloat64Sub, s[2]->arch_opcode());
665 EXPECT_EQ(kSSEFloat64Div, s[3]->arch_opcode());
670 // -----------------------------------------------------------------------------
674 TEST_F(InstructionSelectorTest, Uint32LessThanWithLoadAndLoadStackPointer) {
675 StreamBuilder m(this, kMachBool);
676 Node* const sl = m.Load(
678 m.ExternalConstant(ExternalReference::address_of_stack_limit(isolate())));
679 Node* const sp = m.LoadStackPointer();
680 Node* const n = m.Uint32LessThan(sl, sp);
682 Stream s = m.Build();
683 ASSERT_EQ(1U, s.size());
684 EXPECT_EQ(kIA32StackCheck, s[0]->arch_opcode());
685 ASSERT_EQ(0U, s[0]->InputCount());
686 ASSERT_EQ(1U, s[0]->OutputCount());
687 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
688 EXPECT_EQ(kFlags_set, s[0]->flags_mode());
689 EXPECT_EQ(kUnsignedGreaterThan, s[0]->flags_condition());
693 TEST_F(InstructionSelectorTest, Word32Clz) {
694 StreamBuilder m(this, kMachUint32, kMachUint32);
695 Node* const p0 = m.Parameter(0);
696 Node* const n = m.Word32Clz(p0);
698 Stream s = m.Build();
699 ASSERT_EQ(1U, s.size());
700 EXPECT_EQ(kIA32Lzcnt, s[0]->arch_opcode());
701 ASSERT_EQ(1U, s[0]->InputCount());
702 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
703 ASSERT_EQ(1U, s[0]->OutputCount());
704 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
707 } // namespace compiler
708 } // namespace internal