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

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

Issue 792463003: [turbofan] Turn JSToBoolean and JSUnaryNot into pure operators. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years 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
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/access-builder.h" 5 #include "src/compiler/access-builder.h"
6 #include "src/compiler/js-graph.h" 6 #include "src/compiler/js-graph.h"
7 #include "src/compiler/js-operator.h" 7 #include "src/compiler/js-operator.h"
8 #include "src/compiler/js-typed-lowering.h" 8 #include "src/compiler/js-typed-lowering.h"
9 #include "src/compiler/machine-operator.h" 9 #include "src/compiler/machine-operator.h"
10 #include "src/compiler/node-properties-inl.h" 10 #include "src/compiler/node-properties-inl.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 private: 72 private:
73 JSOperatorBuilder javascript_; 73 JSOperatorBuilder javascript_;
74 }; 74 };
75 75
76 76
77 // ----------------------------------------------------------------------------- 77 // -----------------------------------------------------------------------------
78 // JSToBoolean 78 // JSToBoolean
79 79
80 80
81 TEST_F(JSTypedLoweringTest, JSToBooleanWithBoolean) {
82 Node* input = Parameter(Type::Boolean());
83 Node* context = UndefinedConstant();
84
85 Reduction r =
86 Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context));
87 ASSERT_TRUE(r.Changed());
88 EXPECT_EQ(input, r.replacement());
89 }
90
91
92 TEST_F(JSTypedLoweringTest, JSToBooleanWithUndefined) {
93 Node* input = Parameter(Type::Undefined());
94 Node* context = UndefinedConstant();
95
96 Reduction r =
97 Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context));
98 ASSERT_TRUE(r.Changed());
99 EXPECT_THAT(r.replacement(), IsFalseConstant());
100 }
101
102
103 TEST_F(JSTypedLoweringTest, JSToBooleanWithNull) {
104 Node* input = Parameter(Type::Null());
105 Node* context = UndefinedConstant();
106
107 Reduction r =
108 Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context));
109 ASSERT_TRUE(r.Changed());
110 EXPECT_THAT(r.replacement(), IsFalseConstant());
111 }
112
113
114 TEST_F(JSTypedLoweringTest, JSToBooleanWithDetectableReceiver) {
115 Node* input = Parameter(Type::DetectableReceiver());
116 Node* context = UndefinedConstant();
117
118 Reduction r =
119 Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context));
120 ASSERT_TRUE(r.Changed());
121 EXPECT_THAT(r.replacement(), IsTrueConstant());
122 }
123
124
125 TEST_F(JSTypedLoweringTest, JSToBooleanWithUndetectable) {
126 Node* input = Parameter(Type::Undetectable());
127 Node* context = UndefinedConstant();
128
129 Reduction r =
130 Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context));
131 ASSERT_TRUE(r.Changed());
132 EXPECT_THAT(r.replacement(), IsFalseConstant());
133 }
134
135
136 TEST_F(JSTypedLoweringTest, JSToBooleanWithOrderedNumber) {
137 Node* input = Parameter(Type::OrderedNumber());
138 Node* context = UndefinedConstant();
139
140 Reduction r =
141 Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context));
142 ASSERT_TRUE(r.Changed());
143 EXPECT_THAT(r.replacement(),
144 IsBooleanNot(IsNumberEqual(input, IsNumberConstant(0))));
145 }
146
147
81 TEST_F(JSTypedLoweringTest, JSToBooleanWithString) { 148 TEST_F(JSTypedLoweringTest, JSToBooleanWithString) {
82 Node* input = Parameter(Type::String()); 149 Node* input = Parameter(Type::String());
83 Node* context = UndefinedConstant(); 150 Node* context = UndefinedConstant();
84 Node* effect = graph()->start();
85 Node* control = graph()->start();
86 151
87 Reduction r = Reduce(graph()->NewNode(javascript()->ToBoolean(), input, 152 Reduction r =
88 context, effect, control)); 153 Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context));
89 ASSERT_TRUE(r.Changed()); 154 ASSERT_TRUE(r.Changed());
90 EXPECT_THAT(r.replacement(), 155 EXPECT_THAT(r.replacement(),
91 IsBooleanNot(IsNumberEqual( 156 IsBooleanNot(IsNumberEqual(
92 IsLoadField(AccessBuilder::ForStringLength(), input, 157 IsLoadField(AccessBuilder::ForStringLength(), input,
93 graph()->start(), graph()->start()), 158 graph()->start(), graph()->start()),
94 IsNumberConstant(0)))); 159 IsNumberConstant(0))));
95 } 160 }
96 161
97 162
98 TEST_F(JSTypedLoweringTest, JSToBooleanWithOrderedNumberAndBoolean) { 163 TEST_F(JSTypedLoweringTest, JSToBooleanWithPhi) {
99 Node* p0 = Parameter(Type::OrderedNumber(), 0); 164 Node* p0 = Parameter(Type::OrderedNumber(), 0);
100 Node* p1 = Parameter(Type::Boolean(), 1); 165 Node* p1 = Parameter(Type::Boolean(), 1);
101 Node* context = UndefinedConstant(); 166 Node* context = UndefinedConstant();
102 Node* effect = graph()->start();
103 Node* control = graph()->start(); 167 Node* control = graph()->start();
104 168
105 Reduction r = Reduce(graph()->NewNode( 169 Reduction r = Reduce(graph()->NewNode(
106 javascript()->ToBoolean(), 170 javascript()->ToBoolean(),
107 graph()->NewNode(common()->Phi(kMachAnyTagged, 2), p0, p1, control), 171 graph()->NewNode(common()->Phi(kMachAnyTagged, 2), p0, p1, control),
108 context, effect, control)); 172 context));
109 ASSERT_TRUE(r.Changed()); 173 ASSERT_TRUE(r.Changed());
110 EXPECT_THAT( 174 EXPECT_THAT(
111 r.replacement(), 175 r.replacement(),
112 IsPhi(kMachAnyTagged, 176 IsPhi(kMachAnyTagged,
113 IsBooleanNot(IsNumberEqual(p0, IsNumberConstant(0))), p1, control)); 177 IsBooleanNot(IsNumberEqual(p0, IsNumberConstant(0))), p1, control));
114 } 178 }
115 179
116 180
181 TEST_F(JSTypedLoweringTest, JSToBooleanWithSelect) {
182 Node* p0 = Parameter(Type::Boolean(), 0);
183 Node* p1 = Parameter(Type::DetectableReceiver(), 1);
184 Node* p2 = Parameter(Type::OrderedNumber(), 2);
185 Node* context = UndefinedConstant();
186
187 Reduction r = Reduce(graph()->NewNode(
188 javascript()->ToBoolean(),
189 graph()->NewNode(common()->Select(kMachAnyTagged, BranchHint::kTrue), p0,
190 p1, p2),
191 context));
192 ASSERT_TRUE(r.Changed());
193 EXPECT_THAT(r.replacement(),
194 IsSelect(kMachAnyTagged, p0, IsTrueConstant(),
195 IsBooleanNot(IsNumberEqual(p2, IsNumberConstant(0)))));
196 }
197
198
117 // ----------------------------------------------------------------------------- 199 // -----------------------------------------------------------------------------
118 // JSStrictEqual 200 // JSStrictEqual
119 201
120 202
121 TEST_F(JSTypedLoweringTest, JSStrictEqualWithTheHole) { 203 TEST_F(JSTypedLoweringTest, JSStrictEqualWithTheHole) {
122 Node* const the_hole = HeapConstant(factory()->the_hole_value()); 204 Node* const the_hole = HeapConstant(factory()->the_hole_value());
123 Node* const context = UndefinedConstant(); 205 Node* const context = UndefinedConstant();
124 Node* const effect = graph()->start(); 206 Node* const effect = graph()->start();
125 Node* const control = graph()->start(); 207 Node* const control = graph()->start();
126 TRACED_FOREACH(Type*, type, kJSTypes) { 208 TRACED_FOREACH(Type*, type, kJSTypes) {
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 IsStoreElement( 615 IsStoreElement(
534 access, IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])), 616 access, IsIntPtrConstant(bit_cast<intptr_t>(&backing_store[0])),
535 key, value, effect, control)); 617 key, value, effect, control));
536 } 618 }
537 } 619 }
538 } 620 }
539 621
540 } // namespace compiler 622 } // namespace compiler
541 } // namespace internal 623 } // namespace internal
542 } // namespace v8 624 } // namespace v8
OLDNEW
« src/compiler/js-typed-lowering.h ('K') | « test/unittests/compiler/js-operator-unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698