| OLD | NEW |
| 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 "src/base/bits.h" | 5 #include "src/base/bits.h" |
| 6 #include "src/base/division-by-constant.h" | 6 #include "src/base/division-by-constant.h" |
| 7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
| 8 #include "src/compiler/machine-operator-reducer.h" | 8 #include "src/compiler/machine-operator-reducer.h" |
| 9 #include "src/compiler/typer.h" | 9 #include "src/compiler/typer.h" |
| 10 #include "test/unittests/compiler/graph-unittest.h" | 10 #include "test/unittests/compiler/graph-unittest.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 const uint32_t kUint32Values[] = { | 225 const uint32_t kUint32Values[] = { |
| 226 0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf, | 226 0x00000000, 0x00000001, 0xffffffff, 0x1b09788b, 0x04c5fce8, 0xcc0de5bf, |
| 227 0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344, | 227 0x273a798e, 0x187937a3, 0xece3af83, 0x5495a16b, 0x0b668ecc, 0x11223344, |
| 228 0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c, | 228 0x0000009e, 0x00000043, 0x0000af73, 0x0000116b, 0x00658ecc, 0x002b3b4c, |
| 229 0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00, | 229 0x88776655, 0x70000000, 0x07200000, 0x7fffffff, 0x56123761, 0x7fffff00, |
| 230 0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000, | 230 0x761c4761, 0x80000000, 0x88888888, 0xa0000000, 0xdddddddd, 0xe0000000, |
| 231 0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff, | 231 0xeeeeeeee, 0xfffffffd, 0xf0000000, 0x007fffff, 0x003fffff, 0x001fffff, |
| 232 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff, | 232 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff, |
| 233 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff}; | 233 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff}; |
| 234 | 234 |
| 235 |
| 236 int32_t RandomInt32(base::RandomNumberGenerator* rng) { |
| 237 int index = rng->NextInt(static_cast<int>(arraysize(kInt32Values))); |
| 238 return kInt32Values[index]; |
| 239 } |
| 240 |
| 235 } // namespace | 241 } // namespace |
| 236 | 242 |
| 237 | 243 |
| 238 // ----------------------------------------------------------------------------- | 244 // ----------------------------------------------------------------------------- |
| 239 // Unary operators | 245 // Unary operators |
| 240 | 246 |
| 241 | 247 |
| 242 namespace { | 248 namespace { |
| 243 | 249 |
| 244 struct UnaryOperator { | 250 struct UnaryOperator { |
| (...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 Uint32Constant(x | 0xffffu)), | 1143 Uint32Constant(x | 0xffffu)), |
| 1138 effect, control); | 1144 effect, control); |
| 1139 | 1145 |
| 1140 Reduction r = Reduce(node); | 1146 Reduction r = Reduce(node); |
| 1141 ASSERT_TRUE(r.Changed()); | 1147 ASSERT_TRUE(r.Changed()); |
| 1142 EXPECT_THAT(r.replacement(), | 1148 EXPECT_THAT(r.replacement(), |
| 1143 IsStore(rep, base, index, value, effect, control)); | 1149 IsStore(rep, base, index, value, effect, control)); |
| 1144 } | 1150 } |
| 1145 } | 1151 } |
| 1146 | 1152 |
| 1153 |
| 1154 TEST_F(MachineOperatorReducerTest, ConstantFoldCompare32) { |
| 1155 base::RandomNumberGenerator rng; |
| 1156 TRACED_FOREACH(int32_t, c_0, kInt32Values) { |
| 1157 const int32_t c_1 = RandomInt32(&rng); |
| 1158 const int32_t c_2 = RandomInt32(&rng); |
| 1159 { |
| 1160 Node* const k_0 = Int32Constant(c_0); |
| 1161 Node* const k_1 = Int32Constant(c_1); |
| 1162 Node* const k_2 = Int32Constant(c_2); |
| 1163 Node* const p0 = Parameter(0); |
| 1164 Node* const add_0 = graph()->NewNode(machine()->Int32Add(), p0, k_0); |
| 1165 Node* const add_1 = graph()->NewNode(machine()->Int32Add(), add_0, k_1); |
| 1166 Node* const node = |
| 1167 graph()->NewNode(machine()->Int32LessThan(), add_1, k_2); |
| 1168 Reduction r = Reduce(node); |
| 1169 ASSERT_TRUE(r.Changed()); |
| 1170 EXPECT_THAT(r.replacement(), |
| 1171 IsInt32LessThan(p0, IsInt32Constant(c_2 - c_1 - c_0))); |
| 1172 } |
| 1173 { |
| 1174 Node* const k_0 = Int32Constant(c_0); |
| 1175 Node* const k_1 = Int32Constant(c_1); |
| 1176 Node* const k_2 = Int32Constant(c_2); |
| 1177 Node* const p0 = Parameter(0); |
| 1178 Node* const add_0 = graph()->NewNode(machine()->Int32Add(), p0, k_0); |
| 1179 Node* const add_1 = graph()->NewNode(machine()->Int32Add(), add_0, k_1); |
| 1180 Node* const node = |
| 1181 graph()->NewNode(machine()->Int32LessThan(), k_2, add_1); |
| 1182 Reduction r = Reduce(node); |
| 1183 ASSERT_TRUE(r.Changed()); |
| 1184 EXPECT_THAT(r.replacement(), |
| 1185 IsInt32LessThan(IsInt32Constant(c_2 - c_1 - c_0), p0)); |
| 1186 } |
| 1187 } |
| 1188 } |
| 1189 |
| 1147 } // namespace compiler | 1190 } // namespace compiler |
| 1148 } // namespace internal | 1191 } // namespace internal |
| 1149 } // namespace v8 | 1192 } // namespace v8 |
| OLD | NEW |