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

Side by Side Diff: src/hydrogen-instructions.cc

Issue 16973002: Make MathFloorOfDiv optimization trigger more often (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: fix typo Created 7 years, 6 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
« no previous file with comments | « src/hydrogen.cc ('k') | src/ia32/lithium-ia32.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 void HChange::PrintDataTo(StringStream* stream) { 1504 void HChange::PrintDataTo(StringStream* stream) {
1505 HUnaryOperation::PrintDataTo(stream); 1505 HUnaryOperation::PrintDataTo(stream);
1506 stream->Add(" %s to %s", from().Mnemonic(), to().Mnemonic()); 1506 stream->Add(" %s to %s", from().Mnemonic(), to().Mnemonic());
1507 1507
1508 if (CanTruncateToInt32()) stream->Add(" truncating-int32"); 1508 if (CanTruncateToInt32()) stream->Add(" truncating-int32");
1509 if (CheckFlag(kBailoutOnMinusZero)) stream->Add(" -0?"); 1509 if (CheckFlag(kBailoutOnMinusZero)) stream->Add(" -0?");
1510 if (CheckFlag(kAllowUndefinedAsNaN)) stream->Add(" allow-undefined-as-nan"); 1510 if (CheckFlag(kAllowUndefinedAsNaN)) stream->Add(" allow-undefined-as-nan");
1511 } 1511 }
1512 1512
1513 1513
1514 static HValue* SimplifiedDividendForMathFloorOfDiv(
1515 HValue* dividend,
1516 Representation observed_representation) {
1517 // A value with an integer representation does not need to be transformed.
1518 if (dividend->representation().IsInteger32()) {
1519 return dividend;
1520 }
1521 // A change from an integer32 can be replaced by the integer32 value.
1522 if (dividend->IsChange() &&
1523 HChange::cast(dividend)->from().IsInteger32()) {
1524 return HChange::cast(dividend)->value();
1525 }
1526 // If we've only seen integers so far, insert an appropriate change.
1527 if (observed_representation.IsSmiOrInteger32()) {
1528 return new(dividend->block()->zone())
1529 HChange(dividend, Representation::Integer32(), false, false);
1530 }
1531 return NULL;
1532 }
1533
1534
1514 HValue* HUnaryMathOperation::Canonicalize() { 1535 HValue* HUnaryMathOperation::Canonicalize() {
1515 if (op() == kMathFloor) { 1536 if (op() == kMathFloor) {
1537 HValue* val = value();
1538 if (val->IsChange()) val = HChange::cast(val)->value();
1539
1516 // If the input is integer32 then we replace the floor instruction 1540 // If the input is integer32 then we replace the floor instruction
1517 // with its input. This happens before the representation changes are 1541 // with its input.
1518 // introduced. 1542 if (val->representation().IsInteger32()) return val;
1519
1520 // TODO(2205): The above comment is lying. All of this happens
1521 // *after* representation changes are introduced. We should check
1522 // for value->IsChange() and react accordingly if yes.
1523
1524 if (value()->representation().IsInteger32()) return value();
1525 1543
1526 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_IA32) || \ 1544 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_IA32) || \
1527 defined(V8_TARGET_ARCH_X64) 1545 defined(V8_TARGET_ARCH_X64)
1528 if (value()->IsDiv() && (value()->UseCount() == 1)) { 1546 if (val->IsDiv() && (val->UseCount() == 1)) {
1529 // TODO(2038): Implement this optimization for non ARM architectures. 1547 HDiv* hdiv = HDiv::cast(val);
1530 HDiv* hdiv = HDiv::cast(value());
1531 HValue* left = hdiv->left(); 1548 HValue* left = hdiv->left();
1532 HValue* right = hdiv->right(); 1549 HValue* right = hdiv->right();
1533 // Try to simplify left and right values of the division. 1550 // Try to simplify left and right values of the division.
1534 HValue* new_left = 1551 HValue* new_left = SimplifiedDividendForMathFloorOfDiv(
1535 LChunkBuilder::SimplifiedDividendForMathFloorOfDiv(left); 1552 left, hdiv->observed_input_representation(1));
1536 HValue* new_right = 1553 HValue* new_right =
1537 LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(right); 1554 LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(right);
1555 if (new_right == NULL &&
1556 hdiv->observed_input_representation(2).IsSmiOrInteger32()) {
1557 new_right = new(block()->zone())
1558 HChange(right, Representation::Integer32(), false, false);
1559 }
1538 1560
1539 // Return if left or right are not optimizable. 1561 // Return if left or right are not optimizable.
1540 if ((new_left == NULL) || (new_right == NULL)) return this; 1562 if ((new_left == NULL) || (new_right == NULL)) return this;
1541 1563
1542 // Insert the new values in the graph. 1564 // Insert the new values in the graph.
1543 if (new_left->IsInstruction() && 1565 if (new_left->IsInstruction() &&
1544 !HInstruction::cast(new_left)->IsLinked()) { 1566 !HInstruction::cast(new_left)->IsLinked()) {
1545 HInstruction::cast(new_left)->InsertBefore(this); 1567 HInstruction::cast(new_left)->InsertBefore(this);
1546 } 1568 }
1547 if (new_right->IsInstruction() && 1569 if (new_right->IsInstruction() &&
1548 !HInstruction::cast(new_right)->IsLinked()) { 1570 !HInstruction::cast(new_right)->IsLinked()) {
1549 HInstruction::cast(new_right)->InsertBefore(this); 1571 HInstruction::cast(new_right)->InsertBefore(this);
1550 } 1572 }
1551 HMathFloorOfDiv* instr = new(block()->zone()) HMathFloorOfDiv(context(), 1573 HMathFloorOfDiv* instr = new(block()->zone())
1552 new_left, 1574 HMathFloorOfDiv(context(), new_left, new_right);
1553 new_right);
1554 // Replace this HMathFloor instruction by the new HMathFloorOfDiv. 1575 // Replace this HMathFloor instruction by the new HMathFloorOfDiv.
1555 instr->InsertBefore(this); 1576 instr->InsertBefore(this);
1556 ReplaceAllUsesWith(instr); 1577 ReplaceAllUsesWith(instr);
1557 Kill(); 1578 Kill();
1558 // We know the division had no other uses than this HMathFloor. Delete it. 1579 // We know the division had no other uses than this HMathFloor. Delete it.
1559 // Also delete the arguments of the division if they are not used any 1580 // Also delete the arguments of the division if they are not used any
1560 // more. 1581 // more.
1561 hdiv->DeleteAndReplaceWith(NULL); 1582 hdiv->DeleteAndReplaceWith(NULL);
1562 ASSERT(left->IsChange() || left->IsConstant()); 1583 ASSERT(left->IsChange() || left->IsConstant());
1563 ASSERT(right->IsChange() || right->IsConstant()); 1584 ASSERT(right->IsChange() || right->IsConstant());
(...skipping 2291 matching lines...) Expand 10 before | Expand all | Expand 10 after
3855 case kBackingStore: 3876 case kBackingStore:
3856 if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString()); 3877 if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString());
3857 stream->Add("[backing-store]"); 3878 stream->Add("[backing-store]");
3858 break; 3879 break;
3859 } 3880 }
3860 3881
3861 stream->Add("@%d", offset()); 3882 stream->Add("@%d", offset());
3862 } 3883 }
3863 3884
3864 } } // namespace v8::internal 3885 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.cc ('k') | src/ia32/lithium-ia32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698