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

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

Issue 141653015: Simplify HUnaryMathOperation::Canonicalize. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Moved forward declaration Created 6 years, 11 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
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 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 void HChange::PrintDataTo(StringStream* stream) { 1401 void HChange::PrintDataTo(StringStream* stream) {
1402 HUnaryOperation::PrintDataTo(stream); 1402 HUnaryOperation::PrintDataTo(stream);
1403 stream->Add(" %s to %s", from().Mnemonic(), to().Mnemonic()); 1403 stream->Add(" %s to %s", from().Mnemonic(), to().Mnemonic());
1404 1404
1405 if (CanTruncateToInt32()) stream->Add(" truncating-int32"); 1405 if (CanTruncateToInt32()) stream->Add(" truncating-int32");
1406 if (CheckFlag(kBailoutOnMinusZero)) stream->Add(" -0?"); 1406 if (CheckFlag(kBailoutOnMinusZero)) stream->Add(" -0?");
1407 if (CheckFlag(kAllowUndefinedAsNaN)) stream->Add(" allow-undefined-as-nan"); 1407 if (CheckFlag(kAllowUndefinedAsNaN)) stream->Add(" allow-undefined-as-nan");
1408 } 1408 }
1409 1409
1410 1410
1411 static HValue* SimplifiedDividendForMathFloorOfDiv(HValue* dividend) { 1411 HValue* HUnaryMathOperation::SimplifiedDividendForMathFloorOfDiv(HDiv* hdiv) {
1412 HValue* dividend = hdiv->left();
1412 // A value with an integer representation does not need to be transformed. 1413 // A value with an integer representation does not need to be transformed.
1413 if (dividend->representation().IsInteger32()) { 1414 if (dividend->representation().IsInteger32()) return dividend;
1414 return dividend; 1415 // A change from an integer32 can be replaced by the integer32 value.
1416 if (dividend->IsChange() && HChange::cast(dividend)->from().IsInteger32()) {
1417 return HChange::cast(dividend)->value();
1415 } 1418 }
1416 // A change from an integer32 can be replaced by the integer32 value. 1419 if (hdiv->observed_input_representation(1).IsSmiOrInteger32()) {
1417 if (dividend->IsChange() && 1420 return Prepend(new(block()->zone()) HChange(
1418 HChange::cast(dividend)->from().IsInteger32()) { 1421 dividend, Representation::Integer32(), false, false));
1419 return HChange::cast(dividend)->value();
1420 } 1422 }
1421 return NULL; 1423 return NULL;
1422 } 1424 }
1423 1425
1426
1427 HValue* HUnaryMathOperation::SimplifiedDivisorForMathFloorOfDiv(HDiv* hdiv) {
1428 HValue* divisor = hdiv->right();
1429 if (divisor->IsInteger32Constant()) {
1430 return Prepend(HConstant::cast(divisor)->CopyToRepresentation(
1431 Representation::Integer32(), divisor->block()->zone()));
1432 }
1433 // A value with an integer representation does not need to be transformed.
1434 if (divisor->representation().IsInteger32()) return divisor;
1435 // A change from an integer32 can be replaced by the integer32 value.
1436 if (divisor->IsChange() && HChange::cast(divisor)->from().IsInteger32()) {
1437 return HChange::cast(divisor)->value();
1438 }
1439 if (hdiv->observed_input_representation(2).IsSmiOrInteger32()) {
1440 return Prepend(new(block()->zone()) HChange(
1441 divisor, Representation::Integer32(), false, false));
1442 }
1443 return NULL;
1444 }
1445
1424 1446
1425 HValue* HUnaryMathOperation::Canonicalize() { 1447 HValue* HUnaryMathOperation::Canonicalize() {
1426 if (op() == kMathRound || op() == kMathFloor) { 1448 if (op() == kMathRound || op() == kMathFloor) {
1427 HValue* val = value(); 1449 HValue* val = value();
1428 if (val->IsChange()) val = HChange::cast(val)->value(); 1450 if (val->IsChange()) val = HChange::cast(val)->value();
1429
1430 // If the input is smi or integer32 then we replace the instruction with its
1431 // input.
1432 if (val->representation().IsSmiOrInteger32()) { 1451 if (val->representation().IsSmiOrInteger32()) {
1433 if (!val->representation().Equals(representation())) { 1452 if (val->representation().Equals(representation())) return val;
1434 HChange* result = new(block()->zone()) HChange( 1453 return Prepend(new(block()->zone()) HChange(
1435 val, representation(), false, false); 1454 val, representation(), false, false));
1436 result->InsertBefore(this);
1437 return result;
1438 }
1439 return val;
1440 } 1455 }
1441 } 1456 }
1442 1457 if (op() == kMathFloor && value()->IsDiv() && value()->UseCount() == 1) {
1443 if (op() == kMathFloor) { 1458 HDiv* hdiv = HDiv::cast(value());
1444 HValue* val = value(); 1459 HValue* left = SimplifiedDividendForMathFloorOfDiv(hdiv);
Benedikt Meurer 2014/01/24 12:33:21 Can we please inline the SimplifiedDividend... and
Sven Panne 2014/01/24 14:02:05 Done.
1445 if (val->IsDiv() && (val->UseCount() == 1)) { 1460 if (left == NULL) return this;
1446 HDiv* hdiv = HDiv::cast(val); 1461 HValue* right = SimplifiedDivisorForMathFloorOfDiv(hdiv);
1447 HValue* left = hdiv->left(); 1462 if (right == NULL) return this;
1448 HValue* right = hdiv->right(); 1463 return Prepend(HMathFloorOfDiv::New(
1449 // Try to simplify left and right values of the division. 1464 block()->zone(), context(), left, right));
1450 HValue* new_left = SimplifiedDividendForMathFloorOfDiv(left);
1451 if (new_left == NULL &&
1452 hdiv->observed_input_representation(1).IsSmiOrInteger32()) {
1453 new_left = new(block()->zone()) HChange(
1454 left, Representation::Integer32(), false, false);
1455 HChange::cast(new_left)->InsertBefore(this);
1456 }
1457 HValue* new_right =
1458 LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(right);
1459 if (new_right == NULL &&
1460 #if V8_TARGET_ARCH_ARM
1461 CpuFeatures::IsSupported(SUDIV) &&
1462 #endif
1463 hdiv->observed_input_representation(2).IsSmiOrInteger32()) {
1464 new_right = new(block()->zone()) HChange(
1465 right, Representation::Integer32(), false, false);
1466 HChange::cast(new_right)->InsertBefore(this);
1467 }
1468
1469 // Return if left or right are not optimizable.
1470 if ((new_left == NULL) || (new_right == NULL)) return this;
1471
1472 // Insert the new values in the graph.
1473 if (new_left->IsInstruction() &&
1474 !HInstruction::cast(new_left)->IsLinked()) {
1475 HInstruction::cast(new_left)->InsertBefore(this);
1476 }
1477 if (new_right->IsInstruction() &&
1478 !HInstruction::cast(new_right)->IsLinked()) {
1479 HInstruction::cast(new_right)->InsertBefore(this);
1480 }
1481 HMathFloorOfDiv* instr =
1482 HMathFloorOfDiv::New(block()->zone(), context(), new_left, new_right);
1483 instr->InsertBefore(this);
1484 return instr;
1485 }
1486 } 1465 }
1487 return this; 1466 return this;
1488 } 1467 }
1489 1468
1490 1469
1491 HValue* HCheckInstanceType::Canonicalize() { 1470 HValue* HCheckInstanceType::Canonicalize() {
1492 if (check_ == IS_STRING && value()->type().IsString()) { 1471 if (check_ == IS_STRING && value()->type().IsString()) {
1493 return value(); 1472 return value();
1494 } 1473 }
1495 1474
(...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after
3219 names_cache->map()); 3198 names_cache->map());
3220 HInstruction* index = HLoadKeyed::New( 3199 HInstruction* index = HLoadKeyed::New(
3221 block()->graph()->zone(), 3200 block()->graph()->zone(),
3222 block()->graph()->GetInvalidContext(), 3201 block()->graph()->GetInvalidContext(),
3223 index_cache, 3202 index_cache,
3224 key_load->key(), 3203 key_load->key(),
3225 key_load->key(), 3204 key_load->key(),
3226 key_load->elements_kind()); 3205 key_load->elements_kind());
3227 map_check->InsertBefore(this); 3206 map_check->InsertBefore(this);
3228 index->InsertBefore(this); 3207 index->InsertBefore(this);
3229 HLoadFieldByIndex* load = new(block()->zone()) HLoadFieldByIndex( 3208 return Prepend(new(block()->zone()) HLoadFieldByIndex(
3230 object(), index); 3209 object(), index));
3231 load->InsertBefore(this);
3232 return load;
3233 } 3210 }
3234 } 3211 }
3235 } 3212 }
3236 3213
3237 return this; 3214 return this;
3238 } 3215 }
3239 3216
3240 3217
3241 void HStoreNamedGeneric::PrintDataTo(StringStream* stream) { 3218 void HStoreNamedGeneric::PrintDataTo(StringStream* stream) {
3242 object()->PrintNameTo(stream); 3219 object()->PrintNameTo(stream);
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
4439 break; 4416 break;
4440 case kExternalMemory: 4417 case kExternalMemory:
4441 stream->Add("[external-memory]"); 4418 stream->Add("[external-memory]");
4442 break; 4419 break;
4443 } 4420 }
4444 4421
4445 stream->Add("@%d", offset()); 4422 stream->Add("@%d", offset());
4446 } 4423 }
4447 4424
4448 } } // namespace v8::internal 4425 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698