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

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

Issue 683873002: [turbofan] Avoid unnecessary (u)int32<->float64 changes in simplified lowering. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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/simplified-lowering.h" 5 #include "src/compiler/simplified-lowering.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "src/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/code-factory.h" 10 #include "src/code-factory.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 301
302 // Helper for handling phis. 302 // Helper for handling phis.
303 void VisitPhi(Node* node, MachineTypeUnion use, 303 void VisitPhi(Node* node, MachineTypeUnion use,
304 SimplifiedLowering* lowering) { 304 SimplifiedLowering* lowering) {
305 // Phis adapt to the output representation their uses demand, pushing 305 // Phis adapt to the output representation their uses demand, pushing
306 // representation changes to their inputs. 306 // representation changes to their inputs.
307 Type* upper = NodeProperties::GetBounds(node).upper; 307 Type* upper = NodeProperties::GetBounds(node).upper;
308 MachineType output = kMachNone; 308 MachineType output = kMachNone;
309 MachineType propagate = kMachNone; 309 MachineType propagate = kMachNone;
310 310
311 if (upper->Is(Type::Signed32()) || upper->Is(Type::Unsigned32())) { 311 if ((use & kRepMask) == kRepTagged) {
312 // legal = kRepTagged | kRepFloat64 | kRepWord32; 312 // only tagged uses.
313 if ((use & kRepMask) == kRepTagged) { 313 output = kRepTagged;
314 // only tagged uses. 314 propagate = kRepTagged;
315 output = kRepTagged; 315 } else if (IsSafeIntAdditiveOperand(node)) {
316 propagate = kRepTagged; 316 // Integer within [-2^52, 2^52] range.
317 } else if ((use & kRepMask) == kRepFloat64) { 317 if ((use & kRepMask) == kRepFloat64) {
318 // only float64 uses. 318 // only float64 uses.
319 output = kRepFloat64; 319 output = kRepFloat64;
320 propagate = kRepFloat64; 320 propagate = kRepFloat64;
321 } else { 321 } else if (upper->Is(Type::Signed32()) || upper->Is(Type::Unsigned32())) {
322 // multiple uses. 322 // multiple uses, but we are within 32 bits range => pick kRepWord32.
323 output = kRepWord32; 323 output = kRepWord32;
324 propagate = kRepWord32; 324 propagate = kRepWord32;
325 } 325 } else if ((use & kRepMask) == kRepWord32 ||
326 } else if (upper->Is(Type::Boolean())) { 326 (use & kTypeMask) == kTypeInt32 ||
327 // legal = kRepTagged | kRepBit; 327 (use & kTypeMask) == kTypeUint32) {
328 if ((use & kRepMask) == kRepTagged) { 328 // The type is a safe integer, but we only use 32 bits.
329 // only tagged uses. 329 output = kRepWord32;
330 output = kRepTagged; 330 propagate = kRepWord32;
331 propagate = kRepTagged;
332 } else { 331 } else {
333 // multiple uses.
334 output = kRepBit;
335 propagate = kRepBit;
336 }
337 } else if (upper->Is(Type::Number())) {
338 // legal = kRepTagged | kRepFloat64;
339 if ((use & kRepMask) == kRepTagged) {
340 // only tagged uses.
341 output = kRepTagged;
342 propagate = kRepTagged;
343 } else {
344 // multiple uses.
345 output = kRepFloat64; 332 output = kRepFloat64;
346 propagate = kRepFloat64; 333 propagate = kRepFloat64;
347 } 334 }
335 } else if (upper->Is(Type::Boolean())) {
336 // multiple uses => pick kRepBit.
337 output = kRepBit;
338 propagate = kRepBit;
339 } else if (upper->Is(Type::Number())) {
340 // multiple uses => pick kRepFloat64.
341 output = kRepFloat64;
342 propagate = kRepFloat64;
348 } else { 343 } else {
349 // legal = kRepTagged; 344 // legal = kRepTagged;
350 output = kRepTagged; 345 output = kRepTagged;
351 propagate = kRepTagged; 346 propagate = kRepTagged;
352 } 347 }
353 348
354 MachineType output_type = 349 MachineType output_type =
355 static_cast<MachineType>(changer_->TypeFromUpperBound(upper) | output); 350 static_cast<MachineType>(changer_->TypeFromUpperBound(upper) | output);
356 SetOutput(node, output_type); 351 SetOutput(node, output_type);
357 352
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 } 636 }
642 } 637 }
643 // => Float64Mod 638 // => Float64Mod
644 VisitFloat64Binop(node); 639 VisitFloat64Binop(node);
645 if (lower()) node->set_op(Float64Op(node)); 640 if (lower()) node->set_op(Float64Op(node));
646 break; 641 break;
647 } 642 }
648 case IrOpcode::kNumberToInt32: { 643 case IrOpcode::kNumberToInt32: {
649 MachineTypeUnion use_rep = use & kRepMask; 644 MachineTypeUnion use_rep = use & kRepMask;
650 Node* input = node->InputAt(0); 645 Node* input = node->InputAt(0);
646 Type* in_upper = NodeProperties::GetBounds(input).upper;
651 MachineTypeUnion in = GetInfo(input)->output; 647 MachineTypeUnion in = GetInfo(input)->output;
652 if (NodeProperties::GetBounds(input).upper->Is(Type::Signed32())) { 648 if (in_upper->Is(Type::Signed32())) {
653 // If the input has type int32, pass through representation. 649 // If the input has type int32, pass through representation.
654 VisitUnop(node, kTypeInt32 | use_rep, kTypeInt32 | use_rep); 650 VisitUnop(node, kTypeInt32 | use_rep, kTypeInt32 | use_rep);
655 if (lower()) DeferReplacement(node, node->InputAt(0)); 651 if (lower()) DeferReplacement(node, node->InputAt(0));
656 } else if ((in & kTypeMask) == kTypeUint32 || 652 } else if ((in & kTypeMask) == kTypeUint32 ||
657 (in & kTypeMask) == kTypeInt32 || 653 (in & kTypeMask) == kTypeInt32 ||
654 in_upper->Is(Type::Unsigned32()) ||
titzer 2014/10/28 15:10:42 Something feels a little fishy here. What about ma
658 (in & kRepMask) == kRepWord32) { 655 (in & kRepMask) == kRepWord32) {
659 // Just change representation if necessary. 656 // Just change representation if necessary.
660 VisitUnop(node, kTypeInt32 | kRepWord32, kTypeInt32 | kRepWord32); 657 VisitUnop(node, kTypeInt32 | kRepWord32, kTypeInt32 | kRepWord32);
661 if (lower()) DeferReplacement(node, node->InputAt(0)); 658 if (lower()) DeferReplacement(node, node->InputAt(0));
662 } else { 659 } else {
663 // Require the input in float64 format and perform truncation. 660 // Require the input in float64 format and perform truncation.
664 // TODO(turbofan): avoid a truncation with a smi check. 661 // TODO(turbofan): avoid a truncation with a smi check.
665 VisitUnop(node, kTypeInt32 | kRepFloat64, kTypeInt32 | kRepWord32); 662 VisitUnop(node, kTypeInt32 | kRepFloat64, kTypeInt32 | kRepWord32);
666 if (lower()) 663 if (lower())
667 node->set_op(lowering->machine()->TruncateFloat64ToInt32()); 664 node->set_op(lowering->machine()->TruncateFloat64ToInt32());
668 } 665 }
669 break; 666 break;
670 } 667 }
671 case IrOpcode::kNumberToUint32: { 668 case IrOpcode::kNumberToUint32: {
672 MachineTypeUnion use_rep = use & kRepMask; 669 MachineTypeUnion use_rep = use & kRepMask;
673 Node* input = node->InputAt(0); 670 Node* input = node->InputAt(0);
671 Type* in_upper = NodeProperties::GetBounds(input).upper;
674 MachineTypeUnion in = GetInfo(input)->output; 672 MachineTypeUnion in = GetInfo(input)->output;
675 if (NodeProperties::GetBounds(input).upper->Is(Type::Unsigned32())) { 673 if (in_upper->Is(Type::Unsigned32())) {
676 // If the input has type uint32, pass through representation. 674 // If the input has type uint32, pass through representation.
677 VisitUnop(node, kTypeUint32 | use_rep, kTypeUint32 | use_rep); 675 VisitUnop(node, kTypeUint32 | use_rep, kTypeUint32 | use_rep);
678 if (lower()) DeferReplacement(node, node->InputAt(0)); 676 if (lower()) DeferReplacement(node, node->InputAt(0));
679 } else if ((in & kTypeMask) == kTypeUint32 || 677 } else if ((in & kTypeMask) == kTypeUint32 ||
680 (in & kTypeMask) == kTypeInt32 || 678 (in & kTypeMask) == kTypeInt32 ||
679 in_upper->Is(Type::Signed32()) ||
681 (in & kRepMask) == kRepWord32) { 680 (in & kRepMask) == kRepWord32) {
682 // Just change representation if necessary. 681 // Just change representation if necessary.
683 VisitUnop(node, kTypeUint32 | kRepWord32, kTypeUint32 | kRepWord32); 682 VisitUnop(node, kTypeUint32 | kRepWord32, kTypeUint32 | kRepWord32);
684 if (lower()) DeferReplacement(node, node->InputAt(0)); 683 if (lower()) DeferReplacement(node, node->InputAt(0));
685 } else { 684 } else {
686 // Require the input in float64 format and perform truncation. 685 // Require the input in float64 format and perform truncation.
687 // TODO(turbofan): avoid a truncation with a smi check. 686 // TODO(turbofan): avoid a truncation with a smi check.
688 VisitUnop(node, kTypeUint32 | kRepFloat64, kTypeUint32 | kRepWord32); 687 VisitUnop(node, kTypeUint32 | kRepFloat64, kTypeUint32 | kRepWord32);
689 if (lower()) 688 if (lower())
690 node->set_op(lowering->machine()->TruncateFloat64ToInt32()); 689 node->set_op(lowering->machine()->TruncateFloat64ToInt32());
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 void SimplifiedLowering::DoStringLessThanOrEqual(Node* node) { 1234 void SimplifiedLowering::DoStringLessThanOrEqual(Node* node) {
1236 node->set_op(machine()->IntLessThanOrEqual()); 1235 node->set_op(machine()->IntLessThanOrEqual());
1237 node->ReplaceInput(0, StringComparison(node, true)); 1236 node->ReplaceInput(0, StringComparison(node, true));
1238 node->ReplaceInput(1, jsgraph()->SmiConstant(EQUAL)); 1237 node->ReplaceInput(1, jsgraph()->SmiConstant(EQUAL));
1239 } 1238 }
1240 1239
1241 1240
1242 } // namespace compiler 1241 } // namespace compiler
1243 } // namespace internal 1242 } // namespace internal
1244 } // namespace v8 1243 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698