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

Side by Side Diff: src/compiler/change-lowering.cc

Issue 1420913003: [turbofan] Try hard(er) to use smi representation for float64 values. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove unittest for now. Will need new ones, once we know what we want. Created 5 years, 1 month 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
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-460937.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/compiler/js-graph.h" 8 #include "src/compiler/js-graph.h"
9 #include "src/compiler/linkage.h" 9 #include "src/compiler/linkage.h"
10 #include "src/compiler/machine-operator.h" 10 #include "src/compiler/machine-operator.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 144 }
145 145
146 146
147 Reduction ChangeLowering::ChangeBoolToBit(Node* value) { 147 Reduction ChangeLowering::ChangeBoolToBit(Node* value) {
148 return Replace(graph()->NewNode(machine()->WordEqual(), value, 148 return Replace(graph()->NewNode(machine()->WordEqual(), value,
149 jsgraph()->TrueConstant())); 149 jsgraph()->TrueConstant()));
150 } 150 }
151 151
152 152
153 Reduction ChangeLowering::ChangeFloat64ToTagged(Node* value, Node* control) { 153 Reduction ChangeLowering::ChangeFloat64ToTagged(Node* value, Node* control) {
154 return Replace(AllocateHeapNumberWithValue(value, control)); 154 Type* const value_type = NodeProperties::GetType(value);
155 Node* const value32 = graph()->NewNode(
156 machine()->TruncateFloat64ToInt32(TruncationMode::kRoundToZero), value);
157 // TODO(bmeurer): This fast case must be disabled until we kill the asm.js
158 // support in the generic JavaScript pipeline, because LoadBuffer is lying
159 // about its result.
160 // if (value_type->Is(Type::Signed32())) {
161 // return ChangeInt32ToTagged(value32, control);
162 // }
163 Node* check_same = graph()->NewNode(
164 machine()->Float64Equal(), value,
165 graph()->NewNode(machine()->ChangeInt32ToFloat64(), value32));
166 Node* branch_same = graph()->NewNode(common()->Branch(), check_same, control);
167
168 Node* if_smi = graph()->NewNode(common()->IfTrue(), branch_same);
169 Node* vsmi;
170 Node* if_box = graph()->NewNode(common()->IfFalse(), branch_same);
171 Node* vbox;
172
173 // We only need to check for -0 if the {value} can potentially contain -0.
174 if (value_type->Maybe(Type::MinusZero())) {
175 Node* check_zero = graph()->NewNode(machine()->Word32Equal(), value32,
176 jsgraph()->Int32Constant(0));
177 Node* branch_zero = graph()->NewNode(common()->Branch(BranchHint::kFalse),
178 check_zero, if_smi);
179
180 Node* if_zero = graph()->NewNode(common()->IfTrue(), branch_zero);
181 Node* if_notzero = graph()->NewNode(common()->IfFalse(), branch_zero);
182
183 // In case of 0, we need to check the high bits for the IEEE -0 pattern.
184 Node* check_negative = graph()->NewNode(
185 machine()->Int32LessThan(),
186 graph()->NewNode(machine()->Float64ExtractHighWord32(), value),
187 jsgraph()->Int32Constant(0));
188 Node* branch_negative = graph()->NewNode(
189 common()->Branch(BranchHint::kFalse), check_negative, if_zero);
190
191 Node* if_negative = graph()->NewNode(common()->IfTrue(), branch_negative);
192 Node* if_notnegative =
193 graph()->NewNode(common()->IfFalse(), branch_negative);
194
195 // We need to create a box for negative 0.
196 if_smi = graph()->NewNode(common()->Merge(2), if_notzero, if_notnegative);
197 if_box = graph()->NewNode(common()->Merge(2), if_box, if_negative);
198 }
199
200 // On 64-bit machines we can just wrap the 32-bit integer in a smi, for 32-bit
201 // machines we need to deal with potential overflow and fallback to boxing.
202 if (machine()->Is64() || value_type->Is(Type::SignedSmall())) {
203 vsmi = ChangeInt32ToSmi(value32);
204 } else {
205 Node* smi_tag =
206 graph()->NewNode(machine()->Int32AddWithOverflow(), value32, value32);
207
208 Node* check_ovf = graph()->NewNode(common()->Projection(1), smi_tag);
209 Node* branch_ovf = graph()->NewNode(common()->Branch(BranchHint::kFalse),
210 check_ovf, if_smi);
211
212 Node* if_ovf = graph()->NewNode(common()->IfTrue(), branch_ovf);
213 if_box = graph()->NewNode(common()->Merge(2), if_ovf, if_box);
214
215 if_smi = graph()->NewNode(common()->IfFalse(), branch_ovf);
216 vsmi = graph()->NewNode(common()->Projection(0), smi_tag);
217 }
218
219 // Allocate the box for the {value}.
220 vbox = AllocateHeapNumberWithValue(value, if_box);
221
222 control = graph()->NewNode(common()->Merge(2), if_smi, if_box);
223 value =
224 graph()->NewNode(common()->Phi(kMachAnyTagged, 2), vsmi, vbox, control);
225 return Replace(value);
Jarin 2015/10/27 15:17:03 Just wondering - is there a reason to not use sele
Benedikt Meurer 2015/10/27 16:16:18 Allocate requires a control input.
155 } 226 }
156 227
157 228
158 Reduction ChangeLowering::ChangeInt32ToTagged(Node* value, Node* control) { 229 Reduction ChangeLowering::ChangeInt32ToTagged(Node* value, Node* control) {
159 if (machine()->Is64() || 230 if (machine()->Is64() ||
160 NodeProperties::GetType(value)->Is(Type::SignedSmall())) { 231 NodeProperties::GetType(value)->Is(Type::SignedSmall())) {
161 return Replace(ChangeInt32ToSmi(value)); 232 return Replace(ChangeInt32ToSmi(value));
162 } 233 }
163 234
164 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), value, value); 235 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), value, value);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 } 418 }
348 419
349 420
350 MachineOperatorBuilder* ChangeLowering::machine() const { 421 MachineOperatorBuilder* ChangeLowering::machine() const {
351 return jsgraph()->machine(); 422 return jsgraph()->machine();
352 } 423 }
353 424
354 } // namespace compiler 425 } // namespace compiler
355 } // namespace internal 426 } // namespace internal
356 } // namespace v8 427 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-460937.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698