Chromium Code Reviews| Index: src/hydrogen-instructions.cc |
| diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc |
| index 28617517163d6e589860dd2ac8030ad48f39e395..0f4183b3ad6434f732eac7aefd764b504c9e2b70 100644 |
| --- a/src/hydrogen-instructions.cc |
| +++ b/src/hydrogen-instructions.cc |
| @@ -1408,16 +1408,38 @@ void HChange::PrintDataTo(StringStream* stream) { |
| } |
| -static HValue* SimplifiedDividendForMathFloorOfDiv(HValue* dividend) { |
| +HValue* HUnaryMathOperation::SimplifiedDividendForMathFloorOfDiv(HDiv* hdiv) { |
| + HValue* dividend = hdiv->left(); |
| // A value with an integer representation does not need to be transformed. |
| - if (dividend->representation().IsInteger32()) { |
| - return dividend; |
| - } |
| + if (dividend->representation().IsInteger32()) return dividend; |
| // A change from an integer32 can be replaced by the integer32 value. |
| - if (dividend->IsChange() && |
| - HChange::cast(dividend)->from().IsInteger32()) { |
| + if (dividend->IsChange() && HChange::cast(dividend)->from().IsInteger32()) { |
| return HChange::cast(dividend)->value(); |
| } |
| + if (hdiv->observed_input_representation(1).IsSmiOrInteger32()) { |
| + return Prepend(new(block()->zone()) HChange( |
| + dividend, Representation::Integer32(), false, false)); |
| + } |
| + return NULL; |
| +} |
| + |
| + |
| +HValue* HUnaryMathOperation::SimplifiedDivisorForMathFloorOfDiv(HDiv* hdiv) { |
| + HValue* divisor = hdiv->right(); |
| + if (divisor->IsInteger32Constant()) { |
| + return Prepend(HConstant::cast(divisor)->CopyToRepresentation( |
| + Representation::Integer32(), divisor->block()->zone())); |
| + } |
| + // A value with an integer representation does not need to be transformed. |
| + if (divisor->representation().IsInteger32()) return divisor; |
| + // A change from an integer32 can be replaced by the integer32 value. |
| + if (divisor->IsChange() && HChange::cast(divisor)->from().IsInteger32()) { |
| + return HChange::cast(divisor)->value(); |
| + } |
| + if (hdiv->observed_input_representation(2).IsSmiOrInteger32()) { |
| + return Prepend(new(block()->zone()) HChange( |
| + divisor, Representation::Integer32(), false, false)); |
| + } |
| return NULL; |
| } |
| @@ -1426,63 +1448,20 @@ HValue* HUnaryMathOperation::Canonicalize() { |
| if (op() == kMathRound || op() == kMathFloor) { |
| HValue* val = value(); |
| if (val->IsChange()) val = HChange::cast(val)->value(); |
| - |
| - // If the input is smi or integer32 then we replace the instruction with its |
| - // input. |
| if (val->representation().IsSmiOrInteger32()) { |
| - if (!val->representation().Equals(representation())) { |
| - HChange* result = new(block()->zone()) HChange( |
| - val, representation(), false, false); |
| - result->InsertBefore(this); |
| - return result; |
| - } |
| - return val; |
| + if (val->representation().Equals(representation())) return val; |
| + return Prepend(new(block()->zone()) HChange( |
| + val, representation(), false, false)); |
| } |
| } |
| - |
| - if (op() == kMathFloor) { |
| - HValue* val = value(); |
| - if (val->IsDiv() && (val->UseCount() == 1)) { |
| - HDiv* hdiv = HDiv::cast(val); |
| - HValue* left = hdiv->left(); |
| - HValue* right = hdiv->right(); |
| - // Try to simplify left and right values of the division. |
| - HValue* new_left = SimplifiedDividendForMathFloorOfDiv(left); |
| - if (new_left == NULL && |
| - hdiv->observed_input_representation(1).IsSmiOrInteger32()) { |
| - new_left = new(block()->zone()) HChange( |
| - left, Representation::Integer32(), false, false); |
| - HChange::cast(new_left)->InsertBefore(this); |
| - } |
| - HValue* new_right = |
| - LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(right); |
| - if (new_right == NULL && |
| -#if V8_TARGET_ARCH_ARM |
| - CpuFeatures::IsSupported(SUDIV) && |
| -#endif |
| - hdiv->observed_input_representation(2).IsSmiOrInteger32()) { |
| - new_right = new(block()->zone()) HChange( |
| - right, Representation::Integer32(), false, false); |
| - HChange::cast(new_right)->InsertBefore(this); |
| - } |
| - |
| - // Return if left or right are not optimizable. |
| - if ((new_left == NULL) || (new_right == NULL)) return this; |
| - |
| - // Insert the new values in the graph. |
| - if (new_left->IsInstruction() && |
| - !HInstruction::cast(new_left)->IsLinked()) { |
| - HInstruction::cast(new_left)->InsertBefore(this); |
| - } |
| - if (new_right->IsInstruction() && |
| - !HInstruction::cast(new_right)->IsLinked()) { |
| - HInstruction::cast(new_right)->InsertBefore(this); |
| - } |
| - HMathFloorOfDiv* instr = |
| - HMathFloorOfDiv::New(block()->zone(), context(), new_left, new_right); |
| - instr->InsertBefore(this); |
| - return instr; |
| - } |
| + if (op() == kMathFloor && value()->IsDiv() && value()->UseCount() == 1) { |
| + HDiv* hdiv = HDiv::cast(value()); |
| + 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.
|
| + if (left == NULL) return this; |
| + HValue* right = SimplifiedDivisorForMathFloorOfDiv(hdiv); |
| + if (right == NULL) return this; |
| + return Prepend(HMathFloorOfDiv::New( |
| + block()->zone(), context(), left, right)); |
| } |
| return this; |
| } |
| @@ -3226,10 +3205,8 @@ HValue* HLoadKeyedGeneric::Canonicalize() { |
| key_load->elements_kind()); |
| map_check->InsertBefore(this); |
| index->InsertBefore(this); |
| - HLoadFieldByIndex* load = new(block()->zone()) HLoadFieldByIndex( |
| - object(), index); |
| - load->InsertBefore(this); |
| - return load; |
| + return Prepend(new(block()->zone()) HLoadFieldByIndex( |
| + object(), index)); |
| } |
| } |
| } |