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/compiler/change-lowering.h" | 5 #include "src/compiler/change-lowering.h" |
6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/node-properties-inl.h" | 7 #include "src/compiler/node-properties-inl.h" |
8 #include "src/compiler/simplified-operator.h" | 8 #include "src/compiler/simplified-operator.h" |
9 #include "src/compiler/typer.h" | 9 #include "src/compiler/typer.h" |
10 #include "test/compiler-unittests/graph-unittest.h" | 10 #include "test/compiler-unittests/graph-unittest.h" |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 }; | 288 }; |
289 | 289 |
290 | 290 |
291 TARGET_TEST_F(ChangeLowering64Test, ChangeInt32ToTagged) { | 291 TARGET_TEST_F(ChangeLowering64Test, ChangeInt32ToTagged) { |
292 Node* val = Parameter(0); | 292 Node* val = Parameter(0); |
293 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val); | 293 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val); |
294 Reduction reduction = Reduce(node); | 294 Reduction reduction = Reduce(node); |
295 ASSERT_TRUE(reduction.Changed()); | 295 ASSERT_TRUE(reduction.Changed()); |
296 | 296 |
297 EXPECT_THAT(reduction.replacement(), | 297 EXPECT_THAT(reduction.replacement(), |
298 IsWord64Shl(val, IsInt32Constant(SmiShiftAmount()))); | 298 IsWord64Shl(IsChangeInt32ToInt64(val), |
| 299 IsInt32Constant(SmiShiftAmount()))); |
299 } | 300 } |
300 | 301 |
301 | 302 |
302 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToFloat64) { | 303 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToFloat64) { |
303 STATIC_ASSERT(kSmiTag == 0); | 304 STATIC_ASSERT(kSmiTag == 0); |
304 STATIC_ASSERT(kSmiTagSize == 1); | 305 STATIC_ASSERT(kSmiTagSize == 1); |
305 | 306 |
306 Node* val = Parameter(0); | 307 Node* val = Parameter(0); |
307 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); | 308 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); |
308 Reduction reduction = Reduce(node); | 309 Reduction reduction = Reduce(node); |
309 ASSERT_TRUE(reduction.Changed()); | 310 ASSERT_TRUE(reduction.Changed()); |
310 | 311 |
311 Node* phi = reduction.replacement(); | 312 Node* phi = reduction.replacement(); |
312 Capture<Node*> branch, if_true; | 313 Capture<Node*> branch, if_true; |
313 EXPECT_THAT( | 314 EXPECT_THAT( |
314 phi, | 315 phi, |
315 IsPhi( | 316 IsPhi( |
316 IsLoad(kMachFloat64, val, IsInt32Constant(HeapNumberValueOffset()), | 317 IsLoad(kMachFloat64, val, IsInt32Constant(HeapNumberValueOffset()), |
317 IsControlEffect(CaptureEq(&if_true))), | 318 IsControlEffect(CaptureEq(&if_true))), |
318 IsChangeInt32ToFloat64(IsConvertInt64ToInt32( | 319 IsChangeInt32ToFloat64(IsTruncateInt64ToInt32( |
319 IsWord64Sar(val, IsInt32Constant(SmiShiftAmount())))), | 320 IsWord64Sar(val, IsInt32Constant(SmiShiftAmount())))), |
320 IsMerge( | 321 IsMerge( |
321 AllOf(CaptureEq(&if_true), | 322 AllOf(CaptureEq(&if_true), |
322 IsIfTrue(AllOf( | 323 IsIfTrue(AllOf( |
323 CaptureEq(&branch), | 324 CaptureEq(&branch), |
324 IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)), | 325 IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)), |
325 graph()->start())))), | 326 graph()->start())))), |
326 IsIfFalse(CaptureEq(&branch))))); | 327 IsIfFalse(CaptureEq(&branch))))); |
327 } | 328 } |
328 | 329 |
329 | 330 |
330 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToInt32) { | 331 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToInt32) { |
331 STATIC_ASSERT(kSmiTag == 0); | 332 STATIC_ASSERT(kSmiTag == 0); |
332 STATIC_ASSERT(kSmiTagSize == 1); | 333 STATIC_ASSERT(kSmiTagSize == 1); |
333 | 334 |
334 Node* val = Parameter(0); | 335 Node* val = Parameter(0); |
335 Node* node = graph()->NewNode(simplified()->ChangeTaggedToInt32(), val); | 336 Node* node = graph()->NewNode(simplified()->ChangeTaggedToInt32(), val); |
336 Reduction reduction = Reduce(node); | 337 Reduction reduction = Reduce(node); |
337 ASSERT_TRUE(reduction.Changed()); | 338 ASSERT_TRUE(reduction.Changed()); |
338 | 339 |
339 Node* phi = reduction.replacement(); | 340 Node* phi = reduction.replacement(); |
340 Capture<Node*> branch, if_true; | 341 Capture<Node*> branch, if_true; |
341 EXPECT_THAT( | 342 EXPECT_THAT( |
342 phi, | 343 phi, |
343 IsPhi(IsChangeFloat64ToInt32(IsLoad( | 344 IsPhi(IsChangeFloat64ToInt32(IsLoad( |
344 kMachFloat64, val, IsInt32Constant(HeapNumberValueOffset()), | 345 kMachFloat64, val, IsInt32Constant(HeapNumberValueOffset()), |
345 IsControlEffect(CaptureEq(&if_true)))), | 346 IsControlEffect(CaptureEq(&if_true)))), |
346 IsConvertInt64ToInt32( | 347 IsTruncateInt64ToInt32( |
347 IsWord64Sar(val, IsInt32Constant(SmiShiftAmount()))), | 348 IsWord64Sar(val, IsInt32Constant(SmiShiftAmount()))), |
348 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), | 349 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), |
349 IsIfFalse(AllOf( | 350 IsIfFalse(AllOf( |
350 CaptureEq(&branch), | 351 CaptureEq(&branch), |
351 IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)), | 352 IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)), |
352 graph()->start())))))); | 353 graph()->start())))))); |
353 } | 354 } |
354 | 355 |
355 } // namespace compiler | 356 } // namespace compiler |
356 } // namespace internal | 357 } // namespace internal |
357 } // namespace v8 | 358 } // namespace v8 |
OLD | NEW |