OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/compiler/load-elimination.h" | 5 #include "src/compiler/load-elimination.h" |
6 #include "src/compiler/access-builder.h" | 6 #include "src/compiler/access-builder.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/node.h" | 8 #include "src/compiler/node.h" |
9 #include "src/compiler/simplified-operator.h" | 9 #include "src/compiler/simplified-operator.h" |
10 #include "test/unittests/compiler/graph-reducer-unittest.h" | 10 #include "test/unittests/compiler/graph-reducer-unittest.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 load_elimination.Reduce(store2); | 206 load_elimination.Reduce(store2); |
207 | 207 |
208 Node* load = effect = graph()->NewNode(simplified()->LoadField(access), | 208 Node* load = effect = graph()->NewNode(simplified()->LoadField(access), |
209 object, effect, control); | 209 object, effect, control); |
210 EXPECT_CALL(editor, ReplaceWithValue(load, value, store2, _)); | 210 EXPECT_CALL(editor, ReplaceWithValue(load, value, store2, _)); |
211 Reduction r = load_elimination.Reduce(load); | 211 Reduction r = load_elimination.Reduce(load); |
212 ASSERT_TRUE(r.Changed()); | 212 ASSERT_TRUE(r.Changed()); |
213 EXPECT_EQ(value, r.replacement()); | 213 EXPECT_EQ(value, r.replacement()); |
214 } | 214 } |
215 | 215 |
| 216 TEST_F(LoadEliminationTest, LoadElementOnTrueBranchOfDiamond) { |
| 217 Node* object = Parameter(Type::Any(), 0); |
| 218 Node* index = Parameter(Type::UnsignedSmall(), 1); |
| 219 Node* check = Parameter(Type::Boolean(), 2); |
| 220 Node* effect = graph()->start(); |
| 221 Node* control = graph()->start(); |
| 222 ElementAccess const access = {kTaggedBase, kPointerSize, Type::Any(), |
| 223 MachineType::AnyTagged(), kNoWriteBarrier}; |
| 224 |
| 225 StrictMock<MockAdvancedReducerEditor> editor; |
| 226 LoadElimination load_elimination(&editor, jsgraph(), zone()); |
| 227 |
| 228 load_elimination.Reduce(graph()->start()); |
| 229 |
| 230 Node* branch = graph()->NewNode(common()->Branch(), check, control); |
| 231 |
| 232 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 233 Node* etrue = graph()->NewNode(simplified()->LoadElement(access), object, |
| 234 index, effect, if_true); |
| 235 load_elimination.Reduce(etrue); |
| 236 |
| 237 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 238 Node* efalse = effect; |
| 239 |
| 240 control = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 241 effect = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, control); |
| 242 load_elimination.Reduce(effect); |
| 243 |
| 244 Node* load = graph()->NewNode(simplified()->LoadElement(access), object, |
| 245 index, effect, control); |
| 246 Reduction r = load_elimination.Reduce(load); |
| 247 ASSERT_TRUE(r.Changed()); |
| 248 EXPECT_EQ(load, r.replacement()); |
| 249 } |
| 250 |
| 251 TEST_F(LoadEliminationTest, LoadElementOnFalseBranchOfDiamond) { |
| 252 Node* object = Parameter(Type::Any(), 0); |
| 253 Node* index = Parameter(Type::UnsignedSmall(), 1); |
| 254 Node* check = Parameter(Type::Boolean(), 2); |
| 255 Node* effect = graph()->start(); |
| 256 Node* control = graph()->start(); |
| 257 ElementAccess const access = {kTaggedBase, kPointerSize, Type::Any(), |
| 258 MachineType::AnyTagged(), kNoWriteBarrier}; |
| 259 |
| 260 StrictMock<MockAdvancedReducerEditor> editor; |
| 261 LoadElimination load_elimination(&editor, jsgraph(), zone()); |
| 262 |
| 263 load_elimination.Reduce(graph()->start()); |
| 264 |
| 265 Node* branch = graph()->NewNode(common()->Branch(), check, control); |
| 266 |
| 267 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 268 Node* etrue = effect; |
| 269 |
| 270 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 271 Node* efalse = graph()->NewNode(simplified()->LoadElement(access), object, |
| 272 index, effect, if_false); |
| 273 load_elimination.Reduce(efalse); |
| 274 |
| 275 control = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 276 effect = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, control); |
| 277 load_elimination.Reduce(effect); |
| 278 |
| 279 Node* load = graph()->NewNode(simplified()->LoadElement(access), object, |
| 280 index, effect, control); |
| 281 Reduction r = load_elimination.Reduce(load); |
| 282 ASSERT_TRUE(r.Changed()); |
| 283 EXPECT_EQ(load, r.replacement()); |
| 284 } |
| 285 |
| 286 TEST_F(LoadEliminationTest, LoadFieldOnFalseBranchOfDiamond) { |
| 287 Node* object = Parameter(Type::Any(), 0); |
| 288 Node* check = Parameter(Type::Boolean(), 1); |
| 289 Node* effect = graph()->start(); |
| 290 Node* control = graph()->start(); |
| 291 FieldAccess const access = {kTaggedBase, |
| 292 kPointerSize, |
| 293 MaybeHandle<Name>(), |
| 294 Type::Any(), |
| 295 MachineType::AnyTagged(), |
| 296 kNoWriteBarrier}; |
| 297 |
| 298 StrictMock<MockAdvancedReducerEditor> editor; |
| 299 LoadElimination load_elimination(&editor, jsgraph(), zone()); |
| 300 |
| 301 load_elimination.Reduce(graph()->start()); |
| 302 |
| 303 Node* branch = graph()->NewNode(common()->Branch(), check, control); |
| 304 |
| 305 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 306 Node* etrue = effect; |
| 307 |
| 308 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 309 Node* efalse = graph()->NewNode(simplified()->LoadField(access), object, |
| 310 effect, if_false); |
| 311 load_elimination.Reduce(efalse); |
| 312 |
| 313 control = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 314 effect = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, control); |
| 315 load_elimination.Reduce(effect); |
| 316 |
| 317 Node* load = graph()->NewNode(simplified()->LoadField(access), object, effect, |
| 318 control); |
| 319 Reduction r = load_elimination.Reduce(load); |
| 320 ASSERT_TRUE(r.Changed()); |
| 321 EXPECT_EQ(load, r.replacement()); |
| 322 } |
| 323 |
| 324 TEST_F(LoadEliminationTest, LoadFieldOnTrueBranchOfDiamond) { |
| 325 Node* object = Parameter(Type::Any(), 0); |
| 326 Node* check = Parameter(Type::Boolean(), 1); |
| 327 Node* effect = graph()->start(); |
| 328 Node* control = graph()->start(); |
| 329 FieldAccess const access = {kTaggedBase, |
| 330 kPointerSize, |
| 331 MaybeHandle<Name>(), |
| 332 Type::Any(), |
| 333 MachineType::AnyTagged(), |
| 334 kNoWriteBarrier}; |
| 335 |
| 336 StrictMock<MockAdvancedReducerEditor> editor; |
| 337 LoadElimination load_elimination(&editor, jsgraph(), zone()); |
| 338 |
| 339 load_elimination.Reduce(graph()->start()); |
| 340 |
| 341 Node* branch = graph()->NewNode(common()->Branch(), check, control); |
| 342 |
| 343 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 344 Node* etrue = graph()->NewNode(simplified()->LoadField(access), object, |
| 345 effect, if_true); |
| 346 load_elimination.Reduce(etrue); |
| 347 |
| 348 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 349 Node* efalse = effect; |
| 350 |
| 351 control = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 352 effect = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, control); |
| 353 load_elimination.Reduce(effect); |
| 354 |
| 355 Node* load = graph()->NewNode(simplified()->LoadField(access), object, effect, |
| 356 control); |
| 357 Reduction r = load_elimination.Reduce(load); |
| 358 ASSERT_TRUE(r.Changed()); |
| 359 EXPECT_EQ(load, r.replacement()); |
| 360 } |
| 361 |
216 } // namespace compiler | 362 } // namespace compiler |
217 } // namespace internal | 363 } // namespace internal |
218 } // namespace v8 | 364 } // namespace v8 |
OLD | NEW |