| Index: src/compiler/simplified-lowering.cc
|
| diff --git a/src/compiler/simplified-lowering.cc b/src/compiler/simplified-lowering.cc
|
| index 9555a3fe00a5dc9e46884420bf488e2d68311957..ca3ed1f75909630d9ae5f3a7757ad90c181f9203 100644
|
| --- a/src/compiler/simplified-lowering.cc
|
| +++ b/src/compiler/simplified-lowering.cc
|
| @@ -2111,6 +2111,31 @@ class RepresentationSelector {
|
| if (lower()) DeferReplacement(node, node->InputAt(0));
|
| return;
|
| }
|
| + case IrOpcode::kNumberToUint8Clamped: {
|
| + Type* const input_type = TypeOf(node->InputAt(0));
|
| + if (input_type->Is(type_cache_.kUint8OrMinusZeroOrNaN)) {
|
| + VisitUnop(node, UseInfo::TruncatingWord32(),
|
| + MachineRepresentation::kWord32);
|
| + if (lower()) DeferReplacement(node, node->InputAt(0));
|
| + } else if (input_type->Is(Type::Unsigned32OrMinusZeroOrNaN())) {
|
| + VisitUnop(node, UseInfo::TruncatingWord32(),
|
| + MachineRepresentation::kWord32);
|
| + if (lower()) lowering->DoUnsigned32ToUint8Clamped(node);
|
| + } else if (input_type->Is(Type::Signed32OrMinusZeroOrNaN())) {
|
| + VisitUnop(node, UseInfo::TruncatingWord32(),
|
| + MachineRepresentation::kWord32);
|
| + if (lower()) lowering->DoSigned32ToUint8Clamped(node);
|
| + } else if (input_type->Is(type_cache_.kIntegerOrMinusZeroOrNaN)) {
|
| + VisitUnop(node, UseInfo::TruncatingFloat64(),
|
| + MachineRepresentation::kFloat64);
|
| + if (lower()) lowering->DoIntegerToUint8Clamped(node);
|
| + } else {
|
| + VisitUnop(node, UseInfo::TruncatingFloat64(),
|
| + MachineRepresentation::kFloat64);
|
| + if (lower()) lowering->DoNumberToUint8Clamped(node);
|
| + }
|
| + return;
|
| + }
|
| case IrOpcode::kReferenceEqual: {
|
| VisitBinop(node, UseInfo::AnyTagged(), MachineRepresentation::kBit);
|
| if (lower()) {
|
| @@ -3294,6 +3319,71 @@ void SimplifiedLowering::DoNumberToBit(Node* node) {
|
| NodeProperties::ChangeOp(node, machine()->Float64LessThan());
|
| }
|
|
|
| +void SimplifiedLowering::DoIntegerToUint8Clamped(Node* node) {
|
| + Node* const input = node->InputAt(0);
|
| + Node* const min = jsgraph()->Float64Constant(0.0);
|
| + Node* const max = jsgraph()->Float64Constant(255.0);
|
| +
|
| + node->ReplaceInput(
|
| + 0, graph()->NewNode(machine()->Float64LessThan(), min, input));
|
| + node->AppendInput(
|
| + graph()->zone(),
|
| + graph()->NewNode(
|
| + common()->Select(MachineRepresentation::kFloat64),
|
| + graph()->NewNode(machine()->Float64LessThan(), input, max), input,
|
| + max));
|
| + node->AppendInput(graph()->zone(), min);
|
| + NodeProperties::ChangeOp(node,
|
| + common()->Select(MachineRepresentation::kFloat64));
|
| +}
|
| +
|
| +void SimplifiedLowering::DoNumberToUint8Clamped(Node* node) {
|
| + Node* const input = node->InputAt(0);
|
| + Node* const min = jsgraph()->Float64Constant(0.0);
|
| + Node* const max = jsgraph()->Float64Constant(255.0);
|
| +
|
| + node->ReplaceInput(
|
| + 0, graph()->NewNode(
|
| + common()->Select(MachineRepresentation::kFloat64),
|
| + graph()->NewNode(machine()->Float64LessThan(), min, input),
|
| + graph()->NewNode(
|
| + common()->Select(MachineRepresentation::kFloat64),
|
| + graph()->NewNode(machine()->Float64LessThan(), input, max),
|
| + input, max),
|
| + min));
|
| + NodeProperties::ChangeOp(node,
|
| + machine()->Float64RoundTiesEven().placeholder());
|
| +}
|
| +
|
| +void SimplifiedLowering::DoSigned32ToUint8Clamped(Node* node) {
|
| + Node* const input = node->InputAt(0);
|
| + Node* const min = jsgraph()->Int32Constant(0);
|
| + Node* const max = jsgraph()->Int32Constant(255);
|
| +
|
| + node->ReplaceInput(
|
| + 0, graph()->NewNode(machine()->Int32LessThanOrEqual(), input, max));
|
| + node->AppendInput(
|
| + graph()->zone(),
|
| + graph()->NewNode(common()->Select(MachineRepresentation::kWord32),
|
| + graph()->NewNode(machine()->Int32LessThan(), input, min),
|
| + min, input));
|
| + node->AppendInput(graph()->zone(), max);
|
| + NodeProperties::ChangeOp(node,
|
| + common()->Select(MachineRepresentation::kWord32));
|
| +}
|
| +
|
| +void SimplifiedLowering::DoUnsigned32ToUint8Clamped(Node* node) {
|
| + Node* const input = node->InputAt(0);
|
| + Node* const max = jsgraph()->Uint32Constant(255u);
|
| +
|
| + node->ReplaceInput(
|
| + 0, graph()->NewNode(machine()->Uint32LessThanOrEqual(), input, max));
|
| + node->AppendInput(graph()->zone(), input);
|
| + node->AppendInput(graph()->zone(), max);
|
| + NodeProperties::ChangeOp(node,
|
| + common()->Select(MachineRepresentation::kWord32));
|
| +}
|
| +
|
| Node* SimplifiedLowering::ToNumberCode() {
|
| if (!to_number_code_.is_set()) {
|
| Callable callable = CodeFactory::ToNumber(isolate());
|
|
|