Chromium Code Reviews| Index: src/compiler/representation-change.h |
| diff --git a/src/compiler/representation-change.h b/src/compiler/representation-change.h |
| index 255073003d6c588e616aef0bfe4f06e9528718ae..d8d67bb8f19a4bc2d4fafbe21b2d5520390544cd 100644 |
| --- a/src/compiler/representation-change.h |
| +++ b/src/compiler/representation-change.h |
| @@ -88,7 +88,7 @@ class RepresentationChanger { |
| } else if (use_type & rFloat64) { |
| return GetFloat64RepresentationFor(node, output_type); |
| } else if (use_type & rWord32) { |
| - return GetWord32RepresentationFor(node, output_type); |
| + return GetWord32RepresentationFor(node, output_type, use_type & tUint32); |
| } else if (use_type & rBit) { |
| return GetBitRepresentationFor(node, output_type); |
| } else if (use_type & rWord64) { |
| @@ -165,10 +165,8 @@ class RepresentationChanger { |
| if (output_type & rWord32) { |
| if (output_type & tUint32) { |
| op = machine()->ChangeUint32ToFloat64(); |
| - } else if (output_type & tInt32) { |
| - op = machine()->ChangeInt32ToFloat64(); |
| } else { |
| - return TypeError(node, output_type, rFloat64); |
| + op = machine()->ChangeInt32ToFloat64(); |
| } |
| } else if (output_type & rTagged) { |
| op = simplified()->ChangeTaggedToFloat64(); |
| @@ -178,22 +176,23 @@ class RepresentationChanger { |
| return jsgraph()->graph()->NewNode(op, node); |
| } |
| - Node* GetWord32RepresentationFor(Node* node, RepTypeUnion output_type) { |
| + Node* GetWord32RepresentationFor(Node* node, RepTypeUnion output_type, |
| + bool use_unsigned) { |
| // Eagerly fold representation changes for constants. |
| switch (node->opcode()) { |
| case IrOpcode::kInt32Constant: |
| return node; // No change necessary. |
| case IrOpcode::kNumberConstant: |
| case IrOpcode::kFloat64Constant: { |
| - if (output_type & tUint32) { |
| - int32_t value = static_cast<int32_t>( |
| - static_cast<uint32_t>(ValueOf<double>(node->op()))); |
| - return jsgraph()->Int32Constant(value); |
| - } else if (output_type & tInt32) { |
| - int32_t value = FastD2I(ValueOf<double>(node->op())); |
| - return jsgraph()->Int32Constant(value); |
| + double value = ValueOf<double>(node->op()); |
|
Michael Starzinger
2014/08/11 16:10:19
Can we call DCHECK(Is[Uint|Int]32Double(value)) he
|
| + if (value < 0) { |
| + DCHECK(value >= kMinInt && value <= kMaxInt); |
| + int32_t iv = static_cast<int32_t>(value); |
| + return jsgraph()->Int32Constant(iv); |
| } else { |
| - return TypeError(node, output_type, rWord32); |
| + DCHECK(value >= 0 && value <= kMaxUInt32); |
| + int32_t iv = static_cast<int32_t>(static_cast<uint32_t>(value)); |
| + return jsgraph()->Int32Constant(iv); |
| } |
| } |
| default: |
| @@ -202,20 +201,16 @@ class RepresentationChanger { |
| // Select the correct X -> Word32 operator. |
| Operator* op = NULL; |
| if (output_type & rFloat64) { |
| - if (output_type & tUint32) { |
| + if (output_type & tUint32 || use_unsigned) { |
| op = machine()->ChangeFloat64ToUint32(); |
| - } else if (output_type & tInt32) { |
| - op = machine()->ChangeFloat64ToInt32(); |
| } else { |
| - return TypeError(node, output_type, rWord32); |
| + op = machine()->ChangeFloat64ToInt32(); |
| } |
| } else if (output_type & rTagged) { |
| - if (output_type & tUint32) { |
| + if (output_type & tUint32 || use_unsigned) { |
| op = simplified()->ChangeTaggedToUint32(); |
| - } else if (output_type & tInt32) { |
| - op = simplified()->ChangeTaggedToInt32(); |
| } else { |
| - return TypeError(node, output_type, rWord32); |
| + op = simplified()->ChangeTaggedToInt32(); |
| } |
| } else if (output_type & rBit) { |
| return node; // Sloppy comparison -> word32. |