Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: test/compiler-unittests/change-lowering-unittest.cc

Issue 481903002: [turbofan] Support lowering of ChangeFloat64ToTagged/ChangeTaggedToInt32. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 Capture<Node*> branch; 78 Capture<Node*> branch;
79 EXPECT_THAT( 79 EXPECT_THAT(
80 phi, IsPhi(IsHeapConstant(this->true_unique()), 80 phi, IsPhi(IsHeapConstant(this->true_unique()),
81 IsHeapConstant(this->false_unique()), 81 IsHeapConstant(this->false_unique()),
82 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch), 82 IsMerge(IsIfTrue(AllOf(CaptureEq(&branch),
83 IsBranch(val, this->graph()->start()))), 83 IsBranch(val, this->graph()->start()))),
84 IsIfFalse(CaptureEq(&branch))))); 84 IsIfFalse(CaptureEq(&branch)))));
85 } 85 }
86 86
87 87
88 TARGET_TYPED_TEST(ChangeLoweringTest, ChangeFloat64ToTagged) {
89 Node* val = this->Parameter(0);
90 Node* node =
91 this->graph()->NewNode(this->simplified()->ChangeFloat64ToTagged(), val);
92 Reduction reduction = this->Reduce(node);
93 ASSERT_TRUE(reduction.Changed());
94
95 Node* finish = reduction.replacement();
96 Capture<Node*> heap_number;
97 const int32_t kValueOffset = this->kHeapNumberValueOffset - kHeapObjectTag;
98 EXPECT_THAT(
99 finish,
100 IsFinish(AllOf(CaptureEq(&heap_number),
101 this->IsAllocateHeapNumber(IsValueEffect(val),
102 this->graph()->start())),
103 IsStore(kMachFloat64, kNoWriteBarrier, CaptureEq(&heap_number),
104 IsInt32Constant(kValueOffset), val,
105 CaptureEq(&heap_number), this->graph()->start())));
106 }
107
108
88 TARGET_TYPED_TEST(ChangeLoweringTest, StringAdd) { 109 TARGET_TYPED_TEST(ChangeLoweringTest, StringAdd) {
89 Node* node = this->graph()->NewNode(this->simplified()->StringAdd(), 110 Node* node = this->graph()->NewNode(this->simplified()->StringAdd(),
90 this->Parameter(0), this->Parameter(1)); 111 this->Parameter(0), this->Parameter(1));
91 Reduction reduction = this->Reduce(node); 112 Reduction reduction = this->Reduce(node);
92 EXPECT_FALSE(reduction.Changed()); 113 EXPECT_FALSE(reduction.Changed());
93 } 114 }
94 115
95 116
96 class ChangeLowering32Test : public ChangeLoweringTest<int32_t> { 117 class ChangeLowering32Test : public ChangeLoweringTest<int32_t> {
97 public: 118 public:
(...skipping 16 matching lines...) Expand all
114 Node* val = Parameter(0); 135 Node* val = Parameter(0);
115 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val); 136 Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val);
116 Reduction reduction = Reduce(node); 137 Reduction reduction = Reduce(node);
117 ASSERT_TRUE(reduction.Changed()); 138 ASSERT_TRUE(reduction.Changed());
118 139
119 Node* phi = reduction.replacement(); 140 Node* phi = reduction.replacement();
120 Capture<Node*> add, branch, heap_number, if_true; 141 Capture<Node*> add, branch, heap_number, if_true;
121 const int32_t kValueOffset = kHeapNumberValueOffset - kHeapObjectTag; 142 const int32_t kValueOffset = kHeapNumberValueOffset - kHeapObjectTag;
122 EXPECT_THAT( 143 EXPECT_THAT(
123 phi, 144 phi,
124 IsPhi( 145 IsPhi(IsFinish(
125 IsFinish( 146 AllOf(CaptureEq(&heap_number),
126 AllOf( 147 IsAllocateHeapNumber(_, CaptureEq(&if_true))),
127 CaptureEq(&heap_number), 148 IsStore(kMachFloat64, kNoWriteBarrier, CaptureEq(&heap_number),
128 IsCall( 149 IsInt32Constant(kValueOffset),
129 _, IsHeapConstant( 150 IsChangeInt32ToFloat64(val), CaptureEq(&heap_number),
130 PrintableUnique<HeapObject>::CreateImmovable( 151 CaptureEq(&if_true))),
131 zone(), CEntryStub(isolate(), 1).GetCode())), 152 IsProjection(
132 IsExternalConstant(ExternalReference( 153 0, AllOf(CaptureEq(&add), IsInt32AddWithOverflow(val, val))),
133 Runtime::FunctionForId(Runtime::kAllocateHeapNumber), 154 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))),
134 isolate())), 155 IsIfFalse(AllOf(CaptureEq(&branch),
135 IsInt32Constant(0), IsNumberConstant(0.0), 156 IsBranch(IsProjection(1, CaptureEq(&add)),
136 graph()->start(), CaptureEq(&if_true))), 157 graph()->start()))))));
137 IsStore(kMachFloat64, kNoWriteBarrier, CaptureEq(&heap_number),
138 IsInt32Constant(kValueOffset),
139 IsChangeInt32ToFloat64(val), CaptureEq(&heap_number),
140 CaptureEq(&if_true))),
141 IsProjection(
142 0, AllOf(CaptureEq(&add), IsInt32AddWithOverflow(val, val))),
143 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))),
144 IsIfFalse(AllOf(CaptureEq(&branch),
145 IsBranch(IsProjection(1, CaptureEq(&add)),
146 graph()->start()))))));
147 } 158 }
148 159
149 160
150 TARGET_TEST_F(ChangeLowering32Test, ChangeTaggedToFloat64) { 161 TARGET_TEST_F(ChangeLowering32Test, ChangeTaggedToFloat64) {
151 STATIC_ASSERT(kSmiTag == 0); 162 STATIC_ASSERT(kSmiTag == 0);
152 STATIC_ASSERT(kSmiTagSize == 1); 163 STATIC_ASSERT(kSmiTagSize == 1);
153 164
154 Node* val = Parameter(0); 165 Node* val = Parameter(0);
155 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val); 166 Node* node = graph()->NewNode(simplified()->ChangeTaggedToFloat64(), val);
156 Reduction reduction = Reduce(node); 167 Reduction reduction = Reduce(node);
(...skipping 14 matching lines...) Expand all
171 IsMerge( 182 IsMerge(
172 AllOf(CaptureEq(&if_true), 183 AllOf(CaptureEq(&if_true),
173 IsIfTrue(AllOf( 184 IsIfTrue(AllOf(
174 CaptureEq(&branch), 185 CaptureEq(&branch),
175 IsBranch(IsWord32And(val, IsInt32Constant(kSmiTagMask)), 186 IsBranch(IsWord32And(val, IsInt32Constant(kSmiTagMask)),
176 graph()->start())))), 187 graph()->start())))),
177 IsIfFalse(CaptureEq(&branch))))); 188 IsIfFalse(CaptureEq(&branch)))));
178 } 189 }
179 190
180 191
192 TARGET_TEST_F(ChangeLowering32Test, ChangeTaggedToInt32) {
193 STATIC_ASSERT(kSmiTag == 0);
194 STATIC_ASSERT(kSmiTagSize == 1);
195
196 Node* val = Parameter(0);
197 Node* node = graph()->NewNode(simplified()->ChangeTaggedToInt32(), val);
198 Reduction reduction = Reduce(node);
199 ASSERT_TRUE(reduction.Changed());
200
201 const int32_t kShiftAmount =
202 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize;
203 const int32_t kValueOffset = kHeapNumberValueOffset - kHeapObjectTag;
204 Node* phi = reduction.replacement();
205 Capture<Node*> branch, if_true;
206 EXPECT_THAT(
207 phi,
208 IsPhi(IsChangeFloat64ToInt32(
209 IsLoad(kMachFloat64, val, IsInt32Constant(kValueOffset),
210 IsControlEffect(CaptureEq(&if_true)))),
211 IsWord32Sar(val, IsInt32Constant(kShiftAmount)),
212 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))),
213 IsIfFalse(AllOf(
214 CaptureEq(&branch),
215 IsBranch(IsWord32And(val, IsInt32Constant(kSmiTagMask)),
216 graph()->start()))))));
217 }
218
219
181 class ChangeLowering64Test : public ChangeLoweringTest<int64_t> { 220 class ChangeLowering64Test : public ChangeLoweringTest<int64_t> {
182 public: 221 public:
183 virtual ~ChangeLowering64Test() {} 222 virtual ~ChangeLowering64Test() {}
184 }; 223 };
185 224
186 225
187 TARGET_TEST_F(ChangeLowering64Test, ChangeBoolToBit) { 226 TARGET_TEST_F(ChangeLowering64Test, ChangeBoolToBit) {
188 Node* val = Parameter(0); 227 Node* val = Parameter(0);
189 Node* node = graph()->NewNode(simplified()->ChangeBoolToBit(), val); 228 Node* node = graph()->NewNode(simplified()->ChangeBoolToBit(), val);
190 Reduction reduction = Reduce(node); 229 Reduction reduction = Reduce(node);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 IsWord64Sar(val, IsInt32Constant(kShiftAmount)))), 270 IsWord64Sar(val, IsInt32Constant(kShiftAmount)))),
232 IsMerge( 271 IsMerge(
233 AllOf(CaptureEq(&if_true), 272 AllOf(CaptureEq(&if_true),
234 IsIfTrue(AllOf( 273 IsIfTrue(AllOf(
235 CaptureEq(&branch), 274 CaptureEq(&branch),
236 IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)), 275 IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)),
237 graph()->start())))), 276 graph()->start())))),
238 IsIfFalse(CaptureEq(&branch))))); 277 IsIfFalse(CaptureEq(&branch)))));
239 } 278 }
240 279
280
281 TARGET_TEST_F(ChangeLowering64Test, ChangeTaggedToInt32) {
282 STATIC_ASSERT(kSmiTag == 0);
283 STATIC_ASSERT(kSmiTagSize == 1);
284
285 Node* val = Parameter(0);
286 Node* node = graph()->NewNode(simplified()->ChangeTaggedToInt32(), val);
287 Reduction reduction = Reduce(node);
288 ASSERT_TRUE(reduction.Changed());
289
290 const int32_t kShiftAmount =
291 kSmiTagSize + SmiTagging<kPointerSize>::kSmiShiftSize;
292 const int32_t kValueOffset = kHeapNumberValueOffset - kHeapObjectTag;
293 Node* phi = reduction.replacement();
294 Capture<Node*> branch, if_true;
295 EXPECT_THAT(
296 phi,
297 IsPhi(IsChangeFloat64ToInt32(
298 IsLoad(kMachFloat64, val, IsInt32Constant(kValueOffset),
299 IsControlEffect(CaptureEq(&if_true)))),
300 IsConvertInt64ToInt32(
301 IsWord64Sar(val, IsInt32Constant(kShiftAmount))),
302 IsMerge(AllOf(CaptureEq(&if_true), IsIfTrue(CaptureEq(&branch))),
303 IsIfFalse(AllOf(
304 CaptureEq(&branch),
305 IsBranch(IsWord64And(val, IsInt32Constant(kSmiTagMask)),
306 graph()->start()))))));
307 }
308
241 } // namespace compiler 309 } // namespace compiler
242 } // namespace internal 310 } // namespace internal
243 } // namespace v8 311 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698