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

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

Issue 17094005: Fix MathFloorOfDiv canonicalization ASSERT failures (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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 | « 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 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 1492 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 void HChange::PrintDataTo(StringStream* stream) { 1503 void HChange::PrintDataTo(StringStream* stream) {
1504 HUnaryOperation::PrintDataTo(stream); 1504 HUnaryOperation::PrintDataTo(stream);
1505 stream->Add(" %s to %s", from().Mnemonic(), to().Mnemonic()); 1505 stream->Add(" %s to %s", from().Mnemonic(), to().Mnemonic());
1506 1506
1507 if (CanTruncateToInt32()) stream->Add(" truncating-int32"); 1507 if (CanTruncateToInt32()) stream->Add(" truncating-int32");
1508 if (CheckFlag(kBailoutOnMinusZero)) stream->Add(" -0?"); 1508 if (CheckFlag(kBailoutOnMinusZero)) stream->Add(" -0?");
1509 if (CheckFlag(kAllowUndefinedAsNaN)) stream->Add(" allow-undefined-as-nan"); 1509 if (CheckFlag(kAllowUndefinedAsNaN)) stream->Add(" allow-undefined-as-nan");
1510 } 1510 }
1511 1511
1512 1512
1513 static HValue* SimplifiedDividendForMathFloorOfDiv( 1513 static HValue* SimplifiedDividendForMathFloorOfDiv(HValue* dividend) {
1514 HValue* dividend,
1515 Representation observed_representation) {
1516 // A value with an integer representation does not need to be transformed. 1514 // A value with an integer representation does not need to be transformed.
1517 if (dividend->representation().IsInteger32()) { 1515 if (dividend->representation().IsInteger32()) {
1518 return dividend; 1516 return dividend;
1519 } 1517 }
1520 // A change from an integer32 can be replaced by the integer32 value. 1518 // A change from an integer32 can be replaced by the integer32 value.
1521 if (dividend->IsChange() && 1519 if (dividend->IsChange() &&
1522 HChange::cast(dividend)->from().IsInteger32()) { 1520 HChange::cast(dividend)->from().IsInteger32()) {
1523 return HChange::cast(dividend)->value(); 1521 return HChange::cast(dividend)->value();
1524 } 1522 }
1525 // If we've only seen integers so far, insert an appropriate change.
1526 if (observed_representation.IsSmiOrInteger32()) {
1527 return new(dividend->block()->zone())
1528 HChange(dividend, Representation::Integer32(), false, false);
1529 }
1530 return NULL; 1523 return NULL;
1531 } 1524 }
1532 1525
1533 1526
1534 HValue* HUnaryMathOperation::Canonicalize() { 1527 HValue* HUnaryMathOperation::Canonicalize() {
1535 if (op() == kMathFloor) { 1528 if (op() == kMathFloor) {
1536 HValue* val = value(); 1529 HValue* val = value();
1537 if (val->IsChange()) val = HChange::cast(val)->value(); 1530 if (val->IsChange()) val = HChange::cast(val)->value();
1538 1531
1539 // If the input is integer32 then we replace the floor instruction 1532 // If the input is integer32 then we replace the floor instruction
1540 // with its input. 1533 // with its input.
1541 if (val->representation().IsInteger32()) return val; 1534 if (val->representation().IsInteger32()) return val;
1542 1535
1543 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_IA32) || \ 1536 #if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_IA32) || \
1544 defined(V8_TARGET_ARCH_X64) 1537 defined(V8_TARGET_ARCH_X64)
1545 if (val->IsDiv() && (val->UseCount() == 1)) { 1538 if (val->IsDiv() && (val->UseCount() == 1)) {
1546 HDiv* hdiv = HDiv::cast(val); 1539 HDiv* hdiv = HDiv::cast(val);
1547 HValue* left = hdiv->left(); 1540 HValue* left = hdiv->left();
1548 HValue* right = hdiv->right(); 1541 HValue* right = hdiv->right();
1549 // Try to simplify left and right values of the division. 1542 // Try to simplify left and right values of the division.
1550 HValue* new_left = SimplifiedDividendForMathFloorOfDiv( 1543 HValue* new_left = SimplifiedDividendForMathFloorOfDiv(left);
1551 left, hdiv->observed_input_representation(1)); 1544 if (new_left == NULL &&
1545 hdiv->observed_input_representation(1).IsSmiOrInteger32()) {
1546 new_left = new(block()->zone())
1547 HChange(left, Representation::Integer32(), false, false);
1548 HChange::cast(new_left)->InsertBefore(this);
1549 }
1552 HValue* new_right = 1550 HValue* new_right =
1553 LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(right); 1551 LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(right);
1554 if (new_right == NULL && 1552 if (new_right == NULL &&
1555 hdiv->observed_input_representation(2).IsSmiOrInteger32()) { 1553 hdiv->observed_input_representation(2).IsSmiOrInteger32()) {
1556 new_right = new(block()->zone()) 1554 new_right = new(block()->zone())
1557 HChange(right, Representation::Integer32(), false, false); 1555 HChange(right, Representation::Integer32(), false, false);
1556 HChange::cast(new_right)->InsertBefore(this);
1558 } 1557 }
1559 1558
1560 // Return if left or right are not optimizable. 1559 // Return if left or right are not optimizable.
1561 if ((new_left == NULL) || (new_right == NULL)) return this; 1560 if ((new_left == NULL) || (new_right == NULL)) return this;
1562 1561
1563 // Insert the new values in the graph. 1562 // Insert the new values in the graph.
1564 if (new_left->IsInstruction() && 1563 if (new_left->IsInstruction() &&
1565 !HInstruction::cast(new_left)->IsLinked()) { 1564 !HInstruction::cast(new_left)->IsLinked()) {
1566 HInstruction::cast(new_left)->InsertBefore(this); 1565 HInstruction::cast(new_left)->InsertBefore(this);
1567 } 1566 }
1568 if (new_right->IsInstruction() && 1567 if (new_right->IsInstruction() &&
1569 !HInstruction::cast(new_right)->IsLinked()) { 1568 !HInstruction::cast(new_right)->IsLinked()) {
1570 HInstruction::cast(new_right)->InsertBefore(this); 1569 HInstruction::cast(new_right)->InsertBefore(this);
1571 } 1570 }
1572 HMathFloorOfDiv* instr = new(block()->zone()) 1571 HMathFloorOfDiv* instr = new(block()->zone())
1573 HMathFloorOfDiv(context(), new_left, new_right); 1572 HMathFloorOfDiv(context(), new_left, new_right);
1574 // Replace this HMathFloor instruction by the new HMathFloorOfDiv. 1573 // Replace this HMathFloor instruction by the new HMathFloorOfDiv.
1575 instr->InsertBefore(this); 1574 instr->InsertBefore(this);
1576 ReplaceAllUsesWith(instr); 1575 ReplaceAllUsesWith(instr);
1577 Kill(); 1576 Kill();
1578 // We know the division had no other uses than this HMathFloor. Delete it. 1577 // We know the division had no other uses than this HMathFloor. Delete it.
1579 // Also delete the arguments of the division if they are not used any 1578 // Dead code elimination will deal with |left| and |right| if
1580 // more. 1579 // appropriate.
1581 hdiv->DeleteAndReplaceWith(NULL); 1580 hdiv->DeleteAndReplaceWith(NULL);
1582 ASSERT(left->IsChange() || left->IsConstant());
1583 ASSERT(right->IsChange() || right->IsConstant());
1584 if (left->HasNoUses()) left->DeleteAndReplaceWith(NULL);
1585 if (right->HasNoUses()) right->DeleteAndReplaceWith(NULL);
1586 1581
1587 // Return NULL to remove this instruction from the graph. 1582 // Return NULL to remove this instruction from the graph.
1588 return NULL; 1583 return NULL;
1589 } 1584 }
1590 #endif // V8_TARGET_ARCH_ARM 1585 #endif // V8_TARGET_ARCH_ARM
1591 } 1586 }
1592 return this; 1587 return this;
1593 } 1588 }
1594 1589
1595 1590
(...skipping 2275 matching lines...) Expand 10 before | Expand all | Expand 10 after
3871 case kBackingStore: 3866 case kBackingStore:
3872 if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString()); 3867 if (!name_.is_null()) stream->Add(*String::cast(*name_)->ToCString());
3873 stream->Add("[backing-store]"); 3868 stream->Add("[backing-store]");
3874 break; 3869 break;
3875 } 3870 }
3876 3871
3877 stream->Add("@%d", offset()); 3872 stream->Add("@%d", offset());
3878 } 3873 }
3879 3874
3880 } } // namespace v8::internal 3875 } } // namespace v8::internal
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