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

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: Feedback 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
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/ia32/lithium-codegen-ia32.cc » ('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 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) {
1412 // A value with an integer representation does not need to be transformed.
1413 if (dividend->representation().IsInteger32()) {
1414 return dividend;
1415 }
1416 // A change from an integer32 can be replaced by the integer32 value.
1417 if (dividend->IsChange() &&
1418 HChange::cast(dividend)->from().IsInteger32()) {
1419 return HChange::cast(dividend)->value();
1420 }
1421 return NULL;
1422 }
1423
1424
1425 HValue* HUnaryMathOperation::Canonicalize() { 1411 HValue* HUnaryMathOperation::Canonicalize() {
1426 if (op() == kMathRound || op() == kMathFloor) { 1412 if (op() == kMathRound || op() == kMathFloor) {
1427 HValue* val = value(); 1413 HValue* val = value();
1428 if (val->IsChange()) val = HChange::cast(val)->value(); 1414 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()) { 1415 if (val->representation().IsSmiOrInteger32()) {
1433 if (!val->representation().Equals(representation())) { 1416 if (val->representation().Equals(representation())) return val;
1434 HChange* result = new(block()->zone()) HChange( 1417 return Prepend(new(block()->zone()) HChange(
1435 val, representation(), false, false); 1418 val, representation(), false, false));
1436 result->InsertBefore(this);
1437 return result;
1438 }
1439 return val;
1440 } 1419 }
1441 } 1420 }
1421 if (op() == kMathFloor && value()->IsDiv() && value()->UseCount() == 1) {
1422 HDiv* hdiv = HDiv::cast(value());
1442 1423
1443 if (op() == kMathFloor) { 1424 HValue* left = hdiv->left();
1444 HValue* val = value(); 1425 if (left->representation().IsInteger32()) {
1445 if (val->IsDiv() && (val->UseCount() == 1)) { 1426 // A value with an integer representation does not need to be transformed.
1446 HDiv* hdiv = HDiv::cast(val); 1427 } else if (left->IsChange() && HChange::cast(left)->from().IsInteger32()) {
1447 HValue* left = hdiv->left(); 1428 // A change from an integer32 can be replaced by the integer32 value.
1448 HValue* right = hdiv->right(); 1429 left = HChange::cast(left)->value();
1449 // Try to simplify left and right values of the division. 1430 } else if (hdiv->observed_input_representation(1).IsSmiOrInteger32()) {
1450 HValue* new_left = SimplifiedDividendForMathFloorOfDiv(left); 1431 left = Prepend(new(block()->zone()) HChange(
1451 if (new_left == NULL && 1432 left, Representation::Integer32(), false, false));
1452 hdiv->observed_input_representation(1).IsSmiOrInteger32()) { 1433 } else {
1453 new_left = new(block()->zone()) HChange( 1434 return this;
1454 left, Representation::Integer32(), false, false); 1435 }
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 1436
1469 // Return if left or right are not optimizable. 1437 HValue* right = hdiv->right();
1470 if ((new_left == NULL) || (new_right == NULL)) return this; 1438 if (right->IsInteger32Constant()) {
1439 right = Prepend(HConstant::cast(right)->CopyToRepresentation(
1440 Representation::Integer32(), right->block()->zone()));
1441 } else if (right->representation().IsInteger32()) {
1442 // A value with an integer representation does not need to be transformed.
1443 } else if (right->IsChange() &&
1444 HChange::cast(right)->from().IsInteger32()) {
1445 // A change from an integer32 can be replaced by the integer32 value.
1446 right = HChange::cast(right)->value();
1447 } else if (hdiv->observed_input_representation(2).IsSmiOrInteger32()) {
1448 right = Prepend(new(block()->zone()) HChange(
1449 right, Representation::Integer32(), false, false));
1450 } else {
1451 return this;
1452 }
1471 1453
1472 // Insert the new values in the graph. 1454 return Prepend(HMathFloorOfDiv::New(
1473 if (new_left->IsInstruction() && 1455 block()->zone(), context(), left, right));
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 } 1456 }
1487 return this; 1457 return this;
1488 } 1458 }
1489 1459
1490 1460
1491 HValue* HCheckInstanceType::Canonicalize() { 1461 HValue* HCheckInstanceType::Canonicalize() {
1492 if (check_ == IS_STRING && value()->type().IsString()) { 1462 if (check_ == IS_STRING && value()->type().IsString()) {
1493 return value(); 1463 return value();
1494 } 1464 }
1495 1465
(...skipping 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after
3219 names_cache->map()); 3189 names_cache->map());
3220 HInstruction* index = HLoadKeyed::New( 3190 HInstruction* index = HLoadKeyed::New(
3221 block()->graph()->zone(), 3191 block()->graph()->zone(),
3222 block()->graph()->GetInvalidContext(), 3192 block()->graph()->GetInvalidContext(),
3223 index_cache, 3193 index_cache,
3224 key_load->key(), 3194 key_load->key(),
3225 key_load->key(), 3195 key_load->key(),
3226 key_load->elements_kind()); 3196 key_load->elements_kind());
3227 map_check->InsertBefore(this); 3197 map_check->InsertBefore(this);
3228 index->InsertBefore(this); 3198 index->InsertBefore(this);
3229 HLoadFieldByIndex* load = new(block()->zone()) HLoadFieldByIndex( 3199 return Prepend(new(block()->zone()) HLoadFieldByIndex(
3230 object(), index); 3200 object(), index));
3231 load->InsertBefore(this);
3232 return load;
3233 } 3201 }
3234 } 3202 }
3235 } 3203 }
3236 3204
3237 return this; 3205 return this;
3238 } 3206 }
3239 3207
3240 3208
3241 void HStoreNamedGeneric::PrintDataTo(StringStream* stream) { 3209 void HStoreNamedGeneric::PrintDataTo(StringStream* stream) {
3242 object()->PrintNameTo(stream); 3210 object()->PrintNameTo(stream);
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
4439 break; 4407 break;
4440 case kExternalMemory: 4408 case kExternalMemory:
4441 stream->Add("[external-memory]"); 4409 stream->Add("[external-memory]");
4442 break; 4410 break;
4443 } 4411 }
4444 4412
4445 stream->Add("@%d", offset()); 4413 stream->Add("@%d", offset());
4446 } 4414 }
4447 4415
4448 } } // namespace v8::internal 4416 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.h ('k') | src/ia32/lithium-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698