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/code-stubs.h" | 5 #include "src/code-stubs.h" |
6 #include "src/compiler/change-lowering.h" | 6 #include "src/compiler/change-lowering.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/node-properties-inl.h" | 8 #include "src/compiler/node-properties-inl.h" |
9 #include "src/compiler/simplified-operator.h" | 9 #include "src/compiler/simplified-operator.h" |
10 #include "test/unittests/compiler/compiler-test-utils.h" | 10 #include "test/unittests/compiler/compiler-test-utils.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 virtual ~ChangeLowering32Test() {} | 181 virtual ~ChangeLowering32Test() {} |
182 virtual MachineType WordRepresentation() const FINAL OVERRIDE { | 182 virtual MachineType WordRepresentation() const FINAL OVERRIDE { |
183 return kRepWord32; | 183 return kRepWord32; |
184 } | 184 } |
185 }; | 185 }; |
186 | 186 |
187 | 187 |
188 TARGET_TEST_F(ChangeLowering32Test, ChangeInt32ToTagged) { | 188 TARGET_TEST_F(ChangeLowering32Test, ChangeInt32ToTagged) { |
189 Node* val = Parameter(0); | 189 Node* val = Parameter(0); |
190 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val); | 190 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val); |
| 191 NodeProperties::SetBounds(val, Bounds(Type::None(), Type::Signed32())); |
191 Reduction reduction = Reduce(node); | 192 Reduction reduction = Reduce(node); |
192 ASSERT_TRUE(reduction.Changed()); | 193 ASSERT_TRUE(reduction.Changed()); |
193 | 194 |
194 Node* phi = reduction.replacement(); | 195 Node* phi = reduction.replacement(); |
195 Capture<Node*> add, branch, heap_number, if_true; | 196 Capture<Node*> add, branch, heap_number, if_true; |
196 EXPECT_THAT( | 197 EXPECT_THAT( |
197 phi, | 198 phi, |
198 IsPhi(kMachAnyTagged, | 199 IsPhi(kMachAnyTagged, |
199 IsFinish(AllOf(CaptureEq(&heap_number), | 200 IsFinish(AllOf(CaptureEq(&heap_number), |
200 IsAllocateHeapNumber(_, CaptureEq(&if_true))), | 201 IsAllocateHeapNumber(_, CaptureEq(&if_true))), |
201 IsStore(StoreRepresentation(kMachFloat64, kNoWriteBarrier), | 202 IsStore(StoreRepresentation(kMachFloat64, kNoWriteBarrier), |
202 CaptureEq(&heap_number), | 203 CaptureEq(&heap_number), |
203 IsIntPtrConstant(HeapNumberValueOffset()), | 204 IsIntPtrConstant(HeapNumberValueOffset()), |
204 IsChangeInt32ToFloat64(val), | 205 IsChangeInt32ToFloat64(val), |
205 CaptureEq(&heap_number), CaptureEq(&if_true))), | 206 CaptureEq(&heap_number), CaptureEq(&if_true))), |
206 IsProjection( | 207 IsProjection( |
207 0, AllOf(CaptureEq(&add), IsInt32AddWithOverflow(val, val))), | 208 0, AllOf(CaptureEq(&add), IsInt32AddWithOverflow(val, val))), |
208 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), | 209 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), |
209 IsIfFalse(AllOf(CaptureEq(&branch), | 210 IsIfFalse(AllOf(CaptureEq(&branch), |
210 IsBranch(IsProjection(1, CaptureEq(&add)), | 211 IsBranch(IsProjection(1, CaptureEq(&add)), |
211 graph()->start())))))); | 212 graph()->start())))))); |
212 } | 213 } |
213 | 214 |
214 | 215 |
| 216 TARGET_TEST_F(ChangeLowering32Test, ChangeInt32ToTaggedSmall) { |
| 217 Node* val = Parameter(0); |
| 218 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val); |
| 219 NodeProperties::SetBounds(val, Bounds(Type::None(), Type::SignedSmall())); |
| 220 Reduction reduction = Reduce(node); |
| 221 ASSERT_TRUE(reduction.Changed()); |
| 222 |
| 223 Node* change = reduction.replacement(); |
| 224 Capture<Node*> add, branch, heap_number, if_true; |
| 225 EXPECT_THAT(change, IsWord32Shl(val, IsInt32Constant(SmiShiftAmount()))); |
| 226 } |
| 227 |
| 228 |
215 TARGET_TEST_F(ChangeLowering32Test, ChangeTaggedToFloat64) { | 229 TARGET_TEST_F(ChangeLowering32Test, ChangeTaggedToFloat64) { |
216 STATIC_ASSERT(kSmiTag == 0); | 230 STATIC_ASSERT(kSmiTag == 0); |
217 STATIC_ASSERT(kSmiTagSize == 1); | 231 STATIC_ASSERT(kSmiTagSize == 1); |
218 | 232 |
219 Node* val = Parameter(0); | 233 Node* val = Parameter(0); |
220 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); | 234 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); |
221 Reduction reduction = Reduce(node); | 235 Reduction reduction = Reduce(node); |
222 ASSERT_TRUE(reduction.Changed()); | 236 ASSERT_TRUE(reduction.Changed()); |
223 | 237 |
224 Node* phi = reduction.replacement(); | 238 Node* phi = reduction.replacement(); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 IsIfTrue(AllOf(CaptureEq(&branch), | 461 IsIfTrue(AllOf(CaptureEq(&branch), |
448 IsBranch(IsUint32LessThanOrEqual( | 462 IsBranch(IsUint32LessThanOrEqual( |
449 val, IsInt32Constant(SmiMaxValue())), | 463 val, IsInt32Constant(SmiMaxValue())), |
450 graph()->start()))), | 464 graph()->start()))), |
451 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); | 465 AllOf(CaptureEq(&if_false), IsIfFalse(CaptureEq(&branch)))))); |
452 } | 466 } |
453 | 467 |
454 } // namespace compiler | 468 } // namespace compiler |
455 } // namespace internal | 469 } // namespace internal |
456 } // namespace v8 | 470 } // namespace v8 |
OLD | NEW |