Reviewers: Michael Starzinger,
Description:
Assume signed for converting to word32/float64 unless use or output is
explicitly unsigned.
[email protected]
BUG=
Please review this at https://codereview.chromium.org/461653002/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+21, -33 lines):
M src/compiler/representation-change.h
M test/cctest/compiler/test-representation-change.cc
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());
+ 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.
Index: test/cctest/compiler/test-representation-change.cc
diff --git a/test/cctest/compiler/test-representation-change.cc
b/test/cctest/compiler/test-representation-change.cc
index
d28cf4b4b82001c1473a3149cf85bd5a68bc4d00..092a5f7d90cab204aa9fe1a055240f87d382b0f4
100644
--- a/test/cctest/compiler/test-representation-change.cc
+++ b/test/cctest/compiler/test-representation-change.cc
@@ -192,18 +192,11 @@ TEST(SingleChanges) {
TEST(SignednessInWord32) {
RepresentationChangerTester r;
- // TODO(titzer): these are currently type errors because the output type
is
- // not specified. Maybe the RepresentationChanger should assume anything
to or
- // from {rWord32} is {tInt32}, i.e. signed, if not it is explicitly
otherwise?
- r.CheckTypeError(rTagged, rWord32 | tInt32);
- r.CheckTypeError(rTagged, rWord32 | tUint32);
- r.CheckTypeError(rWord32, rFloat64);
- r.CheckTypeError(rFloat64, rWord32);
-
- // CheckChange(IrOpcode::kChangeTaggedToInt32, rTagged, rWord32 |
tInt32);
- // CheckChange(IrOpcode::kChangeTaggedToUint32, rTagged, rWord32 |
tUint32);
- // CheckChange(IrOpcode::kChangeInt32ToFloat64, rWord32, rFloat64);
- // CheckChange(IrOpcode::kChangeFloat64ToInt32, rFloat64, rWord32);
+ // TODO(titzer): assume that uses of a word32 without a sign mean tInt32.
+ CheckChange(IrOpcode::kChangeTaggedToInt32, rTagged, rWord32 | tInt32);
+ CheckChange(IrOpcode::kChangeTaggedToUint32, rTagged, rWord32 | tUint32);
+ CheckChange(IrOpcode::kChangeInt32ToFloat64, rWord32, rFloat64);
+ CheckChange(IrOpcode::kChangeFloat64ToInt32, rFloat64, rWord32);
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.