Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc

Issue 2669203005: [arm64][turbofan] Fix add+shr for big shift values. (Closed)
Patch Set: Only consider the last 6 bits of the shift immediate Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/compiler/test-run-machops.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "test/unittests/compiler/instruction-selector-unittest.h" 5 #include "test/unittests/compiler/instruction-selector-unittest.h"
6 6
7 namespace v8 { 7 namespace v8 {
8 namespace internal { 8 namespace internal {
9 namespace compiler { 9 namespace compiler {
10 10
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 m.Int32Constant(0), 738 m.Int32Constant(0),
739 (m.*shift.mi.constructor)(m.Parameter(1), m.Int32Constant(imm)))); 739 (m.*shift.mi.constructor)(m.Parameter(1), m.Int32Constant(imm))));
740 Stream s = m.Build(); 740 Stream s = m.Build();
741 741
742 ASSERT_EQ(1U, s.size()); 742 ASSERT_EQ(1U, s.size());
743 EXPECT_EQ(kArm64Sub32, s[0]->arch_opcode()); 743 EXPECT_EQ(kArm64Sub32, s[0]->arch_opcode());
744 ASSERT_EQ(3U, s[0]->InputCount()); 744 ASSERT_EQ(3U, s[0]->InputCount());
745 EXPECT_TRUE(s[0]->InputAt(0)->IsImmediate()); 745 EXPECT_TRUE(s[0]->InputAt(0)->IsImmediate());
746 EXPECT_EQ(0, s.ToInt32(s[0]->InputAt(0))); 746 EXPECT_EQ(0, s.ToInt32(s[0]->InputAt(0)));
747 EXPECT_EQ(shift.mode, s[0]->addressing_mode()); 747 EXPECT_EQ(shift.mode, s[0]->addressing_mode());
748 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(2))); 748 EXPECT_EQ(0x3f & imm, 0x3f & s.ToInt32(s[0]->InputAt(2)));
749 EXPECT_EQ(1U, s[0]->OutputCount()); 749 EXPECT_EQ(1U, s[0]->OutputCount());
750 } 750 }
751 } 751 }
752 { 752 {
753 // Test 64-bit operations. Ignore ROR shifts, as subtract does not 753 // Test 64-bit operations. Ignore ROR shifts, as subtract does not
754 // support them. 754 // support them.
755 if ((shift.mi.machine_type != MachineType::Int64()) || 755 if ((shift.mi.machine_type != MachineType::Int64()) ||
756 (shift.mi.arch_opcode == kArm64Ror32) || 756 (shift.mi.arch_opcode == kArm64Ror32) ||
757 (shift.mi.arch_opcode == kArm64Ror)) 757 (shift.mi.arch_opcode == kArm64Ror))
758 continue; 758 continue;
759 759
760 TRACED_FORRANGE(int, imm, -32, 127) { 760 TRACED_FORRANGE(int, imm, -32, 127) {
761 StreamBuilder m(this, MachineType::Int64(), MachineType::Int64(), 761 StreamBuilder m(this, MachineType::Int64(), MachineType::Int64(),
762 MachineType::Int64()); 762 MachineType::Int64());
763 m.Return(m.Int64Sub( 763 m.Return(m.Int64Sub(
764 m.Int64Constant(0), 764 m.Int64Constant(0),
765 (m.*shift.mi.constructor)(m.Parameter(1), m.Int64Constant(imm)))); 765 (m.*shift.mi.constructor)(m.Parameter(1), m.Int64Constant(imm))));
766 Stream s = m.Build(); 766 Stream s = m.Build();
767 767
768 ASSERT_EQ(1U, s.size()); 768 ASSERT_EQ(1U, s.size());
769 EXPECT_EQ(kArm64Sub, s[0]->arch_opcode()); 769 EXPECT_EQ(kArm64Sub, s[0]->arch_opcode());
770 ASSERT_EQ(3U, s[0]->InputCount()); 770 ASSERT_EQ(3U, s[0]->InputCount());
771 EXPECT_TRUE(s[0]->InputAt(0)->IsImmediate()); 771 EXPECT_TRUE(s[0]->InputAt(0)->IsImmediate());
772 EXPECT_EQ(0, s.ToInt32(s[0]->InputAt(0))); 772 EXPECT_EQ(0, s.ToInt32(s[0]->InputAt(0)));
773 EXPECT_EQ(shift.mode, s[0]->addressing_mode()); 773 EXPECT_EQ(shift.mode, s[0]->addressing_mode());
774 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(2))); 774 EXPECT_EQ(0x3f & imm, 0x3f & s.ToInt32(s[0]->InputAt(2)));
775 EXPECT_EQ(1U, s[0]->OutputCount()); 775 EXPECT_EQ(1U, s[0]->OutputCount());
776 } 776 }
777 } 777 }
778 } 778 }
779 } 779 }
780 780
781 781
782 TEST_F(InstructionSelectorTest, AddNegImmediateOnLeft) { 782 TEST_F(InstructionSelectorTest, AddNegImmediateOnLeft) {
783 { 783 {
784 // 32-bit add. 784 // 32-bit add.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32(), 828 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32(),
829 MachineType::Int32()); 829 MachineType::Int32());
830 m.Return((m.Int32Add)( 830 m.Return((m.Int32Add)(
831 (m.*shift.mi.constructor)(m.Parameter(1), m.Int32Constant(imm)), 831 (m.*shift.mi.constructor)(m.Parameter(1), m.Int32Constant(imm)),
832 m.Parameter(0))); 832 m.Parameter(0)));
833 Stream s = m.Build(); 833 Stream s = m.Build();
834 ASSERT_EQ(1U, s.size()); 834 ASSERT_EQ(1U, s.size());
835 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode()); 835 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode());
836 EXPECT_EQ(shift.mode, s[0]->addressing_mode()); 836 EXPECT_EQ(shift.mode, s[0]->addressing_mode());
837 EXPECT_EQ(3U, s[0]->InputCount()); 837 EXPECT_EQ(3U, s[0]->InputCount());
838 EXPECT_EQ(imm, s.ToInt64(s[0]->InputAt(2))); 838 EXPECT_EQ(0x3f & imm, 0x3f & s.ToInt64(s[0]->InputAt(2)));
839 EXPECT_EQ(1U, s[0]->OutputCount()); 839 EXPECT_EQ(1U, s[0]->OutputCount());
840 } 840 }
841 } 841 }
842 842
843 // 64-bit add. 843 // 64-bit add.
844 TRACED_FOREACH(Shift, shift, kShiftInstructions) { 844 TRACED_FOREACH(Shift, shift, kShiftInstructions) {
845 // Only test relevant shifted operands. 845 // Only test relevant shifted operands.
846 if (shift.mi.machine_type != MachineType::Int64()) continue; 846 if (shift.mi.machine_type != MachineType::Int64()) continue;
847 if (shift.mi.arch_opcode == kArm64Ror) continue; 847 if (shift.mi.arch_opcode == kArm64Ror) continue;
848 848
849 // The available shift operand range is `0 <= imm < 64`, but we also test 849 // The available shift operand range is `0 <= imm < 64`, but we also test
850 // that immediates outside this range are handled properly (modulo-64). 850 // that immediates outside this range are handled properly (modulo-64).
851 TRACED_FORRANGE(int, imm, -64, 127) { 851 TRACED_FORRANGE(int, imm, -64, 127) {
852 StreamBuilder m(this, MachineType::Int64(), MachineType::Int64(), 852 StreamBuilder m(this, MachineType::Int64(), MachineType::Int64(),
853 MachineType::Int64()); 853 MachineType::Int64());
854 m.Return((m.Int64Add)( 854 m.Return((m.Int64Add)(
855 (m.*shift.mi.constructor)(m.Parameter(1), m.Int64Constant(imm)), 855 (m.*shift.mi.constructor)(m.Parameter(1), m.Int64Constant(imm)),
856 m.Parameter(0))); 856 m.Parameter(0)));
857 Stream s = m.Build(); 857 Stream s = m.Build();
858 ASSERT_EQ(1U, s.size()); 858 ASSERT_EQ(1U, s.size());
859 EXPECT_EQ(kArm64Add, s[0]->arch_opcode()); 859 EXPECT_EQ(kArm64Add, s[0]->arch_opcode());
860 EXPECT_EQ(shift.mode, s[0]->addressing_mode()); 860 EXPECT_EQ(shift.mode, s[0]->addressing_mode());
861 EXPECT_EQ(3U, s[0]->InputCount()); 861 EXPECT_EQ(3U, s[0]->InputCount());
862 EXPECT_EQ(imm, s.ToInt64(s[0]->InputAt(2))); 862 EXPECT_EQ(0x3f & imm, 0x3f & s.ToInt64(s[0]->InputAt(2)));
863 EXPECT_EQ(1U, s[0]->OutputCount()); 863 EXPECT_EQ(1U, s[0]->OutputCount());
864 } 864 }
865 } 865 }
866 } 866 }
867 867
868 868
869 TEST_F(InstructionSelectorTest, AddUnsignedExtendByteOnLeft) { 869 TEST_F(InstructionSelectorTest, AddUnsignedExtendByteOnLeft) {
870 { 870 {
871 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32(), 871 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32(),
872 MachineType::Int32()); 872 MachineType::Int32());
(...skipping 2044 matching lines...) Expand 10 before | Expand all | Expand 10 after
2917 Node* const p1 = m.Parameter(1); 2917 Node* const p1 = m.Parameter(1);
2918 Node* r = (m.*shift.mi.constructor)(p1, m.Int32Constant(imm)); 2918 Node* r = (m.*shift.mi.constructor)(p1, m.Int32Constant(imm));
2919 m.Return(m.Word32Equal(p0, r)); 2919 m.Return(m.Word32Equal(p0, r));
2920 Stream s = m.Build(); 2920 Stream s = m.Build();
2921 ASSERT_EQ(1U, s.size()); 2921 ASSERT_EQ(1U, s.size());
2922 EXPECT_EQ(kArm64Cmp32, s[0]->arch_opcode()); 2922 EXPECT_EQ(kArm64Cmp32, s[0]->arch_opcode());
2923 EXPECT_EQ(shift.mode, s[0]->addressing_mode()); 2923 EXPECT_EQ(shift.mode, s[0]->addressing_mode());
2924 ASSERT_EQ(3U, s[0]->InputCount()); 2924 ASSERT_EQ(3U, s[0]->InputCount());
2925 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); 2925 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
2926 EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1))); 2926 EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
2927 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(2))); 2927 EXPECT_EQ(0x3f & imm, 0x3f & s.ToInt32(s[0]->InputAt(2)));
2928 ASSERT_EQ(1U, s[0]->OutputCount()); 2928 ASSERT_EQ(1U, s[0]->OutputCount());
2929 } 2929 }
2930 TRACED_FORRANGE(int32_t, imm, -32, 63) { 2930 TRACED_FORRANGE(int32_t, imm, -32, 63) {
2931 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32(), 2931 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32(),
2932 MachineType::Int32()); 2932 MachineType::Int32());
2933 Node* const p0 = m.Parameter(0); 2933 Node* const p0 = m.Parameter(0);
2934 Node* const p1 = m.Parameter(1); 2934 Node* const p1 = m.Parameter(1);
2935 Node* r = (m.*shift.mi.constructor)(p1, m.Int32Constant(imm)); 2935 Node* r = (m.*shift.mi.constructor)(p1, m.Int32Constant(imm));
2936 m.Return(m.Word32Equal(r, p0)); 2936 m.Return(m.Word32Equal(r, p0));
2937 Stream s = m.Build(); 2937 Stream s = m.Build();
2938 ASSERT_EQ(1U, s.size()); 2938 ASSERT_EQ(1U, s.size());
2939 EXPECT_EQ(kArm64Cmp32, s[0]->arch_opcode()); 2939 EXPECT_EQ(kArm64Cmp32, s[0]->arch_opcode());
2940 EXPECT_EQ(shift.mode, s[0]->addressing_mode()); 2940 EXPECT_EQ(shift.mode, s[0]->addressing_mode());
2941 ASSERT_EQ(3U, s[0]->InputCount()); 2941 ASSERT_EQ(3U, s[0]->InputCount());
2942 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); 2942 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
2943 EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1))); 2943 EXPECT_EQ(s.ToVreg(p1), s.ToVreg(s[0]->InputAt(1)));
2944 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(2))); 2944 EXPECT_EQ(0x3f & imm, 0x3f & s.ToInt32(s[0]->InputAt(2)));
2945 ASSERT_EQ(1U, s[0]->OutputCount()); 2945 ASSERT_EQ(1U, s[0]->OutputCount());
2946 } 2946 }
2947 } 2947 }
2948 } 2948 }
2949 2949
2950 2950
2951 TEST_F(InstructionSelectorTest, Word32EqualWithUnsignedExtendByte) { 2951 TEST_F(InstructionSelectorTest, Word32EqualWithUnsignedExtendByte) {
2952 { 2952 {
2953 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32(), 2953 StreamBuilder m(this, MachineType::Int32(), MachineType::Int32(),
2954 MachineType::Int32()); 2954 MachineType::Int32());
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
3196 Node* const p0 = m.Parameter(0); 3196 Node* const p0 = m.Parameter(0);
3197 Node* const p1 = m.Parameter(1); 3197 Node* const p1 = m.Parameter(1);
3198 Node* r = (m.*shift.mi.constructor)(p1, m.Int32Constant(imm)); 3198 Node* r = (m.*shift.mi.constructor)(p1, m.Int32Constant(imm));
3199 m.Return( 3199 m.Return(
3200 (m.*cmp.mi.constructor)(p0, m.Int32Sub(m.Int32Constant(0), r))); 3200 (m.*cmp.mi.constructor)(p0, m.Int32Sub(m.Int32Constant(0), r)));
3201 Stream s = m.Build(); 3201 Stream s = m.Build();
3202 ASSERT_EQ(1U, s.size()); 3202 ASSERT_EQ(1U, s.size());
3203 EXPECT_EQ(kArm64Cmn32, s[0]->arch_opcode()); 3203 EXPECT_EQ(kArm64Cmn32, s[0]->arch_opcode());
3204 EXPECT_EQ(3U, s[0]->InputCount()); 3204 EXPECT_EQ(3U, s[0]->InputCount());
3205 EXPECT_EQ(shift.mode, s[0]->addressing_mode()); 3205 EXPECT_EQ(shift.mode, s[0]->addressing_mode());
3206 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(2))); 3206 EXPECT_EQ(0x3f & imm, 0x3f & s.ToInt32(s[0]->InputAt(2)));
3207 EXPECT_EQ(1U, s[0]->OutputCount()); 3207 EXPECT_EQ(1U, s[0]->OutputCount());
3208 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); 3208 EXPECT_EQ(kFlags_set, s[0]->flags_mode());
3209 EXPECT_EQ(cmp.cond, s[0]->flags_condition()); 3209 EXPECT_EQ(cmp.cond, s[0]->flags_condition());
3210 } 3210 }
3211 } 3211 }
3212 } 3212 }
3213 } 3213 }
3214 3214
3215 TEST_F(InstructionSelectorTest, CmpWithImmediateOnLeft) { 3215 TEST_F(InstructionSelectorTest, CmpWithImmediateOnLeft) {
3216 TRACED_FOREACH(IntegerCmp, cmp, kIntegerCmpInstructions) { 3216 TRACED_FOREACH(IntegerCmp, cmp, kIntegerCmpInstructions) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
3304 Stream s = m.Build(); 3304 Stream s = m.Build();
3305 // Cmp does not support ROR shifts. 3305 // Cmp does not support ROR shifts.
3306 if (shift.mi.arch_opcode == kArm64Ror32) { 3306 if (shift.mi.arch_opcode == kArm64Ror32) {
3307 ASSERT_EQ(2U, s.size()); 3307 ASSERT_EQ(2U, s.size());
3308 continue; 3308 continue;
3309 } 3309 }
3310 ASSERT_EQ(1U, s.size()); 3310 ASSERT_EQ(1U, s.size());
3311 EXPECT_EQ(kArm64Cmp32, s[0]->arch_opcode()); 3311 EXPECT_EQ(kArm64Cmp32, s[0]->arch_opcode());
3312 EXPECT_EQ(shift.mode, s[0]->addressing_mode()); 3312 EXPECT_EQ(shift.mode, s[0]->addressing_mode());
3313 EXPECT_EQ(3U, s[0]->InputCount()); 3313 EXPECT_EQ(3U, s[0]->InputCount());
3314 EXPECT_EQ(imm, s.ToInt64(s[0]->InputAt(2))); 3314 EXPECT_EQ(0x3f & imm, 0x3f & s.ToInt64(s[0]->InputAt(2)));
3315 EXPECT_EQ(1U, s[0]->OutputCount()); 3315 EXPECT_EQ(1U, s[0]->OutputCount());
3316 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); 3316 EXPECT_EQ(kFlags_set, s[0]->flags_mode());
3317 EXPECT_EQ(cmp.commuted_cond, s[0]->flags_condition()); 3317 EXPECT_EQ(cmp.commuted_cond, s[0]->flags_condition());
3318 } 3318 }
3319 } 3319 }
3320 } 3320 }
3321 } 3321 }
3322 3322
3323 TEST_F(InstructionSelectorTest, CmnShiftByImmediateOnLeft) { 3323 TEST_F(InstructionSelectorTest, CmnShiftByImmediateOnLeft) {
3324 TRACED_FOREACH(IntegerCmp, cmp, kIntegerCmpEqualityInstructions) { 3324 TRACED_FOREACH(IntegerCmp, cmp, kIntegerCmpEqualityInstructions) {
(...skipping 13 matching lines...) Expand all
3338 Stream s = m.Build(); 3338 Stream s = m.Build();
3339 // Cmn does not support ROR shifts. 3339 // Cmn does not support ROR shifts.
3340 if (shift.mi.arch_opcode == kArm64Ror32) { 3340 if (shift.mi.arch_opcode == kArm64Ror32) {
3341 ASSERT_EQ(2U, s.size()); 3341 ASSERT_EQ(2U, s.size());
3342 continue; 3342 continue;
3343 } 3343 }
3344 ASSERT_EQ(1U, s.size()); 3344 ASSERT_EQ(1U, s.size());
3345 EXPECT_EQ(kArm64Cmn32, s[0]->arch_opcode()); 3345 EXPECT_EQ(kArm64Cmn32, s[0]->arch_opcode());
3346 EXPECT_EQ(shift.mode, s[0]->addressing_mode()); 3346 EXPECT_EQ(shift.mode, s[0]->addressing_mode());
3347 EXPECT_EQ(3U, s[0]->InputCount()); 3347 EXPECT_EQ(3U, s[0]->InputCount());
3348 EXPECT_EQ(imm, s.ToInt64(s[0]->InputAt(2))); 3348 EXPECT_EQ(0x3f & imm, 0x3f & s.ToInt64(s[0]->InputAt(2)));
3349 EXPECT_EQ(1U, s[0]->OutputCount()); 3349 EXPECT_EQ(1U, s[0]->OutputCount());
3350 EXPECT_EQ(kFlags_set, s[0]->flags_mode()); 3350 EXPECT_EQ(kFlags_set, s[0]->flags_mode());
3351 EXPECT_EQ(cmp.cond, s[0]->flags_condition()); 3351 EXPECT_EQ(cmp.cond, s[0]->flags_condition());
3352 } 3352 }
3353 } 3353 }
3354 } 3354 }
3355 } 3355 }
3356 3356
3357 // ----------------------------------------------------------------------------- 3357 // -----------------------------------------------------------------------------
3358 // Flag-setting add and and instructions. 3358 // Flag-setting add and and instructions.
(...skipping 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after
4375 EXPECT_EQ(kArm64TestAndBranch, s[1]->arch_opcode()); 4375 EXPECT_EQ(kArm64TestAndBranch, s[1]->arch_opcode());
4376 EXPECT_EQ(kEqual, s[1]->flags_condition()); 4376 EXPECT_EQ(kEqual, s[1]->flags_condition());
4377 EXPECT_EQ(4U, s[1]->InputCount()); 4377 EXPECT_EQ(4U, s[1]->InputCount());
4378 EXPECT_EQ(InstructionOperand::IMMEDIATE, s[1]->InputAt(1)->kind()); 4378 EXPECT_EQ(InstructionOperand::IMMEDIATE, s[1]->InputAt(1)->kind());
4379 EXPECT_EQ(63, s.ToInt32(s[1]->InputAt(1))); 4379 EXPECT_EQ(63, s.ToInt32(s[1]->InputAt(1)));
4380 } 4380 }
4381 4381
4382 } // namespace compiler 4382 } // namespace compiler
4383 } // namespace internal 4383 } // namespace internal
4384 } // namespace v8 4384 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-run-machops.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698