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

Side by Side Diff: src/compiler/s390/instruction-selector-s390.cc

Issue 2668763005: s390: fix shift operand overflow (Closed)
Patch Set: 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 | « src/compiler/s390/code-generator-s390.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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 "src/base/adapters.h" 5 #include "src/base/adapters.h"
6 #include "src/compiler/instruction-selector-impl.h" 6 #include "src/compiler/instruction-selector-impl.h"
7 #include "src/compiler/node-matchers.h" 7 #include "src/compiler/node-matchers.h"
8 #include "src/compiler/node-properties.h" 8 #include "src/compiler/node-properties.h"
9 #include "src/s390/frames-s390.h" 9 #include "src/s390/frames-s390.h"
10 10
(...skipping 13 matching lines...) Expand all
24 // Instr format 24 // Instr format
25 kAllowRRR = 1u << 7, 25 kAllowRRR = 1u << 7,
26 kAllowRM = 1u << 8, 26 kAllowRM = 1u << 8,
27 kAllowRI = 1u << 9, 27 kAllowRI = 1u << 9,
28 kAllowRRI = 1u << 10, 28 kAllowRRI = 1u << 10,
29 kAllowRRM = 1u << 11, 29 kAllowRRM = 1u << 11,
30 // Useful combination 30 // Useful combination
31 kAllowImmediate = kAllowRI | kAllowRRI, 31 kAllowImmediate = kAllowRI | kAllowRRI,
32 kAllowMemoryOperand = kAllowRM | kAllowRRM, 32 kAllowMemoryOperand = kAllowRM | kAllowRRM,
33 kAllowDistinctOps = kAllowRRR | kAllowRRI | kAllowRRM, 33 kAllowDistinctOps = kAllowRRR | kAllowRRI | kAllowRRM,
34 kBitWiseCommonMode = kAllowRI | kUint32Imm, 34 kBitWiseCommonMode = kAllowRI,
35 kArithmeticCommonMode = kAllowRM | kAllowRI 35 kArithmeticCommonMode = kAllowRM | kAllowRI
36 }; 36 };
37 37
38 typedef base::Flags<OperandMode, uint32_t> OperandModes; 38 typedef base::Flags<OperandMode, uint32_t> OperandModes;
39 DEFINE_OPERATORS_FOR_FLAGS(OperandModes); 39 DEFINE_OPERATORS_FOR_FLAGS(OperandModes);
40 OperandModes immediateModeMask = 40 OperandModes immediateModeMask =
41 OperandMode::kShift32Imm | OperandMode::kShift64Imm | 41 OperandMode::kShift32Imm | OperandMode::kShift64Imm |
42 OperandMode::kInt32Imm | OperandMode::kInt32Imm_Negate | 42 OperandMode::kInt32Imm | OperandMode::kInt32Imm_Negate |
43 OperandMode::kUint32Imm | OperandMode::kInt20Imm; 43 OperandMode::kUint32Imm | OperandMode::kInt20Imm;
44 44
45 #define BitWiseOperandMode \ 45 #define AndOperandMode \
46 ((OperandMode::kBitWiseCommonMode | \ 46 ((OperandMode::kBitWiseCommonMode | OperandMode::kUint32Imm | \
47 (CpuFeatures::IsSupported(DISTINCT_OPS) \ 47 OperandMode::kAllowRM | (CpuFeatures::IsSupported(DISTINCT_OPS) \
48 ? OperandMode::kAllowRRR \ 48 ? OperandMode::kAllowRRR \
49 : OperandMode::kBitWiseCommonMode)))
50
51 #define OrOperandMode AndOperandMode
52 #define XorOperandMode AndOperandMode
53
54 #define ShiftOperandMode \
55 ((OperandMode::kBitWiseCommonMode | OperandMode::kShift64Imm | \
56 (CpuFeatures::IsSupported(DISTINCT_OPS) \
57 ? OperandMode::kAllowRRR \
49 : OperandMode::kBitWiseCommonMode))) 58 : OperandMode::kBitWiseCommonMode)))
59
50 #define AddOperandMode \ 60 #define AddOperandMode \
51 ((OperandMode::kArithmeticCommonMode | OperandMode::kInt32Imm | \ 61 ((OperandMode::kArithmeticCommonMode | OperandMode::kInt32Imm | \
52 (CpuFeatures::IsSupported(DISTINCT_OPS) \ 62 (CpuFeatures::IsSupported(DISTINCT_OPS) \
53 ? (OperandMode::kAllowRRR | OperandMode::kAllowRRI) \ 63 ? (OperandMode::kAllowRRR | OperandMode::kAllowRRI) \
54 : OperandMode::kArithmeticCommonMode))) 64 : OperandMode::kArithmeticCommonMode)))
55 #define SubOperandMode \ 65 #define SubOperandMode \
56 ((OperandMode::kArithmeticCommonMode | OperandMode::kInt32Imm_Negate | \ 66 ((OperandMode::kArithmeticCommonMode | OperandMode::kInt32Imm_Negate | \
57 (CpuFeatures::IsSupported(DISTINCT_OPS) \ 67 (CpuFeatures::IsSupported(DISTINCT_OPS) \
58 ? (OperandMode::kAllowRRR | OperandMode::kAllowRRI) \ 68 ? (OperandMode::kAllowRRR | OperandMode::kAllowRRI) \
59 : OperandMode::kArithmeticCommonMode))) 69 : OperandMode::kArithmeticCommonMode)))
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 int mask_lsb = base::bits::CountTrailingZeros64(value); 832 int mask_lsb = base::bits::CountTrailingZeros64(value);
823 if ((mask_width == 0) || (mask_msb + mask_width + mask_lsb != 64)) 833 if ((mask_width == 0) || (mask_msb + mask_width + mask_lsb != 64))
824 return false; 834 return false;
825 *mb = mask_lsb + mask_width - 1; 835 *mb = mask_lsb + mask_width - 1;
826 *me = mask_lsb; 836 *me = mask_lsb;
827 return true; 837 return true;
828 } 838 }
829 #endif 839 #endif
830 840
831 void InstructionSelector::VisitWord32And(Node* node) { 841 void InstructionSelector::VisitWord32And(Node* node) {
832 VisitBin32op(this, node, kS390_And32, 842 VisitBin32op(this, node, kS390_And32, AndOperandMode);
833 BitWiseOperandMode | OperandMode::kAllowRM);
834 } 843 }
835 844
836 #if V8_TARGET_ARCH_S390X 845 #if V8_TARGET_ARCH_S390X
837 void InstructionSelector::VisitWord64And(Node* node) { 846 void InstructionSelector::VisitWord64And(Node* node) {
838 S390OperandGenerator g(this); 847 S390OperandGenerator g(this);
839 Int64BinopMatcher m(node); 848 Int64BinopMatcher m(node);
840 int mb = 0; 849 int mb = 0;
841 int me = 0; 850 int me = 0;
842 if (m.right().HasValue() && IsContiguousMask64(m.right().Value(), &mb, &me)) { 851 if (m.right().HasValue() && IsContiguousMask64(m.right().Value(), &mb, &me)) {
843 int sh = 0; 852 int sh = 0;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 return; 890 return;
882 } 891 }
883 } 892 }
884 } 893 }
885 VisitBinop<Int64BinopMatcher>(this, node, kS390_And64, 894 VisitBinop<Int64BinopMatcher>(this, node, kS390_And64,
886 OperandMode::kUint32Imm); 895 OperandMode::kUint32Imm);
887 } 896 }
888 #endif 897 #endif
889 898
890 void InstructionSelector::VisitWord32Or(Node* node) { 899 void InstructionSelector::VisitWord32Or(Node* node) {
891 VisitBin32op(this, node, kS390_Or32, 900 VisitBin32op(this, node, kS390_Or32, OrOperandMode);
892 BitWiseOperandMode | OperandMode::kAllowRM);
893 } 901 }
894 902
895 #if V8_TARGET_ARCH_S390X 903 #if V8_TARGET_ARCH_S390X
896 void InstructionSelector::VisitWord64Or(Node* node) { 904 void InstructionSelector::VisitWord64Or(Node* node) {
897 Int64BinopMatcher m(node); 905 Int64BinopMatcher m(node);
898 VisitBinop<Int64BinopMatcher>(this, node, kS390_Or64, 906 VisitBinop<Int64BinopMatcher>(this, node, kS390_Or64,
899 OperandMode::kUint32Imm); 907 OperandMode::kUint32Imm);
900 } 908 }
901 #endif 909 #endif
902 910
903 void InstructionSelector::VisitWord32Xor(Node* node) { 911 void InstructionSelector::VisitWord32Xor(Node* node) {
904 VisitBin32op(this, node, kS390_Xor32, 912 VisitBin32op(this, node, kS390_Xor32, XorOperandMode);
905 BitWiseOperandMode | OperandMode::kAllowRM);
906 } 913 }
907 914
908 #if V8_TARGET_ARCH_S390X 915 #if V8_TARGET_ARCH_S390X
909 void InstructionSelector::VisitWord64Xor(Node* node) { 916 void InstructionSelector::VisitWord64Xor(Node* node) {
910 VisitBinop<Int64BinopMatcher>(this, node, kS390_Xor64, 917 VisitBinop<Int64BinopMatcher>(this, node, kS390_Xor64,
911 OperandMode::kUint32Imm); 918 OperandMode::kUint32Imm);
912 } 919 }
913 #endif 920 #endif
914 921
915 void InstructionSelector::VisitWord32Shl(Node* node) { 922 void InstructionSelector::VisitWord32Shl(Node* node) {
916 VisitBin32op(this, node, kS390_ShiftLeft32, BitWiseOperandMode); 923 VisitBin32op(this, node, kS390_ShiftLeft32, ShiftOperandMode);
917 } 924 }
918 925
919 #if V8_TARGET_ARCH_S390X 926 #if V8_TARGET_ARCH_S390X
920 void InstructionSelector::VisitWord64Shl(Node* node) { 927 void InstructionSelector::VisitWord64Shl(Node* node) {
921 S390OperandGenerator g(this); 928 S390OperandGenerator g(this);
922 Int64BinopMatcher m(node); 929 Int64BinopMatcher m(node);
923 // TODO(mbrandy): eliminate left sign extension if right >= 32 930 // TODO(mbrandy): eliminate left sign extension if right >= 32
924 if (m.left().IsWord64And() && m.right().IsInRange(0, 63)) { 931 if (m.left().IsWord64And() && m.right().IsInRange(0, 63)) {
925 Int64BinopMatcher mleft(m.left().node()); 932 Int64BinopMatcher mleft(m.left().node());
926 int sh = m.right().Value(); 933 int sh = m.right().Value();
(...skipping 27 matching lines...) Expand all
954 return; 961 return;
955 } 962 }
956 } 963 }
957 } 964 }
958 } 965 }
959 VisitRRO(this, kS390_ShiftLeft64, node, OperandMode::kShift64Imm); 966 VisitRRO(this, kS390_ShiftLeft64, node, OperandMode::kShift64Imm);
960 } 967 }
961 #endif 968 #endif
962 969
963 void InstructionSelector::VisitWord32Shr(Node* node) { 970 void InstructionSelector::VisitWord32Shr(Node* node) {
964 VisitBin32op(this, node, kS390_ShiftRight32, BitWiseOperandMode); 971 VisitBin32op(this, node, kS390_ShiftRight32, ShiftOperandMode);
965 } 972 }
966 973
967 #if V8_TARGET_ARCH_S390X 974 #if V8_TARGET_ARCH_S390X
968 void InstructionSelector::VisitWord64Shr(Node* node) { 975 void InstructionSelector::VisitWord64Shr(Node* node) {
969 S390OperandGenerator g(this); 976 S390OperandGenerator g(this);
970 Int64BinopMatcher m(node); 977 Int64BinopMatcher m(node);
971 if (m.left().IsWord64And() && m.right().IsInRange(0, 63)) { 978 if (m.left().IsWord64And() && m.right().IsInRange(0, 63)) {
972 Int64BinopMatcher mleft(m.left().node()); 979 Int64BinopMatcher mleft(m.left().node());
973 int sh = m.right().Value(); 980 int sh = m.right().Value();
974 int mb; 981 int mb;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 g.UseRegister(mleft.left().node()), g.TempImmediate(doZeroExt)); 1024 g.UseRegister(mleft.left().node()), g.TempImmediate(doZeroExt));
1018 return; 1025 return;
1019 } else if (mleft.right().Is(24) && m.right().Is(24)) { 1026 } else if (mleft.right().Is(24) && m.right().Is(24)) {
1020 bool doZeroExt = !ZeroExtendsWord32ToWord64(mleft.left().node()); 1027 bool doZeroExt = !ZeroExtendsWord32ToWord64(mleft.left().node());
1021 Emit(kS390_ExtendSignWord8, 1028 Emit(kS390_ExtendSignWord8,
1022 doZeroExt ? g.DefineAsRegister(node) : g.DefineSameAsFirst(node), 1029 doZeroExt ? g.DefineAsRegister(node) : g.DefineSameAsFirst(node),
1023 g.UseRegister(mleft.left().node()), g.TempImmediate(doZeroExt)); 1030 g.UseRegister(mleft.left().node()), g.TempImmediate(doZeroExt));
1024 return; 1031 return;
1025 } 1032 }
1026 } 1033 }
1027 VisitBin32op(this, node, kS390_ShiftRightArith32, BitWiseOperandMode); 1034 VisitBin32op(this, node, kS390_ShiftRightArith32, ShiftOperandMode);
1028 } 1035 }
1029 1036
1030 #if !V8_TARGET_ARCH_S390X 1037 #if !V8_TARGET_ARCH_S390X
1031 void VisitPairBinop(InstructionSelector* selector, InstructionCode opcode, 1038 void VisitPairBinop(InstructionSelector* selector, InstructionCode opcode,
1032 InstructionCode opcode2, Node* node) { 1039 InstructionCode opcode2, Node* node) {
1033 S390OperandGenerator g(selector); 1040 S390OperandGenerator g(selector);
1034 1041
1035 Node* projection1 = NodeProperties::FindProjection(node, 1); 1042 Node* projection1 = NodeProperties::FindProjection(node, 1);
1036 if (projection1) { 1043 if (projection1) {
1037 // We use UseUniqueRegister here to avoid register sharing with the output 1044 // We use UseUniqueRegister here to avoid register sharing with the output
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after
2307 // static 2314 // static
2308 MachineOperatorBuilder::AlignmentRequirements 2315 MachineOperatorBuilder::AlignmentRequirements
2309 InstructionSelector::AlignmentRequirements() { 2316 InstructionSelector::AlignmentRequirements() {
2310 return MachineOperatorBuilder::AlignmentRequirements:: 2317 return MachineOperatorBuilder::AlignmentRequirements::
2311 FullUnalignedAccessSupport(); 2318 FullUnalignedAccessSupport();
2312 } 2319 }
2313 2320
2314 } // namespace compiler 2321 } // namespace compiler
2315 } // namespace internal 2322 } // namespace internal
2316 } // namespace v8 2323 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/s390/code-generator-s390.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698