| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 } | 110 } |
| 111 | 111 |
| 112 | 112 |
| 113 TARGET_TEST_F(ChangeLowering32Test, ChangeInt32ToTagged) { | 113 TARGET_TEST_F(ChangeLowering32Test, ChangeInt32ToTagged) { |
| 114 Node* val = Parameter(0); | 114 Node* val = Parameter(0); |
| 115 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val); | 115 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val); |
| 116 Reduction reduction = Reduce(node); | 116 Reduction reduction = Reduce(node); |
| 117 ASSERT_TRUE(reduction.Changed()); | 117 ASSERT_TRUE(reduction.Changed()); |
| 118 | 118 |
| 119 Node* phi = reduction.replacement(); | 119 Node* phi = reduction.replacement(); |
| 120 ASSERT_EQ(IrOpcode::kPhi, phi->opcode()); | 120 Capture<Node*> add, branch, heap_number, if_true; |
| 121 | |
| 122 Node* smi = NodeProperties::GetValueInput(phi, 1); | |
| 123 ASSERT_THAT(smi, IsProjection(0, IsInt32AddWithOverflow(val, val))); | |
| 124 | |
| 125 Node* heap_number = NodeProperties::GetValueInput(phi, 0); | |
| 126 ASSERT_EQ(IrOpcode::kCall, heap_number->opcode()); | |
| 127 | |
| 128 Node* merge = NodeProperties::GetControlInput(phi); | |
| 129 ASSERT_EQ(IrOpcode::kMerge, merge->opcode()); | |
| 130 | |
| 131 const int32_t kValueOffset = kHeapNumberValueOffset - kHeapObjectTag; | 121 const int32_t kValueOffset = kHeapNumberValueOffset - kHeapObjectTag; |
| 132 EXPECT_THAT(NodeProperties::GetControlInput(merge, 0), | 122 EXPECT_THAT( |
| 133 IsStore(kMachFloat64, kNoWriteBarrier, heap_number, | 123 phi, |
| 124 IsPhi( |
| 125 IsFinish( |
| 126 AllOf( |
| 127 CaptureEq(&heap_number), |
| 128 IsCall( |
| 129 _, IsHeapConstant( |
| 130 PrintableUnique<HeapObject>::CreateImmovable( |
| 131 zone(), CEntryStub(isolate(), 1).GetCode())), |
| 132 IsExternalConstant(ExternalReference( |
| 133 Runtime::FunctionForId(Runtime::kAllocateHeapNumber), |
| 134 isolate())), |
| 135 IsInt32Constant(0), IsNumberConstant(0.0), |
| 136 graph()->start(), CaptureEq(&if_true))), |
| 137 IsStore(kMachFloat64, kNoWriteBarrier, CaptureEq(&heap_number), |
| 134 IsInt32Constant(kValueOffset), | 138 IsInt32Constant(kValueOffset), |
| 135 IsChangeInt32ToFloat64(val), _, heap_number)); | 139 IsChangeInt32ToFloat64(val), CaptureEq(&heap_number), |
| 136 | 140 CaptureEq(&if_true))), |
| 137 Node* if_true = NodeProperties::GetControlInput(heap_number); | 141 IsProjection( |
| 138 ASSERT_EQ(IrOpcode::kIfTrue, if_true->opcode()); | 142 0, AllOf(CaptureEq(&add), IsInt32AddWithOverflow(val, val))), |
| 139 | 143 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))), |
| 140 Node* if_false = NodeProperties::GetControlInput(merge, 1); | 144 IsIfFalse(AllOf(CaptureEq(&branch), |
| 141 ASSERT_EQ(IrOpcode::kIfFalse, if_false->opcode()); | 145 IsBranch(IsProjection(1, CaptureEq(&add)), |
| 142 | 146 graph()->start())))))); |
| 143 Node* branch = NodeProperties::GetControlInput(if_true); | |
| 144 EXPECT_EQ(branch, NodeProperties::GetControlInput(if_false)); | |
| 145 EXPECT_THAT(branch, | |
| 146 IsBranch(IsProjection(1, IsInt32AddWithOverflow(val, val)), | |
| 147 graph()->start())); | |
| 148 } | 147 } |
| 149 | 148 |
| 150 | 149 |
| 151 TARGET_TEST_F(ChangeLowering32Test, ChangeTaggedToFloat64) { | 150 TARGET_TEST_F(ChangeLowering32Test, ChangeTaggedToFloat64) { |
| 152 STATIC_ASSERT(kSmiTag == 0); | 151 STATIC_ASSERT(kSmiTag == 0); |
| 153 STATIC_ASSERT(kSmiTagSize == 1); | 152 STATIC_ASSERT(kSmiTagSize == 1); |
| 154 | 153 |
| 155 Node* val = Parameter(0); | 154 Node* val = Parameter(0); |
| 156 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); | 155 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); |
| 157 Reduction reduction = Reduce(node); | 156 Reduction reduction = Reduce(node); |
| 158 ASSERT_TRUE(reduction.Changed()); | 157 ASSERT_TRUE(reduction.Changed()); |
| 159 | 158 |
| 160 const int32_t kShiftAmount = | 159 const int32_t kShiftAmount = |
| 161 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize; | 160 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize; |
| 162 const int32_t kValueOffset = kHeapNumberValueOffset - kHeapObjectTag; | 161 const int32_t kValueOffset = kHeapNumberValueOffset - kHeapObjectTag; |
| 163 Node* phi = reduction.replacement(); | 162 Node* phi = reduction.replacement(); |
| 164 Capture<Node*> branch; | 163 Capture<Node*> branch, if_true; |
| 165 EXPECT_THAT( | 164 EXPECT_THAT( |
| 166 phi, | 165 phi, |
| 167 IsPhi(IsLoad(kMachFloat64, val, IsInt32Constant(kValueOffset), _), | 166 IsPhi( |
| 168 IsChangeInt32ToFloat64( | 167 IsLoad(kMachFloat64, val, IsInt32Constant(kValueOffset), |
| 169 IsWord32Sar(val, IsInt32Constant(kShiftAmount))), | 168 IsControlEffect(CaptureEq(&if_true))), |
| 170 IsMerge(IsIfTrue(AllOf( | 169 IsChangeInt32ToFloat64( |
| 170 IsWord32Sar(val, IsInt32Constant(kShiftAmount))), |
| 171 IsMerge( |
| 172 AllOf(CaptureEq(&if_true), |
| 173 IsIfTrue(AllOf( |
| 171 CaptureEq(&branch), | 174 CaptureEq(&branch), |
| 172 IsBranch(IsWord32And(val, IsInt32Constant(kSmiTagMask)), | 175 IsBranch(IsWord32And(val, IsInt32Constant(kSmiTagMask)), |
| 173 graph()->start()))), | 176 graph()->start())))), |
| 174 IsIfFalse(CaptureEq(&branch))))); | 177 IsIfFalse(CaptureEq(&branch))))); |
| 175 } | 178 } |
| 176 | 179 |
| 177 | 180 |
| 178 class ChangeLowering64Test : public ChangeLoweringTest<int64_t> { | 181 class ChangeLowering64Test : public ChangeLoweringTest<int64_t> { |
| 179 public: | 182 public: |
| 180 virtual ~ChangeLowering64Test() {} | 183 virtual ~ChangeLowering64Test() {} |
| 181 }; | 184 }; |
| 182 | 185 |
| 183 | 186 |
| 184 TARGET_TEST_F(ChangeLowering64Test, ChangeBoolToBit) { | 187 TARGET_TEST_F(ChangeLowering64Test, ChangeBoolToBit) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 211 | 214 |
| 212 Node* val = Parameter(0); | 215 Node* val = Parameter(0); |
| 213 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); | 216 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); |
| 214 Reduction reduction = Reduce(node); | 217 Reduction reduction = Reduce(node); |
| 215 ASSERT_TRUE(reduction.Changed()); | 218 ASSERT_TRUE(reduction.Changed()); |
| 216 | 219 |
| 217 const int32_t kShiftAmount = | 220 const int32_t kShiftAmount = |
| 218 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize; | 221 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize; |
| 219 const int32_t kValueOffset = kHeapNumberValueOffset - kHeapObjectTag; | 222 const int32_t kValueOffset = kHeapNumberValueOffset - kHeapObjectTag; |
| 220 Node* phi = reduction.replacement(); | 223 Node* phi = reduction.replacement(); |
| 221 Capture<Node*> branch; | 224 Capture<Node*> branch, if_true; |
| 222 EXPECT_THAT( | 225 EXPECT_THAT( |
| 223 phi, | 226 phi, |
| 224 IsPhi(IsLoad(kMachFloat64, val, IsInt32Constant(kValueOffset), _), | 227 IsPhi( |
| 225 IsChangeInt32ToFloat64(IsConvertInt64ToInt32( | 228 IsLoad(kMachFloat64, val, IsInt32Constant(kValueOffset), |
| 226 IsWord64Sar(val, IsInt32Constant(kShiftAmount)))), | 229 IsControlEffect(CaptureEq(&if_true))), |
| 227 IsMerge(IsIfTrue(AllOf( | 230 IsChangeInt32ToFloat64(IsConvertInt64ToInt32( |
| 231 IsWord64Sar(val, IsInt32Constant(kShiftAmount)))), |
| 232 IsMerge( |
| 233 AllOf(CaptureEq(&if_true), |
| 234 IsIfTrue(AllOf( |
| 228 CaptureEq(&branch), | 235 CaptureEq(&branch), |
| 229 IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)), | 236 IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)), |
| 230 graph()->start()))), | 237 graph()->start())))), |
| 231 IsIfFalse(CaptureEq(&branch))))); | 238 IsIfFalse(CaptureEq(&branch))))); |
| 232 } | 239 } |
| 233 | 240 |
| 234 } // namespace compiler | 241 } // namespace compiler |
| 235 } // namespace internal | 242 } // namespace internal |
| 236 } // namespace v8 | 243 } // namespace v8 |
| OLD | NEW |