11cb0ef41Sopenharmony_ci// Copyright 2015 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci#include "src/compiler/representation-change.h"
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci#include <sstream>
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci#include "src/base/bits.h"
101cb0ef41Sopenharmony_ci#include "src/base/safe_conversions.h"
111cb0ef41Sopenharmony_ci#include "src/codegen/code-factory.h"
121cb0ef41Sopenharmony_ci#include "src/compiler/js-heap-broker.h"
131cb0ef41Sopenharmony_ci#include "src/compiler/machine-operator.h"
141cb0ef41Sopenharmony_ci#include "src/compiler/node-matchers.h"
151cb0ef41Sopenharmony_ci#include "src/compiler/simplified-lowering-verifier.h"
161cb0ef41Sopenharmony_ci#include "src/compiler/simplified-operator.h"
171cb0ef41Sopenharmony_ci#include "src/compiler/type-cache.h"
181cb0ef41Sopenharmony_ci#include "src/heap/factory-inl.h"
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_cinamespace v8 {
211cb0ef41Sopenharmony_cinamespace internal {
221cb0ef41Sopenharmony_cinamespace compiler {
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ciconst char* Truncation::description() const {
251cb0ef41Sopenharmony_ci  switch (kind()) {
261cb0ef41Sopenharmony_ci    case TruncationKind::kNone:
271cb0ef41Sopenharmony_ci      return "no-value-use";
281cb0ef41Sopenharmony_ci    case TruncationKind::kBool:
291cb0ef41Sopenharmony_ci      return "truncate-to-bool";
301cb0ef41Sopenharmony_ci    case TruncationKind::kWord32:
311cb0ef41Sopenharmony_ci      return "truncate-to-word32";
321cb0ef41Sopenharmony_ci    case TruncationKind::kWord64:
331cb0ef41Sopenharmony_ci      return "truncate-to-word64";
341cb0ef41Sopenharmony_ci    case TruncationKind::kOddballAndBigIntToNumber:
351cb0ef41Sopenharmony_ci      switch (identify_zeros()) {
361cb0ef41Sopenharmony_ci        case kIdentifyZeros:
371cb0ef41Sopenharmony_ci          return "truncate-oddball&bigint-to-number (identify zeros)";
381cb0ef41Sopenharmony_ci        case kDistinguishZeros:
391cb0ef41Sopenharmony_ci          return "truncate-oddball&bigint-to-number (distinguish zeros)";
401cb0ef41Sopenharmony_ci      }
411cb0ef41Sopenharmony_ci    case TruncationKind::kAny:
421cb0ef41Sopenharmony_ci      switch (identify_zeros()) {
431cb0ef41Sopenharmony_ci        case kIdentifyZeros:
441cb0ef41Sopenharmony_ci          return "no-truncation (but identify zeros)";
451cb0ef41Sopenharmony_ci        case kDistinguishZeros:
461cb0ef41Sopenharmony_ci          return "no-truncation (but distinguish zeros)";
471cb0ef41Sopenharmony_ci      }
481cb0ef41Sopenharmony_ci  }
491cb0ef41Sopenharmony_ci  UNREACHABLE();
501cb0ef41Sopenharmony_ci}
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ci// Partial order for truncations:
531cb0ef41Sopenharmony_ci//
541cb0ef41Sopenharmony_ci//               kAny <-------+
551cb0ef41Sopenharmony_ci//                 ^          |
561cb0ef41Sopenharmony_ci//                 |          |
571cb0ef41Sopenharmony_ci//  kOddballAndBigIntToNumber |
581cb0ef41Sopenharmony_ci//               ^            |
591cb0ef41Sopenharmony_ci//               /            |
601cb0ef41Sopenharmony_ci//        kWord64             |
611cb0ef41Sopenharmony_ci//             ^              |
621cb0ef41Sopenharmony_ci//             |              |
631cb0ef41Sopenharmony_ci//        kWord32           kBool
641cb0ef41Sopenharmony_ci//              ^            ^
651cb0ef41Sopenharmony_ci//              \            /
661cb0ef41Sopenharmony_ci//               \          /
671cb0ef41Sopenharmony_ci//                \        /
681cb0ef41Sopenharmony_ci//                 \      /
691cb0ef41Sopenharmony_ci//                  \    /
701cb0ef41Sopenharmony_ci//                  kNone
711cb0ef41Sopenharmony_ci//
721cb0ef41Sopenharmony_ci// TODO(jarin) We might consider making kBool < kOddballAndBigIntToNumber.
731cb0ef41Sopenharmony_ci
741cb0ef41Sopenharmony_ci// static
751cb0ef41Sopenharmony_ciTruncation::TruncationKind Truncation::Generalize(TruncationKind rep1,
761cb0ef41Sopenharmony_ci                                                  TruncationKind rep2) {
771cb0ef41Sopenharmony_ci  if (LessGeneral(rep1, rep2)) return rep2;
781cb0ef41Sopenharmony_ci  if (LessGeneral(rep2, rep1)) return rep1;
791cb0ef41Sopenharmony_ci  // Handle the generalization of float64-representable values.
801cb0ef41Sopenharmony_ci  if (LessGeneral(rep1, TruncationKind::kOddballAndBigIntToNumber) &&
811cb0ef41Sopenharmony_ci      LessGeneral(rep2, TruncationKind::kOddballAndBigIntToNumber)) {
821cb0ef41Sopenharmony_ci    return TruncationKind::kOddballAndBigIntToNumber;
831cb0ef41Sopenharmony_ci  }
841cb0ef41Sopenharmony_ci  // Handle the generalization of any-representable values.
851cb0ef41Sopenharmony_ci  if (LessGeneral(rep1, TruncationKind::kAny) &&
861cb0ef41Sopenharmony_ci      LessGeneral(rep2, TruncationKind::kAny)) {
871cb0ef41Sopenharmony_ci    return TruncationKind::kAny;
881cb0ef41Sopenharmony_ci  }
891cb0ef41Sopenharmony_ci  // All other combinations are illegal.
901cb0ef41Sopenharmony_ci  FATAL("Tried to combine incompatible truncations");
911cb0ef41Sopenharmony_ci}
921cb0ef41Sopenharmony_ci
931cb0ef41Sopenharmony_ci// static
941cb0ef41Sopenharmony_ciIdentifyZeros Truncation::GeneralizeIdentifyZeros(IdentifyZeros i1,
951cb0ef41Sopenharmony_ci                                                  IdentifyZeros i2) {
961cb0ef41Sopenharmony_ci  if (i1 == i2) {
971cb0ef41Sopenharmony_ci    return i1;
981cb0ef41Sopenharmony_ci  } else {
991cb0ef41Sopenharmony_ci    return kDistinguishZeros;
1001cb0ef41Sopenharmony_ci  }
1011cb0ef41Sopenharmony_ci}
1021cb0ef41Sopenharmony_ci
1031cb0ef41Sopenharmony_ci// static
1041cb0ef41Sopenharmony_cibool Truncation::LessGeneral(TruncationKind rep1, TruncationKind rep2) {
1051cb0ef41Sopenharmony_ci  switch (rep1) {
1061cb0ef41Sopenharmony_ci    case TruncationKind::kNone:
1071cb0ef41Sopenharmony_ci      return true;
1081cb0ef41Sopenharmony_ci    case TruncationKind::kBool:
1091cb0ef41Sopenharmony_ci      return rep2 == TruncationKind::kBool || rep2 == TruncationKind::kAny;
1101cb0ef41Sopenharmony_ci    case TruncationKind::kWord32:
1111cb0ef41Sopenharmony_ci      return rep2 == TruncationKind::kWord32 ||
1121cb0ef41Sopenharmony_ci             rep2 == TruncationKind::kWord64 ||
1131cb0ef41Sopenharmony_ci             rep2 == TruncationKind::kOddballAndBigIntToNumber ||
1141cb0ef41Sopenharmony_ci             rep2 == TruncationKind::kAny;
1151cb0ef41Sopenharmony_ci    case TruncationKind::kWord64:
1161cb0ef41Sopenharmony_ci      return rep2 == TruncationKind::kWord64 ||
1171cb0ef41Sopenharmony_ci             rep2 == TruncationKind::kOddballAndBigIntToNumber ||
1181cb0ef41Sopenharmony_ci             rep2 == TruncationKind::kAny;
1191cb0ef41Sopenharmony_ci    case TruncationKind::kOddballAndBigIntToNumber:
1201cb0ef41Sopenharmony_ci      return rep2 == TruncationKind::kOddballAndBigIntToNumber ||
1211cb0ef41Sopenharmony_ci             rep2 == TruncationKind::kAny;
1221cb0ef41Sopenharmony_ci    case TruncationKind::kAny:
1231cb0ef41Sopenharmony_ci      return rep2 == TruncationKind::kAny;
1241cb0ef41Sopenharmony_ci  }
1251cb0ef41Sopenharmony_ci  UNREACHABLE();
1261cb0ef41Sopenharmony_ci}
1271cb0ef41Sopenharmony_ci
1281cb0ef41Sopenharmony_ci// static
1291cb0ef41Sopenharmony_cibool Truncation::LessGeneralIdentifyZeros(IdentifyZeros i1, IdentifyZeros i2) {
1301cb0ef41Sopenharmony_ci  return i1 == i2 || i1 == kIdentifyZeros;
1311cb0ef41Sopenharmony_ci}
1321cb0ef41Sopenharmony_ci
1331cb0ef41Sopenharmony_cinamespace {
1341cb0ef41Sopenharmony_ci
1351cb0ef41Sopenharmony_cibool IsWord(MachineRepresentation rep) {
1361cb0ef41Sopenharmony_ci  return rep == MachineRepresentation::kWord8 ||
1371cb0ef41Sopenharmony_ci         rep == MachineRepresentation::kWord16 ||
1381cb0ef41Sopenharmony_ci         rep == MachineRepresentation::kWord32;
1391cb0ef41Sopenharmony_ci}
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_ci}  // namespace
1421cb0ef41Sopenharmony_ci
1431cb0ef41Sopenharmony_ciRepresentationChanger::RepresentationChanger(
1441cb0ef41Sopenharmony_ci    JSGraph* jsgraph, JSHeapBroker* broker,
1451cb0ef41Sopenharmony_ci    SimplifiedLoweringVerifier* verifier)
1461cb0ef41Sopenharmony_ci    : cache_(TypeCache::Get()),
1471cb0ef41Sopenharmony_ci      jsgraph_(jsgraph),
1481cb0ef41Sopenharmony_ci      broker_(broker),
1491cb0ef41Sopenharmony_ci      verifier_(verifier),
1501cb0ef41Sopenharmony_ci      testing_type_errors_(false),
1511cb0ef41Sopenharmony_ci      type_error_(false) {}
1521cb0ef41Sopenharmony_ci
1531cb0ef41Sopenharmony_ci// Changes representation from {output_rep} to {use_rep}. The {truncation}
1541cb0ef41Sopenharmony_ci// parameter is only used for checking - if the changer cannot figure
1551cb0ef41Sopenharmony_ci// out signedness for the word32->float64 conversion, then we check that the
1561cb0ef41Sopenharmony_ci// uses truncate to word32 (so they do not care about signedness).
1571cb0ef41Sopenharmony_ciNode* RepresentationChanger::GetRepresentationFor(
1581cb0ef41Sopenharmony_ci    Node* node, MachineRepresentation output_rep, Type output_type,
1591cb0ef41Sopenharmony_ci    Node* use_node, UseInfo use_info) {
1601cb0ef41Sopenharmony_ci  if (output_rep == MachineRepresentation::kNone && !output_type.IsNone()) {
1611cb0ef41Sopenharmony_ci    // The output representation should be set if the type is inhabited (i.e.,
1621cb0ef41Sopenharmony_ci    // if the value is possible).
1631cb0ef41Sopenharmony_ci    return TypeError(node, output_rep, output_type, use_info.representation());
1641cb0ef41Sopenharmony_ci  }
1651cb0ef41Sopenharmony_ci
1661cb0ef41Sopenharmony_ci  // Rematerialize any truncated BigInt if user is not expecting a BigInt.
1671cb0ef41Sopenharmony_ci  if (output_type.Is(Type::BigInt()) &&
1681cb0ef41Sopenharmony_ci      output_rep == MachineRepresentation::kWord64 &&
1691cb0ef41Sopenharmony_ci      use_info.type_check() != TypeCheckKind::kBigInt) {
1701cb0ef41Sopenharmony_ci    if (output_type.Is(Type::UnsignedBigInt64())) {
1711cb0ef41Sopenharmony_ci      node = InsertConversion(node, simplified()->ChangeUint64ToBigInt(),
1721cb0ef41Sopenharmony_ci                              use_node);
1731cb0ef41Sopenharmony_ci    } else {
1741cb0ef41Sopenharmony_ci      node =
1751cb0ef41Sopenharmony_ci          InsertConversion(node, simplified()->ChangeInt64ToBigInt(), use_node);
1761cb0ef41Sopenharmony_ci    }
1771cb0ef41Sopenharmony_ci    output_rep = MachineRepresentation::kTaggedPointer;
1781cb0ef41Sopenharmony_ci  }
1791cb0ef41Sopenharmony_ci
1801cb0ef41Sopenharmony_ci  // Handle the no-op shortcuts when no checking is necessary.
1811cb0ef41Sopenharmony_ci  if (use_info.type_check() == TypeCheckKind::kNone ||
1821cb0ef41Sopenharmony_ci      // TODO(nicohartmann@, chromium:1077804): Ignoring {use_info.type_check()}
1831cb0ef41Sopenharmony_ci      // in case the representation already matches is not correct. For now,
1841cb0ef41Sopenharmony_ci      // this behavior is disabled only for TypeCheckKind::kBigInt, but should
1851cb0ef41Sopenharmony_ci      // be fixed for all other type checks.
1861cb0ef41Sopenharmony_ci      (output_rep != MachineRepresentation::kWord32 &&
1871cb0ef41Sopenharmony_ci       use_info.type_check() != TypeCheckKind::kBigInt)) {
1881cb0ef41Sopenharmony_ci    if (use_info.representation() == output_rep) {
1891cb0ef41Sopenharmony_ci      // Representations are the same. That's a no-op.
1901cb0ef41Sopenharmony_ci      return node;
1911cb0ef41Sopenharmony_ci    }
1921cb0ef41Sopenharmony_ci    if (IsWord(use_info.representation()) && IsWord(output_rep)) {
1931cb0ef41Sopenharmony_ci      // Both are words less than or equal to 32-bits.
1941cb0ef41Sopenharmony_ci      // Since loads of integers from memory implicitly sign or zero extend the
1951cb0ef41Sopenharmony_ci      // value to the full machine word size and stores implicitly truncate,
1961cb0ef41Sopenharmony_ci      // no representation change is necessary.
1971cb0ef41Sopenharmony_ci      return node;
1981cb0ef41Sopenharmony_ci    }
1991cb0ef41Sopenharmony_ci  }
2001cb0ef41Sopenharmony_ci
2011cb0ef41Sopenharmony_ci  switch (use_info.representation()) {
2021cb0ef41Sopenharmony_ci    case MachineRepresentation::kTaggedSigned:
2031cb0ef41Sopenharmony_ci      DCHECK(use_info.type_check() == TypeCheckKind::kNone ||
2041cb0ef41Sopenharmony_ci             use_info.type_check() == TypeCheckKind::kSignedSmall);
2051cb0ef41Sopenharmony_ci      return GetTaggedSignedRepresentationFor(node, output_rep, output_type,
2061cb0ef41Sopenharmony_ci                                              use_node, use_info);
2071cb0ef41Sopenharmony_ci    case MachineRepresentation::kTaggedPointer:
2081cb0ef41Sopenharmony_ci      DCHECK(use_info.type_check() == TypeCheckKind::kNone ||
2091cb0ef41Sopenharmony_ci             use_info.type_check() == TypeCheckKind::kHeapObject ||
2101cb0ef41Sopenharmony_ci             use_info.type_check() == TypeCheckKind::kBigInt);
2111cb0ef41Sopenharmony_ci      return GetTaggedPointerRepresentationFor(node, output_rep, output_type,
2121cb0ef41Sopenharmony_ci                                               use_node, use_info);
2131cb0ef41Sopenharmony_ci    case MachineRepresentation::kTagged:
2141cb0ef41Sopenharmony_ci      DCHECK_EQ(TypeCheckKind::kNone, use_info.type_check());
2151cb0ef41Sopenharmony_ci      return GetTaggedRepresentationFor(node, output_rep, output_type,
2161cb0ef41Sopenharmony_ci                                        use_info.truncation());
2171cb0ef41Sopenharmony_ci    case MachineRepresentation::kFloat32:
2181cb0ef41Sopenharmony_ci      DCHECK_EQ(TypeCheckKind::kNone, use_info.type_check());
2191cb0ef41Sopenharmony_ci      return GetFloat32RepresentationFor(node, output_rep, output_type,
2201cb0ef41Sopenharmony_ci                                         use_info.truncation());
2211cb0ef41Sopenharmony_ci    case MachineRepresentation::kFloat64:
2221cb0ef41Sopenharmony_ci      DCHECK(use_info.type_check() == TypeCheckKind::kNone ||
2231cb0ef41Sopenharmony_ci             use_info.type_check() == TypeCheckKind::kNumber ||
2241cb0ef41Sopenharmony_ci             use_info.type_check() == TypeCheckKind::kNumberOrBoolean ||
2251cb0ef41Sopenharmony_ci             use_info.type_check() == TypeCheckKind::kNumberOrOddball);
2261cb0ef41Sopenharmony_ci      return GetFloat64RepresentationFor(node, output_rep, output_type,
2271cb0ef41Sopenharmony_ci                                         use_node, use_info);
2281cb0ef41Sopenharmony_ci    case MachineRepresentation::kBit:
2291cb0ef41Sopenharmony_ci      DCHECK_EQ(TypeCheckKind::kNone, use_info.type_check());
2301cb0ef41Sopenharmony_ci      return GetBitRepresentationFor(node, output_rep, output_type);
2311cb0ef41Sopenharmony_ci    case MachineRepresentation::kWord8:
2321cb0ef41Sopenharmony_ci    case MachineRepresentation::kWord16:
2331cb0ef41Sopenharmony_ci    case MachineRepresentation::kWord32:
2341cb0ef41Sopenharmony_ci      return GetWord32RepresentationFor(node, output_rep, output_type, use_node,
2351cb0ef41Sopenharmony_ci                                        use_info);
2361cb0ef41Sopenharmony_ci    case MachineRepresentation::kWord64:
2371cb0ef41Sopenharmony_ci      DCHECK(use_info.type_check() == TypeCheckKind::kNone ||
2381cb0ef41Sopenharmony_ci             use_info.type_check() == TypeCheckKind::kSigned64 ||
2391cb0ef41Sopenharmony_ci             use_info.type_check() == TypeCheckKind::kBigInt ||
2401cb0ef41Sopenharmony_ci             use_info.type_check() == TypeCheckKind::kArrayIndex);
2411cb0ef41Sopenharmony_ci      return GetWord64RepresentationFor(node, output_rep, output_type, use_node,
2421cb0ef41Sopenharmony_ci                                        use_info);
2431cb0ef41Sopenharmony_ci    case MachineRepresentation::kSimd128:
2441cb0ef41Sopenharmony_ci    case MachineRepresentation::kNone:
2451cb0ef41Sopenharmony_ci      return node;
2461cb0ef41Sopenharmony_ci    case MachineRepresentation::kCompressed:
2471cb0ef41Sopenharmony_ci    case MachineRepresentation::kCompressedPointer:
2481cb0ef41Sopenharmony_ci    case MachineRepresentation::kSandboxedPointer:
2491cb0ef41Sopenharmony_ci    case MachineRepresentation::kMapWord:
2501cb0ef41Sopenharmony_ci      UNREACHABLE();
2511cb0ef41Sopenharmony_ci  }
2521cb0ef41Sopenharmony_ci  UNREACHABLE();
2531cb0ef41Sopenharmony_ci}
2541cb0ef41Sopenharmony_ci
2551cb0ef41Sopenharmony_ciNode* RepresentationChanger::GetTaggedSignedRepresentationFor(
2561cb0ef41Sopenharmony_ci    Node* node, MachineRepresentation output_rep, Type output_type,
2571cb0ef41Sopenharmony_ci    Node* use_node, UseInfo use_info) {
2581cb0ef41Sopenharmony_ci  // Eagerly fold representation changes for constants.
2591cb0ef41Sopenharmony_ci  switch (node->opcode()) {
2601cb0ef41Sopenharmony_ci    case IrOpcode::kNumberConstant:
2611cb0ef41Sopenharmony_ci      if (output_type.Is(Type::SignedSmall())) {
2621cb0ef41Sopenharmony_ci        return node;
2631cb0ef41Sopenharmony_ci      }
2641cb0ef41Sopenharmony_ci      break;
2651cb0ef41Sopenharmony_ci    default:
2661cb0ef41Sopenharmony_ci      break;
2671cb0ef41Sopenharmony_ci  }
2681cb0ef41Sopenharmony_ci  // Select the correct X -> Tagged operator.
2691cb0ef41Sopenharmony_ci  const Operator* op;
2701cb0ef41Sopenharmony_ci  if (output_type.Is(Type::None())) {
2711cb0ef41Sopenharmony_ci    // This is an impossible value; it should not be used at runtime.
2721cb0ef41Sopenharmony_ci    return jsgraph()->graph()->NewNode(
2731cb0ef41Sopenharmony_ci        jsgraph()->common()->DeadValue(MachineRepresentation::kTaggedSigned),
2741cb0ef41Sopenharmony_ci        node);
2751cb0ef41Sopenharmony_ci  } else if (IsWord(output_rep)) {
2761cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Signed31())) {
2771cb0ef41Sopenharmony_ci      op = simplified()->ChangeInt31ToTaggedSigned();
2781cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Signed32())) {
2791cb0ef41Sopenharmony_ci      if (SmiValuesAre32Bits()) {
2801cb0ef41Sopenharmony_ci        op = simplified()->ChangeInt32ToTagged();
2811cb0ef41Sopenharmony_ci      } else if (use_info.type_check() == TypeCheckKind::kSignedSmall) {
2821cb0ef41Sopenharmony_ci        op = simplified()->CheckedInt32ToTaggedSigned(use_info.feedback());
2831cb0ef41Sopenharmony_ci      } else {
2841cb0ef41Sopenharmony_ci        return TypeError(node, output_rep, output_type,
2851cb0ef41Sopenharmony_ci                         MachineRepresentation::kTaggedSigned);
2861cb0ef41Sopenharmony_ci      }
2871cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Unsigned32()) &&
2881cb0ef41Sopenharmony_ci               use_info.type_check() == TypeCheckKind::kSignedSmall) {
2891cb0ef41Sopenharmony_ci      op = simplified()->CheckedUint32ToTaggedSigned(use_info.feedback());
2901cb0ef41Sopenharmony_ci    } else {
2911cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
2921cb0ef41Sopenharmony_ci                       MachineRepresentation::kTaggedSigned);
2931cb0ef41Sopenharmony_ci    }
2941cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kWord64) {
2951cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Signed31())) {
2961cb0ef41Sopenharmony_ci      // int64 -> int32 -> tagged signed
2971cb0ef41Sopenharmony_ci      node = InsertTruncateInt64ToInt32(node);
2981cb0ef41Sopenharmony_ci      op = simplified()->ChangeInt31ToTaggedSigned();
2991cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Signed32()) && SmiValuesAre32Bits()) {
3001cb0ef41Sopenharmony_ci      // int64 -> int32 -> tagged signed
3011cb0ef41Sopenharmony_ci      node = InsertTruncateInt64ToInt32(node);
3021cb0ef41Sopenharmony_ci      op = simplified()->ChangeInt32ToTagged();
3031cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kSignedSmall) {
3041cb0ef41Sopenharmony_ci      if (output_type.Is(cache_->kPositiveSafeInteger)) {
3051cb0ef41Sopenharmony_ci        op = simplified()->CheckedUint64ToTaggedSigned(use_info.feedback());
3061cb0ef41Sopenharmony_ci      } else if (output_type.Is(cache_->kSafeInteger)) {
3071cb0ef41Sopenharmony_ci        op = simplified()->CheckedInt64ToTaggedSigned(use_info.feedback());
3081cb0ef41Sopenharmony_ci      } else {
3091cb0ef41Sopenharmony_ci        return TypeError(node, output_rep, output_type,
3101cb0ef41Sopenharmony_ci                         MachineRepresentation::kTaggedSigned);
3111cb0ef41Sopenharmony_ci      }
3121cb0ef41Sopenharmony_ci    } else {
3131cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
3141cb0ef41Sopenharmony_ci                       MachineRepresentation::kTaggedSigned);
3151cb0ef41Sopenharmony_ci    }
3161cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kFloat64) {
3171cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Signed31())) {
3181cb0ef41Sopenharmony_ci      // float64 -> int32 -> tagged signed
3191cb0ef41Sopenharmony_ci      node = InsertChangeFloat64ToInt32(node);
3201cb0ef41Sopenharmony_ci      op = simplified()->ChangeInt31ToTaggedSigned();
3211cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Signed32())) {
3221cb0ef41Sopenharmony_ci      // float64 -> int32 -> tagged signed
3231cb0ef41Sopenharmony_ci      node = InsertChangeFloat64ToInt32(node);
3241cb0ef41Sopenharmony_ci      if (SmiValuesAre32Bits()) {
3251cb0ef41Sopenharmony_ci        op = simplified()->ChangeInt32ToTagged();
3261cb0ef41Sopenharmony_ci      } else if (use_info.type_check() == TypeCheckKind::kSignedSmall) {
3271cb0ef41Sopenharmony_ci        op = simplified()->CheckedInt32ToTaggedSigned(use_info.feedback());
3281cb0ef41Sopenharmony_ci      } else {
3291cb0ef41Sopenharmony_ci        return TypeError(node, output_rep, output_type,
3301cb0ef41Sopenharmony_ci                         MachineRepresentation::kTaggedSigned);
3311cb0ef41Sopenharmony_ci      }
3321cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Unsigned32()) &&
3331cb0ef41Sopenharmony_ci               use_info.type_check() == TypeCheckKind::kSignedSmall) {
3341cb0ef41Sopenharmony_ci      // float64 -> uint32 -> tagged signed
3351cb0ef41Sopenharmony_ci      node = InsertChangeFloat64ToUint32(node);
3361cb0ef41Sopenharmony_ci      op = simplified()->CheckedUint32ToTaggedSigned(use_info.feedback());
3371cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kSignedSmall) {
3381cb0ef41Sopenharmony_ci      node = InsertCheckedFloat64ToInt32(
3391cb0ef41Sopenharmony_ci          node,
3401cb0ef41Sopenharmony_ci          output_type.Maybe(Type::MinusZero())
3411cb0ef41Sopenharmony_ci              ? CheckForMinusZeroMode::kCheckForMinusZero
3421cb0ef41Sopenharmony_ci              : CheckForMinusZeroMode::kDontCheckForMinusZero,
3431cb0ef41Sopenharmony_ci          use_info.feedback(), use_node);
3441cb0ef41Sopenharmony_ci      if (SmiValuesAre32Bits()) {
3451cb0ef41Sopenharmony_ci        op = simplified()->ChangeInt32ToTagged();
3461cb0ef41Sopenharmony_ci      } else {
3471cb0ef41Sopenharmony_ci        op = simplified()->CheckedInt32ToTaggedSigned(use_info.feedback());
3481cb0ef41Sopenharmony_ci      }
3491cb0ef41Sopenharmony_ci    } else {
3501cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
3511cb0ef41Sopenharmony_ci                       MachineRepresentation::kTaggedSigned);
3521cb0ef41Sopenharmony_ci    }
3531cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kFloat32) {
3541cb0ef41Sopenharmony_ci    if (use_info.type_check() == TypeCheckKind::kSignedSmall) {
3551cb0ef41Sopenharmony_ci      node = InsertChangeFloat32ToFloat64(node);
3561cb0ef41Sopenharmony_ci      node = InsertCheckedFloat64ToInt32(
3571cb0ef41Sopenharmony_ci          node,
3581cb0ef41Sopenharmony_ci          output_type.Maybe(Type::MinusZero())
3591cb0ef41Sopenharmony_ci              ? CheckForMinusZeroMode::kCheckForMinusZero
3601cb0ef41Sopenharmony_ci              : CheckForMinusZeroMode::kDontCheckForMinusZero,
3611cb0ef41Sopenharmony_ci          use_info.feedback(), use_node);
3621cb0ef41Sopenharmony_ci      if (SmiValuesAre32Bits()) {
3631cb0ef41Sopenharmony_ci        op = simplified()->ChangeInt32ToTagged();
3641cb0ef41Sopenharmony_ci      } else {
3651cb0ef41Sopenharmony_ci        op = simplified()->CheckedInt32ToTaggedSigned(use_info.feedback());
3661cb0ef41Sopenharmony_ci      }
3671cb0ef41Sopenharmony_ci    } else {
3681cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
3691cb0ef41Sopenharmony_ci                       MachineRepresentation::kTaggedSigned);
3701cb0ef41Sopenharmony_ci    }
3711cb0ef41Sopenharmony_ci  } else if (CanBeTaggedPointer(output_rep)) {
3721cb0ef41Sopenharmony_ci    if (use_info.type_check() == TypeCheckKind::kSignedSmall) {
3731cb0ef41Sopenharmony_ci      op = simplified()->CheckedTaggedToTaggedSigned(use_info.feedback());
3741cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::SignedSmall())) {
3751cb0ef41Sopenharmony_ci      op = simplified()->ChangeTaggedToTaggedSigned();
3761cb0ef41Sopenharmony_ci    } else {
3771cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
3781cb0ef41Sopenharmony_ci                       MachineRepresentation::kTaggedSigned);
3791cb0ef41Sopenharmony_ci    }
3801cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kBit) {
3811cb0ef41Sopenharmony_ci    if (use_info.type_check() == TypeCheckKind::kSignedSmall) {
3821cb0ef41Sopenharmony_ci      // TODO(turbofan): Consider adding a Bailout operator that just deopts.
3831cb0ef41Sopenharmony_ci      // Also use that for MachineRepresentation::kPointer case above.
3841cb0ef41Sopenharmony_ci      node = InsertChangeBitToTagged(node);
3851cb0ef41Sopenharmony_ci      op = simplified()->CheckedTaggedToTaggedSigned(use_info.feedback());
3861cb0ef41Sopenharmony_ci    } else {
3871cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
3881cb0ef41Sopenharmony_ci                       MachineRepresentation::kTaggedSigned);
3891cb0ef41Sopenharmony_ci    }
3901cb0ef41Sopenharmony_ci  } else {
3911cb0ef41Sopenharmony_ci    return TypeError(node, output_rep, output_type,
3921cb0ef41Sopenharmony_ci                     MachineRepresentation::kTaggedSigned);
3931cb0ef41Sopenharmony_ci  }
3941cb0ef41Sopenharmony_ci  return InsertConversion(node, op, use_node);
3951cb0ef41Sopenharmony_ci}
3961cb0ef41Sopenharmony_ci
3971cb0ef41Sopenharmony_ciNode* RepresentationChanger::GetTaggedPointerRepresentationFor(
3981cb0ef41Sopenharmony_ci    Node* node, MachineRepresentation output_rep, Type output_type,
3991cb0ef41Sopenharmony_ci    Node* use_node, UseInfo use_info) {
4001cb0ef41Sopenharmony_ci  // Eagerly fold representation changes for constants.
4011cb0ef41Sopenharmony_ci  switch (node->opcode()) {
4021cb0ef41Sopenharmony_ci    case IrOpcode::kHeapConstant:
4031cb0ef41Sopenharmony_ci    case IrOpcode::kDelayedStringConstant:
4041cb0ef41Sopenharmony_ci      if (use_info.type_check() == TypeCheckKind::kBigInt) break;
4051cb0ef41Sopenharmony_ci      return node;  // No change necessary.
4061cb0ef41Sopenharmony_ci    case IrOpcode::kInt32Constant:
4071cb0ef41Sopenharmony_ci    case IrOpcode::kFloat64Constant:
4081cb0ef41Sopenharmony_ci    case IrOpcode::kFloat32Constant:
4091cb0ef41Sopenharmony_ci      UNREACHABLE();
4101cb0ef41Sopenharmony_ci    default:
4111cb0ef41Sopenharmony_ci      break;
4121cb0ef41Sopenharmony_ci  }
4131cb0ef41Sopenharmony_ci  // Select the correct X -> TaggedPointer operator.
4141cb0ef41Sopenharmony_ci  Operator const* op;
4151cb0ef41Sopenharmony_ci  if (output_type.Is(Type::None())) {
4161cb0ef41Sopenharmony_ci    // This is an impossible value; it should not be used at runtime.
4171cb0ef41Sopenharmony_ci    return jsgraph()->graph()->NewNode(
4181cb0ef41Sopenharmony_ci        jsgraph()->common()->DeadValue(MachineRepresentation::kTaggedPointer),
4191cb0ef41Sopenharmony_ci        node);
4201cb0ef41Sopenharmony_ci  }
4211cb0ef41Sopenharmony_ci
4221cb0ef41Sopenharmony_ci  if (use_info.type_check() == TypeCheckKind::kBigInt &&
4231cb0ef41Sopenharmony_ci      !output_type.Is(Type::BigInt())) {
4241cb0ef41Sopenharmony_ci    // BigInt checks can only be performed on tagged representations. Note that
4251cb0ef41Sopenharmony_ci    // a corresponding check is inserted down below.
4261cb0ef41Sopenharmony_ci    if (!CanBeTaggedPointer(output_rep)) {
4271cb0ef41Sopenharmony_ci      Node* unreachable =
4281cb0ef41Sopenharmony_ci          InsertUnconditionalDeopt(use_node, DeoptimizeReason::kNotABigInt);
4291cb0ef41Sopenharmony_ci      return jsgraph()->graph()->NewNode(
4301cb0ef41Sopenharmony_ci          jsgraph()->common()->DeadValue(MachineRepresentation::kTaggedPointer),
4311cb0ef41Sopenharmony_ci          unreachable);
4321cb0ef41Sopenharmony_ci    }
4331cb0ef41Sopenharmony_ci  }
4341cb0ef41Sopenharmony_ci
4351cb0ef41Sopenharmony_ci  if (output_rep == MachineRepresentation::kBit) {
4361cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Boolean())) {
4371cb0ef41Sopenharmony_ci      op = simplified()->ChangeBitToTagged();
4381cb0ef41Sopenharmony_ci    } else {
4391cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
4401cb0ef41Sopenharmony_ci                       MachineRepresentation::kTagged);
4411cb0ef41Sopenharmony_ci    }
4421cb0ef41Sopenharmony_ci  } else if (IsWord(output_rep)) {
4431cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Unsigned32())) {
4441cb0ef41Sopenharmony_ci      // uint32 -> float64 -> tagged
4451cb0ef41Sopenharmony_ci      node = InsertChangeUint32ToFloat64(node);
4461cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Signed32())) {
4471cb0ef41Sopenharmony_ci      // int32 -> float64 -> tagged
4481cb0ef41Sopenharmony_ci      node = InsertChangeInt32ToFloat64(node);
4491cb0ef41Sopenharmony_ci    } else {
4501cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
4511cb0ef41Sopenharmony_ci                       MachineRepresentation::kTaggedPointer);
4521cb0ef41Sopenharmony_ci    }
4531cb0ef41Sopenharmony_ci    op = simplified()->ChangeFloat64ToTaggedPointer();
4541cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kWord64) {
4551cb0ef41Sopenharmony_ci    if (output_type.Is(cache_->kSafeInteger)) {
4561cb0ef41Sopenharmony_ci      // int64 -> float64 -> tagged pointer
4571cb0ef41Sopenharmony_ci      op = machine()->ChangeInt64ToFloat64();
4581cb0ef41Sopenharmony_ci      node = jsgraph()->graph()->NewNode(op, node);
4591cb0ef41Sopenharmony_ci      op = simplified()->ChangeFloat64ToTaggedPointer();
4601cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::SignedBigInt64()) &&
4611cb0ef41Sopenharmony_ci               use_info.type_check() == TypeCheckKind::kBigInt) {
4621cb0ef41Sopenharmony_ci      op = simplified()->ChangeInt64ToBigInt();
4631cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::UnsignedBigInt64()) &&
4641cb0ef41Sopenharmony_ci               use_info.type_check() == TypeCheckKind::kBigInt) {
4651cb0ef41Sopenharmony_ci      op = simplified()->ChangeUint64ToBigInt();
4661cb0ef41Sopenharmony_ci    } else {
4671cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
4681cb0ef41Sopenharmony_ci                       MachineRepresentation::kTaggedPointer);
4691cb0ef41Sopenharmony_ci    }
4701cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kFloat32) {
4711cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Number())) {
4721cb0ef41Sopenharmony_ci      // float32 -> float64 -> tagged
4731cb0ef41Sopenharmony_ci      node = InsertChangeFloat32ToFloat64(node);
4741cb0ef41Sopenharmony_ci      op = simplified()->ChangeFloat64ToTaggedPointer();
4751cb0ef41Sopenharmony_ci    } else {
4761cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
4771cb0ef41Sopenharmony_ci                       MachineRepresentation::kTaggedPointer);
4781cb0ef41Sopenharmony_ci    }
4791cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kFloat64) {
4801cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Number())) {
4811cb0ef41Sopenharmony_ci      // float64 -> tagged
4821cb0ef41Sopenharmony_ci      op = simplified()->ChangeFloat64ToTaggedPointer();
4831cb0ef41Sopenharmony_ci    } else {
4841cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
4851cb0ef41Sopenharmony_ci                       MachineRepresentation::kTaggedPointer);
4861cb0ef41Sopenharmony_ci    }
4871cb0ef41Sopenharmony_ci  } else if (CanBeTaggedSigned(output_rep) &&
4881cb0ef41Sopenharmony_ci             use_info.type_check() == TypeCheckKind::kHeapObject) {
4891cb0ef41Sopenharmony_ci    if (!output_type.Maybe(Type::SignedSmall())) {
4901cb0ef41Sopenharmony_ci      return node;
4911cb0ef41Sopenharmony_ci    }
4921cb0ef41Sopenharmony_ci    // TODO(turbofan): Consider adding a Bailout operator that just deopts
4931cb0ef41Sopenharmony_ci    // for TaggedSigned output representation.
4941cb0ef41Sopenharmony_ci    op = simplified()->CheckedTaggedToTaggedPointer(use_info.feedback());
4951cb0ef41Sopenharmony_ci  } else if (IsAnyTagged(output_rep) &&
4961cb0ef41Sopenharmony_ci             (use_info.type_check() == TypeCheckKind::kBigInt ||
4971cb0ef41Sopenharmony_ci              output_type.Is(Type::BigInt()))) {
4981cb0ef41Sopenharmony_ci    if (output_type.Is(Type::BigInt())) {
4991cb0ef41Sopenharmony_ci      return node;
5001cb0ef41Sopenharmony_ci    }
5011cb0ef41Sopenharmony_ci    op = simplified()->CheckBigInt(use_info.feedback());
5021cb0ef41Sopenharmony_ci  } else {
5031cb0ef41Sopenharmony_ci    return TypeError(node, output_rep, output_type,
5041cb0ef41Sopenharmony_ci                     MachineRepresentation::kTaggedPointer);
5051cb0ef41Sopenharmony_ci  }
5061cb0ef41Sopenharmony_ci  return InsertConversion(node, op, use_node);
5071cb0ef41Sopenharmony_ci}
5081cb0ef41Sopenharmony_ci
5091cb0ef41Sopenharmony_ciNode* RepresentationChanger::GetTaggedRepresentationFor(
5101cb0ef41Sopenharmony_ci    Node* node, MachineRepresentation output_rep, Type output_type,
5111cb0ef41Sopenharmony_ci    Truncation truncation) {
5121cb0ef41Sopenharmony_ci  // Eagerly fold representation changes for constants.
5131cb0ef41Sopenharmony_ci  switch (node->opcode()) {
5141cb0ef41Sopenharmony_ci    case IrOpcode::kNumberConstant:
5151cb0ef41Sopenharmony_ci    case IrOpcode::kHeapConstant:
5161cb0ef41Sopenharmony_ci    case IrOpcode::kDelayedStringConstant:
5171cb0ef41Sopenharmony_ci      return node;  // No change necessary.
5181cb0ef41Sopenharmony_ci    case IrOpcode::kInt32Constant:
5191cb0ef41Sopenharmony_ci    case IrOpcode::kFloat64Constant:
5201cb0ef41Sopenharmony_ci    case IrOpcode::kFloat32Constant:
5211cb0ef41Sopenharmony_ci      UNREACHABLE();
5221cb0ef41Sopenharmony_ci    default:
5231cb0ef41Sopenharmony_ci      break;
5241cb0ef41Sopenharmony_ci  }
5251cb0ef41Sopenharmony_ci  if (output_rep == MachineRepresentation::kTaggedSigned ||
5261cb0ef41Sopenharmony_ci      output_rep == MachineRepresentation::kTaggedPointer ||
5271cb0ef41Sopenharmony_ci      output_rep == MachineRepresentation::kMapWord) {
5281cb0ef41Sopenharmony_ci    // this is a no-op.
5291cb0ef41Sopenharmony_ci    return node;
5301cb0ef41Sopenharmony_ci  }
5311cb0ef41Sopenharmony_ci  // Select the correct X -> Tagged operator.
5321cb0ef41Sopenharmony_ci  const Operator* op;
5331cb0ef41Sopenharmony_ci  if (output_type.Is(Type::None())) {
5341cb0ef41Sopenharmony_ci    // This is an impossible value; it should not be used at runtime.
5351cb0ef41Sopenharmony_ci    return jsgraph()->graph()->NewNode(
5361cb0ef41Sopenharmony_ci        jsgraph()->common()->DeadValue(MachineRepresentation::kTagged), node);
5371cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kBit) {
5381cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Boolean())) {
5391cb0ef41Sopenharmony_ci      op = simplified()->ChangeBitToTagged();
5401cb0ef41Sopenharmony_ci    } else {
5411cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
5421cb0ef41Sopenharmony_ci                       MachineRepresentation::kTagged);
5431cb0ef41Sopenharmony_ci    }
5441cb0ef41Sopenharmony_ci  } else if (IsWord(output_rep)) {
5451cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Signed31())) {
5461cb0ef41Sopenharmony_ci      op = simplified()->ChangeInt31ToTaggedSigned();
5471cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Signed32()) ||
5481cb0ef41Sopenharmony_ci               (output_type.Is(Type::Signed32OrMinusZero()) &&
5491cb0ef41Sopenharmony_ci                truncation.IdentifiesZeroAndMinusZero())) {
5501cb0ef41Sopenharmony_ci      op = simplified()->ChangeInt32ToTagged();
5511cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Unsigned32()) ||
5521cb0ef41Sopenharmony_ci               (output_type.Is(Type::Unsigned32OrMinusZero()) &&
5531cb0ef41Sopenharmony_ci                truncation.IdentifiesZeroAndMinusZero()) ||
5541cb0ef41Sopenharmony_ci               truncation.IsUsedAsWord32()) {
5551cb0ef41Sopenharmony_ci      // Either the output is uint32 or the uses only care about the
5561cb0ef41Sopenharmony_ci      // low 32 bits (so we can pick uint32 safely).
5571cb0ef41Sopenharmony_ci      op = simplified()->ChangeUint32ToTagged();
5581cb0ef41Sopenharmony_ci    } else {
5591cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
5601cb0ef41Sopenharmony_ci                       MachineRepresentation::kTagged);
5611cb0ef41Sopenharmony_ci    }
5621cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kWord64) {
5631cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Signed31())) {
5641cb0ef41Sopenharmony_ci      // int64 -> int32 -> tagged signed
5651cb0ef41Sopenharmony_ci      node = InsertTruncateInt64ToInt32(node);
5661cb0ef41Sopenharmony_ci      op = simplified()->ChangeInt31ToTaggedSigned();
5671cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Signed32())) {
5681cb0ef41Sopenharmony_ci      // int64 -> int32 -> tagged
5691cb0ef41Sopenharmony_ci      node = InsertTruncateInt64ToInt32(node);
5701cb0ef41Sopenharmony_ci      op = simplified()->ChangeInt32ToTagged();
5711cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Unsigned32())) {
5721cb0ef41Sopenharmony_ci      // int64 -> uint32 -> tagged
5731cb0ef41Sopenharmony_ci      node = InsertTruncateInt64ToInt32(node);
5741cb0ef41Sopenharmony_ci      op = simplified()->ChangeUint32ToTagged();
5751cb0ef41Sopenharmony_ci    } else if (output_type.Is(cache_->kPositiveSafeInteger)) {
5761cb0ef41Sopenharmony_ci      // uint64 -> tagged
5771cb0ef41Sopenharmony_ci      op = simplified()->ChangeUint64ToTagged();
5781cb0ef41Sopenharmony_ci    } else if (output_type.Is(cache_->kSafeInteger)) {
5791cb0ef41Sopenharmony_ci      // int64 -> tagged
5801cb0ef41Sopenharmony_ci      op = simplified()->ChangeInt64ToTagged();
5811cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::SignedBigInt64())) {
5821cb0ef41Sopenharmony_ci      // int64 -> BigInt
5831cb0ef41Sopenharmony_ci      op = simplified()->ChangeInt64ToBigInt();
5841cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::UnsignedBigInt64())) {
5851cb0ef41Sopenharmony_ci      // uint64 -> BigInt
5861cb0ef41Sopenharmony_ci      op = simplified()->ChangeUint64ToBigInt();
5871cb0ef41Sopenharmony_ci    } else {
5881cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
5891cb0ef41Sopenharmony_ci                       MachineRepresentation::kTagged);
5901cb0ef41Sopenharmony_ci    }
5911cb0ef41Sopenharmony_ci  } else if (output_rep ==
5921cb0ef41Sopenharmony_ci             MachineRepresentation::kFloat32) {  // float32 -> float64 -> tagged
5931cb0ef41Sopenharmony_ci    node = InsertChangeFloat32ToFloat64(node);
5941cb0ef41Sopenharmony_ci    op = simplified()->ChangeFloat64ToTagged(
5951cb0ef41Sopenharmony_ci        output_type.Maybe(Type::MinusZero())
5961cb0ef41Sopenharmony_ci            ? CheckForMinusZeroMode::kCheckForMinusZero
5971cb0ef41Sopenharmony_ci            : CheckForMinusZeroMode::kDontCheckForMinusZero);
5981cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kFloat64) {
5991cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Signed31())) {  // float64 -> int32 -> tagged
6001cb0ef41Sopenharmony_ci      node = InsertChangeFloat64ToInt32(node);
6011cb0ef41Sopenharmony_ci      op = simplified()->ChangeInt31ToTaggedSigned();
6021cb0ef41Sopenharmony_ci    } else if (output_type.Is(
6031cb0ef41Sopenharmony_ci                   Type::Signed32())) {  // float64 -> int32 -> tagged
6041cb0ef41Sopenharmony_ci      node = InsertChangeFloat64ToInt32(node);
6051cb0ef41Sopenharmony_ci      op = simplified()->ChangeInt32ToTagged();
6061cb0ef41Sopenharmony_ci    } else if (output_type.Is(
6071cb0ef41Sopenharmony_ci                   Type::Unsigned32())) {  // float64 -> uint32 -> tagged
6081cb0ef41Sopenharmony_ci      node = InsertChangeFloat64ToUint32(node);
6091cb0ef41Sopenharmony_ci      op = simplified()->ChangeUint32ToTagged();
6101cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Number()) ||
6111cb0ef41Sopenharmony_ci               (output_type.Is(Type::NumberOrOddball()) &&
6121cb0ef41Sopenharmony_ci                truncation.TruncatesOddballAndBigIntToNumber())) {
6131cb0ef41Sopenharmony_ci      op = simplified()->ChangeFloat64ToTagged(
6141cb0ef41Sopenharmony_ci          output_type.Maybe(Type::MinusZero())
6151cb0ef41Sopenharmony_ci              ? CheckForMinusZeroMode::kCheckForMinusZero
6161cb0ef41Sopenharmony_ci              : CheckForMinusZeroMode::kDontCheckForMinusZero);
6171cb0ef41Sopenharmony_ci    } else {
6181cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
6191cb0ef41Sopenharmony_ci                       MachineRepresentation::kTagged);
6201cb0ef41Sopenharmony_ci    }
6211cb0ef41Sopenharmony_ci  } else {
6221cb0ef41Sopenharmony_ci    return TypeError(node, output_rep, output_type,
6231cb0ef41Sopenharmony_ci                     MachineRepresentation::kTagged);
6241cb0ef41Sopenharmony_ci  }
6251cb0ef41Sopenharmony_ci  return jsgraph()->graph()->NewNode(op, node);
6261cb0ef41Sopenharmony_ci}
6271cb0ef41Sopenharmony_ci
6281cb0ef41Sopenharmony_ciNode* RepresentationChanger::GetFloat32RepresentationFor(
6291cb0ef41Sopenharmony_ci    Node* node, MachineRepresentation output_rep, Type output_type,
6301cb0ef41Sopenharmony_ci    Truncation truncation) {
6311cb0ef41Sopenharmony_ci  // Eagerly fold representation changes for constants.
6321cb0ef41Sopenharmony_ci  switch (node->opcode()) {
6331cb0ef41Sopenharmony_ci    case IrOpcode::kNumberConstant:
6341cb0ef41Sopenharmony_ci      return jsgraph()->Float32Constant(
6351cb0ef41Sopenharmony_ci          DoubleToFloat32(OpParameter<double>(node->op())));
6361cb0ef41Sopenharmony_ci    case IrOpcode::kInt32Constant:
6371cb0ef41Sopenharmony_ci    case IrOpcode::kFloat64Constant:
6381cb0ef41Sopenharmony_ci    case IrOpcode::kFloat32Constant:
6391cb0ef41Sopenharmony_ci      UNREACHABLE();
6401cb0ef41Sopenharmony_ci    default:
6411cb0ef41Sopenharmony_ci      break;
6421cb0ef41Sopenharmony_ci  }
6431cb0ef41Sopenharmony_ci  // Select the correct X -> Float32 operator.
6441cb0ef41Sopenharmony_ci  const Operator* op = nullptr;
6451cb0ef41Sopenharmony_ci  if (output_type.Is(Type::None())) {
6461cb0ef41Sopenharmony_ci    // This is an impossible value; it should not be used at runtime.
6471cb0ef41Sopenharmony_ci    return jsgraph()->graph()->NewNode(
6481cb0ef41Sopenharmony_ci        jsgraph()->common()->DeadValue(MachineRepresentation::kFloat32), node);
6491cb0ef41Sopenharmony_ci  } else if (IsWord(output_rep)) {
6501cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Signed32())) {
6511cb0ef41Sopenharmony_ci      // int32 -> float64 -> float32
6521cb0ef41Sopenharmony_ci      op = machine()->ChangeInt32ToFloat64();
6531cb0ef41Sopenharmony_ci      node = jsgraph()->graph()->NewNode(op, node);
6541cb0ef41Sopenharmony_ci      op = machine()->TruncateFloat64ToFloat32();
6551cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Unsigned32()) ||
6561cb0ef41Sopenharmony_ci               truncation.IsUsedAsWord32()) {
6571cb0ef41Sopenharmony_ci      // Either the output is uint32 or the uses only care about the
6581cb0ef41Sopenharmony_ci      // low 32 bits (so we can pick uint32 safely).
6591cb0ef41Sopenharmony_ci
6601cb0ef41Sopenharmony_ci      // uint32 -> float64 -> float32
6611cb0ef41Sopenharmony_ci      op = machine()->ChangeUint32ToFloat64();
6621cb0ef41Sopenharmony_ci      node = jsgraph()->graph()->NewNode(op, node);
6631cb0ef41Sopenharmony_ci      op = machine()->TruncateFloat64ToFloat32();
6641cb0ef41Sopenharmony_ci    }
6651cb0ef41Sopenharmony_ci  } else if (IsAnyTagged(output_rep)) {
6661cb0ef41Sopenharmony_ci    if (output_type.Is(Type::NumberOrOddball())) {
6671cb0ef41Sopenharmony_ci      // tagged -> float64 -> float32
6681cb0ef41Sopenharmony_ci      if (output_type.Is(Type::Number())) {
6691cb0ef41Sopenharmony_ci        op = simplified()->ChangeTaggedToFloat64();
6701cb0ef41Sopenharmony_ci      } else {
6711cb0ef41Sopenharmony_ci        op = simplified()->TruncateTaggedToFloat64();
6721cb0ef41Sopenharmony_ci      }
6731cb0ef41Sopenharmony_ci      node = jsgraph()->graph()->NewNode(op, node);
6741cb0ef41Sopenharmony_ci      op = machine()->TruncateFloat64ToFloat32();
6751cb0ef41Sopenharmony_ci    }
6761cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kFloat64) {
6771cb0ef41Sopenharmony_ci    op = machine()->TruncateFloat64ToFloat32();
6781cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kWord64) {
6791cb0ef41Sopenharmony_ci    if (output_type.Is(cache_->kSafeInteger)) {
6801cb0ef41Sopenharmony_ci      // int64 -> float64 -> float32
6811cb0ef41Sopenharmony_ci      op = machine()->ChangeInt64ToFloat64();
6821cb0ef41Sopenharmony_ci      node = jsgraph()->graph()->NewNode(op, node);
6831cb0ef41Sopenharmony_ci      op = machine()->TruncateFloat64ToFloat32();
6841cb0ef41Sopenharmony_ci    }
6851cb0ef41Sopenharmony_ci  }
6861cb0ef41Sopenharmony_ci  if (op == nullptr) {
6871cb0ef41Sopenharmony_ci    return TypeError(node, output_rep, output_type,
6881cb0ef41Sopenharmony_ci                     MachineRepresentation::kFloat32);
6891cb0ef41Sopenharmony_ci  }
6901cb0ef41Sopenharmony_ci  return jsgraph()->graph()->NewNode(op, node);
6911cb0ef41Sopenharmony_ci}
6921cb0ef41Sopenharmony_ci
6931cb0ef41Sopenharmony_ciNode* RepresentationChanger::GetFloat64RepresentationFor(
6941cb0ef41Sopenharmony_ci    Node* node, MachineRepresentation output_rep, Type output_type,
6951cb0ef41Sopenharmony_ci    Node* use_node, UseInfo use_info) {
6961cb0ef41Sopenharmony_ci  NumberMatcher m(node);
6971cb0ef41Sopenharmony_ci  if (m.HasResolvedValue()) {
6981cb0ef41Sopenharmony_ci    // BigInts are not used as number constants.
6991cb0ef41Sopenharmony_ci    DCHECK(use_info.type_check() != TypeCheckKind::kBigInt);
7001cb0ef41Sopenharmony_ci    switch (use_info.type_check()) {
7011cb0ef41Sopenharmony_ci      case TypeCheckKind::kNone:
7021cb0ef41Sopenharmony_ci      case TypeCheckKind::kNumber:
7031cb0ef41Sopenharmony_ci      case TypeCheckKind::kNumberOrBoolean:
7041cb0ef41Sopenharmony_ci      case TypeCheckKind::kNumberOrOddball:
7051cb0ef41Sopenharmony_ci        return jsgraph()->Float64Constant(m.ResolvedValue());
7061cb0ef41Sopenharmony_ci      case TypeCheckKind::kBigInt:
7071cb0ef41Sopenharmony_ci      case TypeCheckKind::kHeapObject:
7081cb0ef41Sopenharmony_ci      case TypeCheckKind::kSigned32:
7091cb0ef41Sopenharmony_ci      case TypeCheckKind::kSigned64:
7101cb0ef41Sopenharmony_ci      case TypeCheckKind::kSignedSmall:
7111cb0ef41Sopenharmony_ci      case TypeCheckKind::kArrayIndex:
7121cb0ef41Sopenharmony_ci        break;
7131cb0ef41Sopenharmony_ci    }
7141cb0ef41Sopenharmony_ci  }
7151cb0ef41Sopenharmony_ci  // Select the correct X -> Float64 operator.
7161cb0ef41Sopenharmony_ci  const Operator* op = nullptr;
7171cb0ef41Sopenharmony_ci  if (output_type.Is(Type::None())) {
7181cb0ef41Sopenharmony_ci    // This is an impossible value; it should not be used at runtime.
7191cb0ef41Sopenharmony_ci    return jsgraph()->graph()->NewNode(
7201cb0ef41Sopenharmony_ci        jsgraph()->common()->DeadValue(MachineRepresentation::kFloat64), node);
7211cb0ef41Sopenharmony_ci  } else if (IsWord(output_rep)) {
7221cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Signed32()) ||
7231cb0ef41Sopenharmony_ci        (output_type.Is(Type::Signed32OrMinusZero()) &&
7241cb0ef41Sopenharmony_ci         use_info.truncation().IdentifiesZeroAndMinusZero())) {
7251cb0ef41Sopenharmony_ci      op = machine()->ChangeInt32ToFloat64();
7261cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Unsigned32()) ||
7271cb0ef41Sopenharmony_ci               (output_type.Is(Type::Unsigned32OrMinusZero()) &&
7281cb0ef41Sopenharmony_ci                use_info.truncation().IdentifiesZeroAndMinusZero()) ||
7291cb0ef41Sopenharmony_ci               use_info.truncation().IsUsedAsWord32()) {
7301cb0ef41Sopenharmony_ci      // Either the output is uint32 or the uses only care about the
7311cb0ef41Sopenharmony_ci      // low 32 bits (so we can pick uint32 safely).
7321cb0ef41Sopenharmony_ci      op = machine()->ChangeUint32ToFloat64();
7331cb0ef41Sopenharmony_ci    }
7341cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kBit) {
7351cb0ef41Sopenharmony_ci    CHECK(output_type.Is(Type::Boolean()));
7361cb0ef41Sopenharmony_ci    if (use_info.truncation().TruncatesOddballAndBigIntToNumber() ||
7371cb0ef41Sopenharmony_ci        use_info.type_check() == TypeCheckKind::kNumberOrBoolean ||
7381cb0ef41Sopenharmony_ci        use_info.type_check() == TypeCheckKind::kNumberOrOddball) {
7391cb0ef41Sopenharmony_ci      op = machine()->ChangeUint32ToFloat64();
7401cb0ef41Sopenharmony_ci    } else {
7411cb0ef41Sopenharmony_ci      CHECK_NE(use_info.type_check(), TypeCheckKind::kNone);
7421cb0ef41Sopenharmony_ci      Node* unreachable =
7431cb0ef41Sopenharmony_ci          InsertUnconditionalDeopt(use_node, DeoptimizeReason::kNotAHeapNumber);
7441cb0ef41Sopenharmony_ci      return jsgraph()->graph()->NewNode(
7451cb0ef41Sopenharmony_ci          jsgraph()->common()->DeadValue(MachineRepresentation::kFloat64),
7461cb0ef41Sopenharmony_ci          unreachable);
7471cb0ef41Sopenharmony_ci    }
7481cb0ef41Sopenharmony_ci  } else if (IsAnyTagged(output_rep)) {
7491cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Undefined())) {
7501cb0ef41Sopenharmony_ci      if (use_info.type_check() == TypeCheckKind::kNumberOrOddball ||
7511cb0ef41Sopenharmony_ci          (use_info.type_check() == TypeCheckKind::kNone &&
7521cb0ef41Sopenharmony_ci           use_info.truncation().TruncatesOddballAndBigIntToNumber())) {
7531cb0ef41Sopenharmony_ci        return jsgraph()->Float64Constant(
7541cb0ef41Sopenharmony_ci            std::numeric_limits<double>::quiet_NaN());
7551cb0ef41Sopenharmony_ci      } else {
7561cb0ef41Sopenharmony_ci        DCHECK(use_info.type_check() == TypeCheckKind::kNone ||
7571cb0ef41Sopenharmony_ci               use_info.type_check() == TypeCheckKind::kNumber ||
7581cb0ef41Sopenharmony_ci               use_info.type_check() == TypeCheckKind::kNumberOrBoolean);
7591cb0ef41Sopenharmony_ci        Node* unreachable = InsertUnconditionalDeopt(
7601cb0ef41Sopenharmony_ci            use_node, use_info.type_check() == TypeCheckKind::kNumber
7611cb0ef41Sopenharmony_ci                          ? DeoptimizeReason::kNotANumber
7621cb0ef41Sopenharmony_ci                          : DeoptimizeReason::kNotANumberOrBoolean);
7631cb0ef41Sopenharmony_ci        return jsgraph()->graph()->NewNode(
7641cb0ef41Sopenharmony_ci            jsgraph()->common()->DeadValue(MachineRepresentation::kFloat64),
7651cb0ef41Sopenharmony_ci            unreachable);
7661cb0ef41Sopenharmony_ci      }
7671cb0ef41Sopenharmony_ci    } else if (output_rep == MachineRepresentation::kTaggedSigned) {
7681cb0ef41Sopenharmony_ci      node = InsertChangeTaggedSignedToInt32(node);
7691cb0ef41Sopenharmony_ci      op = machine()->ChangeInt32ToFloat64();
7701cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Number())) {
7711cb0ef41Sopenharmony_ci      op = simplified()->ChangeTaggedToFloat64();
7721cb0ef41Sopenharmony_ci    } else if ((output_type.Is(Type::NumberOrOddball()) &&
7731cb0ef41Sopenharmony_ci                use_info.truncation().TruncatesOddballAndBigIntToNumber()) ||
7741cb0ef41Sopenharmony_ci               output_type.Is(Type::NumberOrHole())) {
7751cb0ef41Sopenharmony_ci      // JavaScript 'null' is an Oddball that results in +0 when truncated to
7761cb0ef41Sopenharmony_ci      // Number. In a context like -0 == null, which must evaluate to false,
7771cb0ef41Sopenharmony_ci      // this truncation must not happen. For this reason we restrict this
7781cb0ef41Sopenharmony_ci      // case to when either the user explicitly requested a float (and thus
7791cb0ef41Sopenharmony_ci      // wants +0 if null is the input) or we know from the types that the
7801cb0ef41Sopenharmony_ci      // input can only be Number | Hole. The latter is necessary to handle
7811cb0ef41Sopenharmony_ci      // the operator CheckFloat64Hole. We did not put in the type (Number |
7821cb0ef41Sopenharmony_ci      // Oddball \ Null) to discover more bugs related to this conversion via
7831cb0ef41Sopenharmony_ci      // crashes.
7841cb0ef41Sopenharmony_ci      op = simplified()->TruncateTaggedToFloat64();
7851cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kNumber ||
7861cb0ef41Sopenharmony_ci               (use_info.type_check() == TypeCheckKind::kNumberOrOddball &&
7871cb0ef41Sopenharmony_ci                !output_type.Maybe(Type::BooleanOrNullOrNumber()))) {
7881cb0ef41Sopenharmony_ci      op = simplified()->CheckedTaggedToFloat64(CheckTaggedInputMode::kNumber,
7891cb0ef41Sopenharmony_ci                                                use_info.feedback());
7901cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kNumberOrBoolean) {
7911cb0ef41Sopenharmony_ci      op = simplified()->CheckedTaggedToFloat64(
7921cb0ef41Sopenharmony_ci          CheckTaggedInputMode::kNumberOrBoolean, use_info.feedback());
7931cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kNumberOrOddball) {
7941cb0ef41Sopenharmony_ci      op = simplified()->CheckedTaggedToFloat64(
7951cb0ef41Sopenharmony_ci          CheckTaggedInputMode::kNumberOrOddball, use_info.feedback());
7961cb0ef41Sopenharmony_ci    }
7971cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kFloat32) {
7981cb0ef41Sopenharmony_ci    op = machine()->ChangeFloat32ToFloat64();
7991cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kWord64) {
8001cb0ef41Sopenharmony_ci    if (output_type.Is(cache_->kSafeInteger)) {
8011cb0ef41Sopenharmony_ci      op = machine()->ChangeInt64ToFloat64();
8021cb0ef41Sopenharmony_ci    }
8031cb0ef41Sopenharmony_ci  }
8041cb0ef41Sopenharmony_ci  if (op == nullptr) {
8051cb0ef41Sopenharmony_ci    return TypeError(node, output_rep, output_type,
8061cb0ef41Sopenharmony_ci                     MachineRepresentation::kFloat64);
8071cb0ef41Sopenharmony_ci  }
8081cb0ef41Sopenharmony_ci  return InsertConversion(node, op, use_node);
8091cb0ef41Sopenharmony_ci}
8101cb0ef41Sopenharmony_ci
8111cb0ef41Sopenharmony_ciNode* RepresentationChanger::MakeTruncatedInt32Constant(double value) {
8121cb0ef41Sopenharmony_ci  return jsgraph()->Int32Constant(DoubleToInt32(value));
8131cb0ef41Sopenharmony_ci}
8141cb0ef41Sopenharmony_ci
8151cb0ef41Sopenharmony_ciNode* RepresentationChanger::InsertUnconditionalDeopt(
8161cb0ef41Sopenharmony_ci    Node* node, DeoptimizeReason reason, const FeedbackSource& feedback) {
8171cb0ef41Sopenharmony_ci  Node* effect = NodeProperties::GetEffectInput(node);
8181cb0ef41Sopenharmony_ci  Node* control = NodeProperties::GetControlInput(node);
8191cb0ef41Sopenharmony_ci  effect =
8201cb0ef41Sopenharmony_ci      jsgraph()->graph()->NewNode(simplified()->CheckIf(reason, feedback),
8211cb0ef41Sopenharmony_ci                                  jsgraph()->Int32Constant(0), effect, control);
8221cb0ef41Sopenharmony_ci  Node* unreachable = effect = jsgraph()->graph()->NewNode(
8231cb0ef41Sopenharmony_ci      jsgraph()->common()->Unreachable(), effect, control);
8241cb0ef41Sopenharmony_ci  NodeProperties::ReplaceEffectInput(node, effect);
8251cb0ef41Sopenharmony_ci  return unreachable;
8261cb0ef41Sopenharmony_ci}
8271cb0ef41Sopenharmony_ci
8281cb0ef41Sopenharmony_ciNode* RepresentationChanger::GetWord32RepresentationFor(
8291cb0ef41Sopenharmony_ci    Node* node, MachineRepresentation output_rep, Type output_type,
8301cb0ef41Sopenharmony_ci    Node* use_node, UseInfo use_info) {
8311cb0ef41Sopenharmony_ci  // Eagerly fold representation changes for constants.
8321cb0ef41Sopenharmony_ci  switch (node->opcode()) {
8331cb0ef41Sopenharmony_ci    case IrOpcode::kInt32Constant:
8341cb0ef41Sopenharmony_ci    case IrOpcode::kInt64Constant:
8351cb0ef41Sopenharmony_ci    case IrOpcode::kFloat32Constant:
8361cb0ef41Sopenharmony_ci    case IrOpcode::kFloat64Constant:
8371cb0ef41Sopenharmony_ci      UNREACHABLE();
8381cb0ef41Sopenharmony_ci    case IrOpcode::kNumberConstant: {
8391cb0ef41Sopenharmony_ci      double const fv = OpParameter<double>(node->op());
8401cb0ef41Sopenharmony_ci      if (use_info.type_check() == TypeCheckKind::kNone ||
8411cb0ef41Sopenharmony_ci          ((use_info.type_check() == TypeCheckKind::kSignedSmall ||
8421cb0ef41Sopenharmony_ci            use_info.type_check() == TypeCheckKind::kSigned32 ||
8431cb0ef41Sopenharmony_ci            use_info.type_check() == TypeCheckKind::kNumber ||
8441cb0ef41Sopenharmony_ci            use_info.type_check() == TypeCheckKind::kNumberOrOddball ||
8451cb0ef41Sopenharmony_ci            use_info.type_check() == TypeCheckKind::kArrayIndex) &&
8461cb0ef41Sopenharmony_ci           IsInt32Double(fv))) {
8471cb0ef41Sopenharmony_ci        return InsertTypeOverrideForVerifier(NodeProperties::GetType(node),
8481cb0ef41Sopenharmony_ci                                             MakeTruncatedInt32Constant(fv));
8491cb0ef41Sopenharmony_ci      }
8501cb0ef41Sopenharmony_ci      break;
8511cb0ef41Sopenharmony_ci    }
8521cb0ef41Sopenharmony_ci    default:
8531cb0ef41Sopenharmony_ci      break;
8541cb0ef41Sopenharmony_ci  }
8551cb0ef41Sopenharmony_ci
8561cb0ef41Sopenharmony_ci  // Select the correct X -> Word32 operator.
8571cb0ef41Sopenharmony_ci  const Operator* op = nullptr;
8581cb0ef41Sopenharmony_ci  if (output_type.Is(Type::None())) {
8591cb0ef41Sopenharmony_ci    // This is an impossible value; it should not be used at runtime.
8601cb0ef41Sopenharmony_ci    return jsgraph()->graph()->NewNode(
8611cb0ef41Sopenharmony_ci        jsgraph()->common()->DeadValue(MachineRepresentation::kWord32), node);
8621cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kBit) {
8631cb0ef41Sopenharmony_ci    CHECK(output_type.Is(Type::Boolean()));
8641cb0ef41Sopenharmony_ci    if (use_info.truncation().IsUsedAsWord32()) {
8651cb0ef41Sopenharmony_ci      return node;
8661cb0ef41Sopenharmony_ci    } else {
8671cb0ef41Sopenharmony_ci      CHECK(Truncation::Any(kIdentifyZeros)
8681cb0ef41Sopenharmony_ci                .IsLessGeneralThan(use_info.truncation()));
8691cb0ef41Sopenharmony_ci      CHECK_NE(use_info.type_check(), TypeCheckKind::kNone);
8701cb0ef41Sopenharmony_ci      CHECK_NE(use_info.type_check(), TypeCheckKind::kNumberOrOddball);
8711cb0ef41Sopenharmony_ci      Node* unreachable =
8721cb0ef41Sopenharmony_ci          InsertUnconditionalDeopt(use_node, DeoptimizeReason::kNotASmi);
8731cb0ef41Sopenharmony_ci      return jsgraph()->graph()->NewNode(
8741cb0ef41Sopenharmony_ci          jsgraph()->common()->DeadValue(MachineRepresentation::kWord32),
8751cb0ef41Sopenharmony_ci          unreachable);
8761cb0ef41Sopenharmony_ci    }
8771cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kFloat64) {
8781cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Signed32())) {
8791cb0ef41Sopenharmony_ci      op = machine()->ChangeFloat64ToInt32();
8801cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kSignedSmall ||
8811cb0ef41Sopenharmony_ci               use_info.type_check() == TypeCheckKind::kSigned32 ||
8821cb0ef41Sopenharmony_ci               use_info.type_check() == TypeCheckKind::kArrayIndex) {
8831cb0ef41Sopenharmony_ci      op = simplified()->CheckedFloat64ToInt32(
8841cb0ef41Sopenharmony_ci          output_type.Maybe(Type::MinusZero())
8851cb0ef41Sopenharmony_ci              ? use_info.minus_zero_check()
8861cb0ef41Sopenharmony_ci              : CheckForMinusZeroMode::kDontCheckForMinusZero,
8871cb0ef41Sopenharmony_ci          use_info.feedback());
8881cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Unsigned32())) {
8891cb0ef41Sopenharmony_ci      op = machine()->ChangeFloat64ToUint32();
8901cb0ef41Sopenharmony_ci    } else if (use_info.truncation().IsUsedAsWord32()) {
8911cb0ef41Sopenharmony_ci      op = machine()->TruncateFloat64ToWord32();
8921cb0ef41Sopenharmony_ci    } else {
8931cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
8941cb0ef41Sopenharmony_ci                       MachineRepresentation::kWord32);
8951cb0ef41Sopenharmony_ci    }
8961cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kFloat32) {
8971cb0ef41Sopenharmony_ci    node = InsertChangeFloat32ToFloat64(node);  // float32 -> float64 -> int32
8981cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Signed32())) {
8991cb0ef41Sopenharmony_ci      op = machine()->ChangeFloat64ToInt32();
9001cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kSignedSmall ||
9011cb0ef41Sopenharmony_ci               use_info.type_check() == TypeCheckKind::kSigned32 ||
9021cb0ef41Sopenharmony_ci               use_info.type_check() == TypeCheckKind::kArrayIndex) {
9031cb0ef41Sopenharmony_ci      op = simplified()->CheckedFloat64ToInt32(
9041cb0ef41Sopenharmony_ci          output_type.Maybe(Type::MinusZero())
9051cb0ef41Sopenharmony_ci              ? use_info.minus_zero_check()
9061cb0ef41Sopenharmony_ci              : CheckForMinusZeroMode::kDontCheckForMinusZero,
9071cb0ef41Sopenharmony_ci          use_info.feedback());
9081cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Unsigned32())) {
9091cb0ef41Sopenharmony_ci      op = machine()->ChangeFloat64ToUint32();
9101cb0ef41Sopenharmony_ci    } else if (use_info.truncation().IsUsedAsWord32()) {
9111cb0ef41Sopenharmony_ci      op = machine()->TruncateFloat64ToWord32();
9121cb0ef41Sopenharmony_ci    } else {
9131cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
9141cb0ef41Sopenharmony_ci                       MachineRepresentation::kWord32);
9151cb0ef41Sopenharmony_ci    }
9161cb0ef41Sopenharmony_ci  } else if (IsAnyTagged(output_rep)) {
9171cb0ef41Sopenharmony_ci    if (output_rep == MachineRepresentation::kTaggedSigned &&
9181cb0ef41Sopenharmony_ci        output_type.Is(Type::SignedSmall())) {
9191cb0ef41Sopenharmony_ci      op = simplified()->ChangeTaggedSignedToInt32();
9201cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Signed32())) {
9211cb0ef41Sopenharmony_ci      op = simplified()->ChangeTaggedToInt32();
9221cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kSignedSmall) {
9231cb0ef41Sopenharmony_ci      op = simplified()->CheckedTaggedSignedToInt32(use_info.feedback());
9241cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kSigned32) {
9251cb0ef41Sopenharmony_ci      op = simplified()->CheckedTaggedToInt32(
9261cb0ef41Sopenharmony_ci          output_type.Maybe(Type::MinusZero())
9271cb0ef41Sopenharmony_ci              ? use_info.minus_zero_check()
9281cb0ef41Sopenharmony_ci              : CheckForMinusZeroMode::kDontCheckForMinusZero,
9291cb0ef41Sopenharmony_ci          use_info.feedback());
9301cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kArrayIndex) {
9311cb0ef41Sopenharmony_ci      op = simplified()->CheckedTaggedToArrayIndex(use_info.feedback());
9321cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Unsigned32())) {
9331cb0ef41Sopenharmony_ci      op = simplified()->ChangeTaggedToUint32();
9341cb0ef41Sopenharmony_ci    } else if (use_info.truncation().IsUsedAsWord32()) {
9351cb0ef41Sopenharmony_ci      if (output_type.Is(Type::NumberOrOddball())) {
9361cb0ef41Sopenharmony_ci        op = simplified()->TruncateTaggedToWord32();
9371cb0ef41Sopenharmony_ci      } else if (use_info.type_check() == TypeCheckKind::kNumber) {
9381cb0ef41Sopenharmony_ci        op = simplified()->CheckedTruncateTaggedToWord32(
9391cb0ef41Sopenharmony_ci            CheckTaggedInputMode::kNumber, use_info.feedback());
9401cb0ef41Sopenharmony_ci      } else if (use_info.type_check() == TypeCheckKind::kNumberOrOddball) {
9411cb0ef41Sopenharmony_ci        op = simplified()->CheckedTruncateTaggedToWord32(
9421cb0ef41Sopenharmony_ci            CheckTaggedInputMode::kNumberOrOddball, use_info.feedback());
9431cb0ef41Sopenharmony_ci      } else {
9441cb0ef41Sopenharmony_ci        return TypeError(node, output_rep, output_type,
9451cb0ef41Sopenharmony_ci                         MachineRepresentation::kWord32);
9461cb0ef41Sopenharmony_ci      }
9471cb0ef41Sopenharmony_ci    } else {
9481cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
9491cb0ef41Sopenharmony_ci                       MachineRepresentation::kWord32);
9501cb0ef41Sopenharmony_ci    }
9511cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kWord32) {
9521cb0ef41Sopenharmony_ci    // Only the checked case should get here, the non-checked case is
9531cb0ef41Sopenharmony_ci    // handled in GetRepresentationFor.
9541cb0ef41Sopenharmony_ci    if (use_info.type_check() == TypeCheckKind::kSignedSmall ||
9551cb0ef41Sopenharmony_ci        use_info.type_check() == TypeCheckKind::kSigned32 ||
9561cb0ef41Sopenharmony_ci        use_info.type_check() == TypeCheckKind::kArrayIndex) {
9571cb0ef41Sopenharmony_ci      bool identify_zeros = use_info.truncation().IdentifiesZeroAndMinusZero();
9581cb0ef41Sopenharmony_ci      if (output_type.Is(Type::Signed32()) ||
9591cb0ef41Sopenharmony_ci          (identify_zeros && output_type.Is(Type::Signed32OrMinusZero()))) {
9601cb0ef41Sopenharmony_ci        return node;
9611cb0ef41Sopenharmony_ci      } else if (output_type.Is(Type::Unsigned32()) ||
9621cb0ef41Sopenharmony_ci                 (identify_zeros &&
9631cb0ef41Sopenharmony_ci                  output_type.Is(Type::Unsigned32OrMinusZero()))) {
9641cb0ef41Sopenharmony_ci        op = simplified()->CheckedUint32ToInt32(use_info.feedback());
9651cb0ef41Sopenharmony_ci      } else {
9661cb0ef41Sopenharmony_ci        return TypeError(node, output_rep, output_type,
9671cb0ef41Sopenharmony_ci                         MachineRepresentation::kWord32);
9681cb0ef41Sopenharmony_ci      }
9691cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kNumber ||
9701cb0ef41Sopenharmony_ci               use_info.type_check() == TypeCheckKind::kNumberOrOddball) {
9711cb0ef41Sopenharmony_ci      return node;
9721cb0ef41Sopenharmony_ci    }
9731cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kWord8 ||
9741cb0ef41Sopenharmony_ci             output_rep == MachineRepresentation::kWord16) {
9751cb0ef41Sopenharmony_ci    DCHECK_EQ(MachineRepresentation::kWord32, use_info.representation());
9761cb0ef41Sopenharmony_ci    DCHECK(use_info.type_check() == TypeCheckKind::kSignedSmall ||
9771cb0ef41Sopenharmony_ci           use_info.type_check() == TypeCheckKind::kSigned32);
9781cb0ef41Sopenharmony_ci    return node;
9791cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kWord64) {
9801cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Signed32()) ||
9811cb0ef41Sopenharmony_ci        (output_type.Is(Type::Unsigned32()) &&
9821cb0ef41Sopenharmony_ci         use_info.type_check() == TypeCheckKind::kNone) ||
9831cb0ef41Sopenharmony_ci        (output_type.Is(cache_->kSafeInteger) &&
9841cb0ef41Sopenharmony_ci         use_info.truncation().IsUsedAsWord32())) {
9851cb0ef41Sopenharmony_ci      op = machine()->TruncateInt64ToInt32();
9861cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kSignedSmall ||
9871cb0ef41Sopenharmony_ci               use_info.type_check() == TypeCheckKind::kSigned32 ||
9881cb0ef41Sopenharmony_ci               use_info.type_check() == TypeCheckKind::kArrayIndex) {
9891cb0ef41Sopenharmony_ci      if (output_type.Is(cache_->kPositiveSafeInteger)) {
9901cb0ef41Sopenharmony_ci        op = simplified()->CheckedUint64ToInt32(use_info.feedback());
9911cb0ef41Sopenharmony_ci      } else if (output_type.Is(cache_->kSafeInteger)) {
9921cb0ef41Sopenharmony_ci        op = simplified()->CheckedInt64ToInt32(use_info.feedback());
9931cb0ef41Sopenharmony_ci      } else {
9941cb0ef41Sopenharmony_ci        return TypeError(node, output_rep, output_type,
9951cb0ef41Sopenharmony_ci                         MachineRepresentation::kWord32);
9961cb0ef41Sopenharmony_ci      }
9971cb0ef41Sopenharmony_ci    } else {
9981cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
9991cb0ef41Sopenharmony_ci                       MachineRepresentation::kWord32);
10001cb0ef41Sopenharmony_ci    }
10011cb0ef41Sopenharmony_ci  }
10021cb0ef41Sopenharmony_ci
10031cb0ef41Sopenharmony_ci  if (op == nullptr) {
10041cb0ef41Sopenharmony_ci    return TypeError(node, output_rep, output_type,
10051cb0ef41Sopenharmony_ci                     MachineRepresentation::kWord32);
10061cb0ef41Sopenharmony_ci  }
10071cb0ef41Sopenharmony_ci  return InsertConversion(node, op, use_node);
10081cb0ef41Sopenharmony_ci}
10091cb0ef41Sopenharmony_ci
10101cb0ef41Sopenharmony_ciNode* RepresentationChanger::InsertConversion(Node* node, const Operator* op,
10111cb0ef41Sopenharmony_ci                                              Node* use_node) {
10121cb0ef41Sopenharmony_ci  if (op->ControlInputCount() > 0) {
10131cb0ef41Sopenharmony_ci    // If the operator can deoptimize (which means it has control
10141cb0ef41Sopenharmony_ci    // input), we need to connect it to the effect and control chains.
10151cb0ef41Sopenharmony_ci    Node* effect = NodeProperties::GetEffectInput(use_node);
10161cb0ef41Sopenharmony_ci    Node* control = NodeProperties::GetControlInput(use_node);
10171cb0ef41Sopenharmony_ci    Node* conversion = jsgraph()->graph()->NewNode(op, node, effect, control);
10181cb0ef41Sopenharmony_ci    NodeProperties::ReplaceEffectInput(use_node, conversion);
10191cb0ef41Sopenharmony_ci    return conversion;
10201cb0ef41Sopenharmony_ci  }
10211cb0ef41Sopenharmony_ci  return jsgraph()->graph()->NewNode(op, node);
10221cb0ef41Sopenharmony_ci}
10231cb0ef41Sopenharmony_ci
10241cb0ef41Sopenharmony_ciNode* RepresentationChanger::GetBitRepresentationFor(
10251cb0ef41Sopenharmony_ci    Node* node, MachineRepresentation output_rep, Type output_type) {
10261cb0ef41Sopenharmony_ci  // Eagerly fold representation changes for constants.
10271cb0ef41Sopenharmony_ci  switch (node->opcode()) {
10281cb0ef41Sopenharmony_ci    case IrOpcode::kHeapConstant: {
10291cb0ef41Sopenharmony_ci      HeapObjectMatcher m(node);
10301cb0ef41Sopenharmony_ci      if (m.Is(factory()->false_value())) {
10311cb0ef41Sopenharmony_ci        return jsgraph()->Int32Constant(0);
10321cb0ef41Sopenharmony_ci      } else if (m.Is(factory()->true_value())) {
10331cb0ef41Sopenharmony_ci        return jsgraph()->Int32Constant(1);
10341cb0ef41Sopenharmony_ci      }
10351cb0ef41Sopenharmony_ci      break;
10361cb0ef41Sopenharmony_ci    }
10371cb0ef41Sopenharmony_ci    default:
10381cb0ef41Sopenharmony_ci      break;
10391cb0ef41Sopenharmony_ci  }
10401cb0ef41Sopenharmony_ci  // Select the correct X -> Bit operator.
10411cb0ef41Sopenharmony_ci  const Operator* op;
10421cb0ef41Sopenharmony_ci  if (output_type.Is(Type::None())) {
10431cb0ef41Sopenharmony_ci    // This is an impossible value; it should not be used at runtime.
10441cb0ef41Sopenharmony_ci    return jsgraph()->graph()->NewNode(
10451cb0ef41Sopenharmony_ci        jsgraph()->common()->DeadValue(MachineRepresentation::kBit), node);
10461cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kTagged ||
10471cb0ef41Sopenharmony_ci             output_rep == MachineRepresentation::kTaggedPointer) {
10481cb0ef41Sopenharmony_ci    if (output_type.Is(Type::BooleanOrNullOrUndefined())) {
10491cb0ef41Sopenharmony_ci      // true is the only trueish Oddball.
10501cb0ef41Sopenharmony_ci      op = simplified()->ChangeTaggedToBit();
10511cb0ef41Sopenharmony_ci    } else {
10521cb0ef41Sopenharmony_ci      if (output_rep == MachineRepresentation::kTagged &&
10531cb0ef41Sopenharmony_ci          output_type.Maybe(Type::SignedSmall())) {
10541cb0ef41Sopenharmony_ci        op = simplified()->TruncateTaggedToBit();
10551cb0ef41Sopenharmony_ci      } else {
10561cb0ef41Sopenharmony_ci        // The {output_type} either doesn't include the Smi range,
10571cb0ef41Sopenharmony_ci        // or the {output_rep} is known to be TaggedPointer.
10581cb0ef41Sopenharmony_ci        op = simplified()->TruncateTaggedPointerToBit();
10591cb0ef41Sopenharmony_ci      }
10601cb0ef41Sopenharmony_ci    }
10611cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kTaggedSigned) {
10621cb0ef41Sopenharmony_ci    if (COMPRESS_POINTERS_BOOL) {
10631cb0ef41Sopenharmony_ci      node = jsgraph()->graph()->NewNode(machine()->Word32Equal(), node,
10641cb0ef41Sopenharmony_ci                                         jsgraph()->Int32Constant(0));
10651cb0ef41Sopenharmony_ci    } else {
10661cb0ef41Sopenharmony_ci      node = jsgraph()->graph()->NewNode(machine()->WordEqual(), node,
10671cb0ef41Sopenharmony_ci                                         jsgraph()->IntPtrConstant(0));
10681cb0ef41Sopenharmony_ci    }
10691cb0ef41Sopenharmony_ci    return jsgraph()->graph()->NewNode(machine()->Word32Equal(), node,
10701cb0ef41Sopenharmony_ci                                       jsgraph()->Int32Constant(0));
10711cb0ef41Sopenharmony_ci  } else if (IsWord(output_rep)) {
10721cb0ef41Sopenharmony_ci    node = jsgraph()->graph()->NewNode(machine()->Word32Equal(), node,
10731cb0ef41Sopenharmony_ci                                       jsgraph()->Int32Constant(0));
10741cb0ef41Sopenharmony_ci    return jsgraph()->graph()->NewNode(machine()->Word32Equal(), node,
10751cb0ef41Sopenharmony_ci                                       jsgraph()->Int32Constant(0));
10761cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kWord64) {
10771cb0ef41Sopenharmony_ci    node = jsgraph()->graph()->NewNode(machine()->Word64Equal(), node,
10781cb0ef41Sopenharmony_ci                                       jsgraph()->Int64Constant(0));
10791cb0ef41Sopenharmony_ci    return jsgraph()->graph()->NewNode(machine()->Word32Equal(), node,
10801cb0ef41Sopenharmony_ci                                       jsgraph()->Int32Constant(0));
10811cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kFloat32) {
10821cb0ef41Sopenharmony_ci    node = jsgraph()->graph()->NewNode(machine()->Float32Abs(), node);
10831cb0ef41Sopenharmony_ci    return jsgraph()->graph()->NewNode(machine()->Float32LessThan(),
10841cb0ef41Sopenharmony_ci                                       jsgraph()->Float32Constant(0.0), node);
10851cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kFloat64) {
10861cb0ef41Sopenharmony_ci    node = jsgraph()->graph()->NewNode(machine()->Float64Abs(), node);
10871cb0ef41Sopenharmony_ci    return jsgraph()->graph()->NewNode(machine()->Float64LessThan(),
10881cb0ef41Sopenharmony_ci                                       jsgraph()->Float64Constant(0.0), node);
10891cb0ef41Sopenharmony_ci  } else {
10901cb0ef41Sopenharmony_ci    return TypeError(node, output_rep, output_type,
10911cb0ef41Sopenharmony_ci                     MachineRepresentation::kBit);
10921cb0ef41Sopenharmony_ci  }
10931cb0ef41Sopenharmony_ci  return jsgraph()->graph()->NewNode(op, node);
10941cb0ef41Sopenharmony_ci}
10951cb0ef41Sopenharmony_ci
10961cb0ef41Sopenharmony_ciNode* RepresentationChanger::GetWord64RepresentationFor(
10971cb0ef41Sopenharmony_ci    Node* node, MachineRepresentation output_rep, Type output_type,
10981cb0ef41Sopenharmony_ci    Node* use_node, UseInfo use_info) {
10991cb0ef41Sopenharmony_ci  // Eagerly fold representation changes for constants.
11001cb0ef41Sopenharmony_ci  switch (node->opcode()) {
11011cb0ef41Sopenharmony_ci    case IrOpcode::kInt32Constant:
11021cb0ef41Sopenharmony_ci    case IrOpcode::kInt64Constant:
11031cb0ef41Sopenharmony_ci    case IrOpcode::kFloat32Constant:
11041cb0ef41Sopenharmony_ci    case IrOpcode::kFloat64Constant:
11051cb0ef41Sopenharmony_ci      UNREACHABLE();
11061cb0ef41Sopenharmony_ci    case IrOpcode::kNumberConstant: {
11071cb0ef41Sopenharmony_ci      if (use_info.type_check() != TypeCheckKind::kBigInt) {
11081cb0ef41Sopenharmony_ci        double const fv = OpParameter<double>(node->op());
11091cb0ef41Sopenharmony_ci        if (base::IsValueInRangeForNumericType<int64_t>(fv)) {
11101cb0ef41Sopenharmony_ci          int64_t const iv = static_cast<int64_t>(fv);
11111cb0ef41Sopenharmony_ci          if (static_cast<double>(iv) == fv) {
11121cb0ef41Sopenharmony_ci            return InsertTypeOverrideForVerifier(NodeProperties::GetType(node),
11131cb0ef41Sopenharmony_ci                                                 jsgraph()->Int64Constant(iv));
11141cb0ef41Sopenharmony_ci          }
11151cb0ef41Sopenharmony_ci        }
11161cb0ef41Sopenharmony_ci      }
11171cb0ef41Sopenharmony_ci      break;
11181cb0ef41Sopenharmony_ci    }
11191cb0ef41Sopenharmony_ci    case IrOpcode::kHeapConstant: {
11201cb0ef41Sopenharmony_ci      HeapObjectMatcher m(node);
11211cb0ef41Sopenharmony_ci      if (m.HasResolvedValue() && m.Ref(broker_).IsBigInt() &&
11221cb0ef41Sopenharmony_ci          use_info.truncation().IsUsedAsWord64()) {
11231cb0ef41Sopenharmony_ci        BigIntRef bigint = m.Ref(broker_).AsBigInt();
11241cb0ef41Sopenharmony_ci        return InsertTypeOverrideForVerifier(
11251cb0ef41Sopenharmony_ci            NodeProperties::GetType(node),
11261cb0ef41Sopenharmony_ci            jsgraph()->Int64Constant(static_cast<int64_t>(bigint.AsUint64())));
11271cb0ef41Sopenharmony_ci      }
11281cb0ef41Sopenharmony_ci      break;
11291cb0ef41Sopenharmony_ci    }
11301cb0ef41Sopenharmony_ci    default:
11311cb0ef41Sopenharmony_ci      break;
11321cb0ef41Sopenharmony_ci  }
11331cb0ef41Sopenharmony_ci
11341cb0ef41Sopenharmony_ci  if (use_info.type_check() == TypeCheckKind::kBigInt) {
11351cb0ef41Sopenharmony_ci    // BigInts are only represented as tagged pointer and word64.
11361cb0ef41Sopenharmony_ci    if (!CanBeTaggedPointer(output_rep) &&
11371cb0ef41Sopenharmony_ci        output_rep != MachineRepresentation::kWord64) {
11381cb0ef41Sopenharmony_ci      DCHECK(!output_type.Equals(Type::BigInt()));
11391cb0ef41Sopenharmony_ci      Node* unreachable = InsertUnconditionalDeopt(
11401cb0ef41Sopenharmony_ci          use_node, DeoptimizeReason::kNotABigInt, use_info.feedback());
11411cb0ef41Sopenharmony_ci      return jsgraph()->graph()->NewNode(
11421cb0ef41Sopenharmony_ci          jsgraph()->common()->DeadValue(MachineRepresentation::kWord64),
11431cb0ef41Sopenharmony_ci          unreachable);
11441cb0ef41Sopenharmony_ci    }
11451cb0ef41Sopenharmony_ci  }
11461cb0ef41Sopenharmony_ci
11471cb0ef41Sopenharmony_ci  // Select the correct X -> Word64 operator.
11481cb0ef41Sopenharmony_ci  const Operator* op;
11491cb0ef41Sopenharmony_ci  if (output_type.Is(Type::None())) {
11501cb0ef41Sopenharmony_ci    // This is an impossible value; it should not be used at runtime.
11511cb0ef41Sopenharmony_ci    return jsgraph()->graph()->NewNode(
11521cb0ef41Sopenharmony_ci        jsgraph()->common()->DeadValue(MachineRepresentation::kWord64), node);
11531cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kBit) {
11541cb0ef41Sopenharmony_ci    CHECK(output_type.Is(Type::Boolean()));
11551cb0ef41Sopenharmony_ci    CHECK_NE(use_info.type_check(), TypeCheckKind::kNone);
11561cb0ef41Sopenharmony_ci    CHECK_NE(use_info.type_check(), TypeCheckKind::kNumberOrOddball);
11571cb0ef41Sopenharmony_ci    CHECK_NE(use_info.type_check(), TypeCheckKind::kBigInt);
11581cb0ef41Sopenharmony_ci    Node* unreachable =
11591cb0ef41Sopenharmony_ci        InsertUnconditionalDeopt(use_node, DeoptimizeReason::kNotASmi);
11601cb0ef41Sopenharmony_ci    return jsgraph()->graph()->NewNode(
11611cb0ef41Sopenharmony_ci        jsgraph()->common()->DeadValue(MachineRepresentation::kWord64),
11621cb0ef41Sopenharmony_ci        unreachable);
11631cb0ef41Sopenharmony_ci  } else if (IsWord(output_rep)) {
11641cb0ef41Sopenharmony_ci    if (output_type.Is(Type::Unsigned32OrMinusZero())) {
11651cb0ef41Sopenharmony_ci      // uint32 -> uint64
11661cb0ef41Sopenharmony_ci      CHECK_IMPLIES(output_type.Maybe(Type::MinusZero()),
11671cb0ef41Sopenharmony_ci                    use_info.truncation().IdentifiesZeroAndMinusZero());
11681cb0ef41Sopenharmony_ci      op = machine()->ChangeUint32ToUint64();
11691cb0ef41Sopenharmony_ci    } else if (output_type.Is(Type::Signed32OrMinusZero())) {
11701cb0ef41Sopenharmony_ci      // int32 -> int64
11711cb0ef41Sopenharmony_ci      CHECK_IMPLIES(output_type.Maybe(Type::MinusZero()),
11721cb0ef41Sopenharmony_ci                    use_info.truncation().IdentifiesZeroAndMinusZero());
11731cb0ef41Sopenharmony_ci      op = machine()->ChangeInt32ToInt64();
11741cb0ef41Sopenharmony_ci    } else {
11751cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
11761cb0ef41Sopenharmony_ci                       MachineRepresentation::kWord64);
11771cb0ef41Sopenharmony_ci    }
11781cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kFloat32) {
11791cb0ef41Sopenharmony_ci    if (output_type.Is(cache_->kDoubleRepresentableInt64)) {
11801cb0ef41Sopenharmony_ci      // float32 -> float64 -> int64
11811cb0ef41Sopenharmony_ci      node = InsertChangeFloat32ToFloat64(node);
11821cb0ef41Sopenharmony_ci      op = machine()->ChangeFloat64ToInt64();
11831cb0ef41Sopenharmony_ci    } else if (output_type.Is(cache_->kDoubleRepresentableUint64)) {
11841cb0ef41Sopenharmony_ci      // float32 -> float64 -> uint64
11851cb0ef41Sopenharmony_ci      node = InsertChangeFloat32ToFloat64(node);
11861cb0ef41Sopenharmony_ci      op = machine()->ChangeFloat64ToUint64();
11871cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kSigned64 ||
11881cb0ef41Sopenharmony_ci               use_info.type_check() == TypeCheckKind::kArrayIndex) {
11891cb0ef41Sopenharmony_ci      // float32 -> float64 -> int64
11901cb0ef41Sopenharmony_ci      node = InsertChangeFloat32ToFloat64(node);
11911cb0ef41Sopenharmony_ci      op = simplified()->CheckedFloat64ToInt64(
11921cb0ef41Sopenharmony_ci          output_type.Maybe(Type::MinusZero())
11931cb0ef41Sopenharmony_ci              ? use_info.minus_zero_check()
11941cb0ef41Sopenharmony_ci              : CheckForMinusZeroMode::kDontCheckForMinusZero,
11951cb0ef41Sopenharmony_ci          use_info.feedback());
11961cb0ef41Sopenharmony_ci    } else {
11971cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
11981cb0ef41Sopenharmony_ci                       MachineRepresentation::kWord64);
11991cb0ef41Sopenharmony_ci    }
12001cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kFloat64) {
12011cb0ef41Sopenharmony_ci    if (output_type.Is(cache_->kDoubleRepresentableInt64)) {
12021cb0ef41Sopenharmony_ci      op = machine()->ChangeFloat64ToInt64();
12031cb0ef41Sopenharmony_ci    } else if (output_type.Is(cache_->kDoubleRepresentableUint64)) {
12041cb0ef41Sopenharmony_ci      op = machine()->ChangeFloat64ToUint64();
12051cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kSigned64 ||
12061cb0ef41Sopenharmony_ci               use_info.type_check() == TypeCheckKind::kArrayIndex) {
12071cb0ef41Sopenharmony_ci      op = simplified()->CheckedFloat64ToInt64(
12081cb0ef41Sopenharmony_ci          output_type.Maybe(Type::MinusZero())
12091cb0ef41Sopenharmony_ci              ? use_info.minus_zero_check()
12101cb0ef41Sopenharmony_ci              : CheckForMinusZeroMode::kDontCheckForMinusZero,
12111cb0ef41Sopenharmony_ci          use_info.feedback());
12121cb0ef41Sopenharmony_ci    } else {
12131cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
12141cb0ef41Sopenharmony_ci                       MachineRepresentation::kWord64);
12151cb0ef41Sopenharmony_ci    }
12161cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kTaggedSigned) {
12171cb0ef41Sopenharmony_ci    if (output_type.Is(Type::SignedSmall())) {
12181cb0ef41Sopenharmony_ci      op = simplified()->ChangeTaggedSignedToInt64();
12191cb0ef41Sopenharmony_ci    } else {
12201cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
12211cb0ef41Sopenharmony_ci                       MachineRepresentation::kWord64);
12221cb0ef41Sopenharmony_ci    }
12231cb0ef41Sopenharmony_ci  } else if (IsAnyTagged(output_rep) &&
12241cb0ef41Sopenharmony_ci             use_info.truncation().IsUsedAsWord64() &&
12251cb0ef41Sopenharmony_ci             (use_info.type_check() == TypeCheckKind::kBigInt ||
12261cb0ef41Sopenharmony_ci              output_type.Is(Type::BigInt()))) {
12271cb0ef41Sopenharmony_ci    node = GetTaggedPointerRepresentationFor(node, output_rep, output_type,
12281cb0ef41Sopenharmony_ci                                             use_node, use_info);
12291cb0ef41Sopenharmony_ci    op = simplified()->TruncateBigIntToWord64();
12301cb0ef41Sopenharmony_ci  } else if (CanBeTaggedPointer(output_rep)) {
12311cb0ef41Sopenharmony_ci    if (output_type.Is(cache_->kDoubleRepresentableInt64)) {
12321cb0ef41Sopenharmony_ci      op = simplified()->ChangeTaggedToInt64();
12331cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kSigned64) {
12341cb0ef41Sopenharmony_ci      op = simplified()->CheckedTaggedToInt64(
12351cb0ef41Sopenharmony_ci          output_type.Maybe(Type::MinusZero())
12361cb0ef41Sopenharmony_ci              ? use_info.minus_zero_check()
12371cb0ef41Sopenharmony_ci              : CheckForMinusZeroMode::kDontCheckForMinusZero,
12381cb0ef41Sopenharmony_ci          use_info.feedback());
12391cb0ef41Sopenharmony_ci    } else if (use_info.type_check() == TypeCheckKind::kArrayIndex) {
12401cb0ef41Sopenharmony_ci      op = simplified()->CheckedTaggedToArrayIndex(use_info.feedback());
12411cb0ef41Sopenharmony_ci    } else {
12421cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
12431cb0ef41Sopenharmony_ci                       MachineRepresentation::kWord64);
12441cb0ef41Sopenharmony_ci    }
12451cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kWord64) {
12461cb0ef41Sopenharmony_ci    DCHECK_EQ(use_info.type_check(), TypeCheckKind::kBigInt);
12471cb0ef41Sopenharmony_ci    if (output_type.Is(Type::BigInt())) {
12481cb0ef41Sopenharmony_ci      return node;
12491cb0ef41Sopenharmony_ci    } else {
12501cb0ef41Sopenharmony_ci      Node* unreachable = InsertUnconditionalDeopt(
12511cb0ef41Sopenharmony_ci          use_node, DeoptimizeReason::kNotABigInt, use_info.feedback());
12521cb0ef41Sopenharmony_ci      return jsgraph()->graph()->NewNode(
12531cb0ef41Sopenharmony_ci          jsgraph()->common()->DeadValue(MachineRepresentation::kWord64),
12541cb0ef41Sopenharmony_ci          unreachable);
12551cb0ef41Sopenharmony_ci    }
12561cb0ef41Sopenharmony_ci  } else if (output_rep == MachineRepresentation::kSandboxedPointer) {
12571cb0ef41Sopenharmony_ci    if (output_type.Is(Type::SandboxedPointer())) {
12581cb0ef41Sopenharmony_ci      return node;
12591cb0ef41Sopenharmony_ci    } else {
12601cb0ef41Sopenharmony_ci      return TypeError(node, output_rep, output_type,
12611cb0ef41Sopenharmony_ci                       MachineRepresentation::kWord64);
12621cb0ef41Sopenharmony_ci    }
12631cb0ef41Sopenharmony_ci  } else {
12641cb0ef41Sopenharmony_ci    return TypeError(node, output_rep, output_type,
12651cb0ef41Sopenharmony_ci                     MachineRepresentation::kWord64);
12661cb0ef41Sopenharmony_ci  }
12671cb0ef41Sopenharmony_ci  return InsertConversion(node, op, use_node);
12681cb0ef41Sopenharmony_ci}
12691cb0ef41Sopenharmony_ci
12701cb0ef41Sopenharmony_ciconst Operator* RepresentationChanger::Int32OperatorFor(
12711cb0ef41Sopenharmony_ci    IrOpcode::Value opcode) {
12721cb0ef41Sopenharmony_ci  switch (opcode) {
12731cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberAdd:  // Fall through.
12741cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeSafeIntegerAdd:
12751cb0ef41Sopenharmony_ci    case IrOpcode::kNumberAdd:
12761cb0ef41Sopenharmony_ci      return machine()->Int32Add();
12771cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberSubtract:  // Fall through.
12781cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeSafeIntegerSubtract:
12791cb0ef41Sopenharmony_ci    case IrOpcode::kNumberSubtract:
12801cb0ef41Sopenharmony_ci      return machine()->Int32Sub();
12811cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberMultiply:
12821cb0ef41Sopenharmony_ci    case IrOpcode::kNumberMultiply:
12831cb0ef41Sopenharmony_ci      return machine()->Int32Mul();
12841cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberDivide:
12851cb0ef41Sopenharmony_ci    case IrOpcode::kNumberDivide:
12861cb0ef41Sopenharmony_ci      return machine()->Int32Div();
12871cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberModulus:
12881cb0ef41Sopenharmony_ci    case IrOpcode::kNumberModulus:
12891cb0ef41Sopenharmony_ci      return machine()->Int32Mod();
12901cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberBitwiseOr:  // Fall through.
12911cb0ef41Sopenharmony_ci    case IrOpcode::kNumberBitwiseOr:
12921cb0ef41Sopenharmony_ci      return machine()->Word32Or();
12931cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberBitwiseXor:  // Fall through.
12941cb0ef41Sopenharmony_ci    case IrOpcode::kNumberBitwiseXor:
12951cb0ef41Sopenharmony_ci      return machine()->Word32Xor();
12961cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberBitwiseAnd:  // Fall through.
12971cb0ef41Sopenharmony_ci    case IrOpcode::kNumberBitwiseAnd:
12981cb0ef41Sopenharmony_ci      return machine()->Word32And();
12991cb0ef41Sopenharmony_ci    case IrOpcode::kNumberEqual:
13001cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberEqual:
13011cb0ef41Sopenharmony_ci      return machine()->Word32Equal();
13021cb0ef41Sopenharmony_ci    case IrOpcode::kNumberLessThan:
13031cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberLessThan:
13041cb0ef41Sopenharmony_ci      return machine()->Int32LessThan();
13051cb0ef41Sopenharmony_ci    case IrOpcode::kNumberLessThanOrEqual:
13061cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberLessThanOrEqual:
13071cb0ef41Sopenharmony_ci      return machine()->Int32LessThanOrEqual();
13081cb0ef41Sopenharmony_ci    default:
13091cb0ef41Sopenharmony_ci      UNREACHABLE();
13101cb0ef41Sopenharmony_ci  }
13111cb0ef41Sopenharmony_ci}
13121cb0ef41Sopenharmony_ci
13131cb0ef41Sopenharmony_ciconst Operator* RepresentationChanger::Int32OverflowOperatorFor(
13141cb0ef41Sopenharmony_ci    IrOpcode::Value opcode) {
13151cb0ef41Sopenharmony_ci  switch (opcode) {
13161cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeSafeIntegerAdd:
13171cb0ef41Sopenharmony_ci      return simplified()->CheckedInt32Add();
13181cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeSafeIntegerSubtract:
13191cb0ef41Sopenharmony_ci      return simplified()->CheckedInt32Sub();
13201cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberDivide:
13211cb0ef41Sopenharmony_ci      return simplified()->CheckedInt32Div();
13221cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberModulus:
13231cb0ef41Sopenharmony_ci      return simplified()->CheckedInt32Mod();
13241cb0ef41Sopenharmony_ci    default:
13251cb0ef41Sopenharmony_ci      UNREACHABLE();
13261cb0ef41Sopenharmony_ci  }
13271cb0ef41Sopenharmony_ci}
13281cb0ef41Sopenharmony_ci
13291cb0ef41Sopenharmony_ciconst Operator* RepresentationChanger::Int64OperatorFor(
13301cb0ef41Sopenharmony_ci    IrOpcode::Value opcode) {
13311cb0ef41Sopenharmony_ci  switch (opcode) {
13321cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberAdd:  // Fall through.
13331cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeSafeIntegerAdd:
13341cb0ef41Sopenharmony_ci    case IrOpcode::kNumberAdd:
13351cb0ef41Sopenharmony_ci      return machine()->Int64Add();
13361cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberSubtract:  // Fall through.
13371cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeSafeIntegerSubtract:
13381cb0ef41Sopenharmony_ci    case IrOpcode::kNumberSubtract:
13391cb0ef41Sopenharmony_ci      return machine()->Int64Sub();
13401cb0ef41Sopenharmony_ci    default:
13411cb0ef41Sopenharmony_ci      UNREACHABLE();
13421cb0ef41Sopenharmony_ci  }
13431cb0ef41Sopenharmony_ci}
13441cb0ef41Sopenharmony_ci
13451cb0ef41Sopenharmony_ciconst Operator* RepresentationChanger::TaggedSignedOperatorFor(
13461cb0ef41Sopenharmony_ci    IrOpcode::Value opcode) {
13471cb0ef41Sopenharmony_ci  switch (opcode) {
13481cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberLessThan:
13491cb0ef41Sopenharmony_ci      return (COMPRESS_POINTERS_BOOL || machine()->Is32())
13501cb0ef41Sopenharmony_ci                 ? machine()->Int32LessThan()
13511cb0ef41Sopenharmony_ci                 : machine()->Int64LessThan();
13521cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberLessThanOrEqual:
13531cb0ef41Sopenharmony_ci      return (COMPRESS_POINTERS_BOOL || machine()->Is32())
13541cb0ef41Sopenharmony_ci                 ? machine()->Int32LessThanOrEqual()
13551cb0ef41Sopenharmony_ci                 : machine()->Int64LessThanOrEqual();
13561cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberEqual:
13571cb0ef41Sopenharmony_ci      return (COMPRESS_POINTERS_BOOL || machine()->Is32())
13581cb0ef41Sopenharmony_ci                 ? machine()->Word32Equal()
13591cb0ef41Sopenharmony_ci                 : machine()->Word64Equal();
13601cb0ef41Sopenharmony_ci    default:
13611cb0ef41Sopenharmony_ci      UNREACHABLE();
13621cb0ef41Sopenharmony_ci  }
13631cb0ef41Sopenharmony_ci}
13641cb0ef41Sopenharmony_ci
13651cb0ef41Sopenharmony_ciconst Operator* RepresentationChanger::Uint32OperatorFor(
13661cb0ef41Sopenharmony_ci    IrOpcode::Value opcode) {
13671cb0ef41Sopenharmony_ci  switch (opcode) {
13681cb0ef41Sopenharmony_ci    case IrOpcode::kNumberAdd:
13691cb0ef41Sopenharmony_ci      return machine()->Int32Add();
13701cb0ef41Sopenharmony_ci    case IrOpcode::kNumberSubtract:
13711cb0ef41Sopenharmony_ci      return machine()->Int32Sub();
13721cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberMultiply:
13731cb0ef41Sopenharmony_ci    case IrOpcode::kNumberMultiply:
13741cb0ef41Sopenharmony_ci      return machine()->Int32Mul();
13751cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberDivide:
13761cb0ef41Sopenharmony_ci    case IrOpcode::kNumberDivide:
13771cb0ef41Sopenharmony_ci      return machine()->Uint32Div();
13781cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberModulus:
13791cb0ef41Sopenharmony_ci    case IrOpcode::kNumberModulus:
13801cb0ef41Sopenharmony_ci      return machine()->Uint32Mod();
13811cb0ef41Sopenharmony_ci    case IrOpcode::kNumberEqual:
13821cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberEqual:
13831cb0ef41Sopenharmony_ci      return machine()->Word32Equal();
13841cb0ef41Sopenharmony_ci    case IrOpcode::kNumberLessThan:
13851cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberLessThan:
13861cb0ef41Sopenharmony_ci      return machine()->Uint32LessThan();
13871cb0ef41Sopenharmony_ci    case IrOpcode::kNumberLessThanOrEqual:
13881cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberLessThanOrEqual:
13891cb0ef41Sopenharmony_ci      return machine()->Uint32LessThanOrEqual();
13901cb0ef41Sopenharmony_ci    case IrOpcode::kNumberClz32:
13911cb0ef41Sopenharmony_ci      return machine()->Word32Clz();
13921cb0ef41Sopenharmony_ci    case IrOpcode::kNumberImul:
13931cb0ef41Sopenharmony_ci      return machine()->Int32Mul();
13941cb0ef41Sopenharmony_ci    default:
13951cb0ef41Sopenharmony_ci      UNREACHABLE();
13961cb0ef41Sopenharmony_ci  }
13971cb0ef41Sopenharmony_ci}
13981cb0ef41Sopenharmony_ci
13991cb0ef41Sopenharmony_ciconst Operator* RepresentationChanger::Uint32OverflowOperatorFor(
14001cb0ef41Sopenharmony_ci    IrOpcode::Value opcode) {
14011cb0ef41Sopenharmony_ci  switch (opcode) {
14021cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberDivide:
14031cb0ef41Sopenharmony_ci      return simplified()->CheckedUint32Div();
14041cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberModulus:
14051cb0ef41Sopenharmony_ci      return simplified()->CheckedUint32Mod();
14061cb0ef41Sopenharmony_ci    default:
14071cb0ef41Sopenharmony_ci      UNREACHABLE();
14081cb0ef41Sopenharmony_ci  }
14091cb0ef41Sopenharmony_ci}
14101cb0ef41Sopenharmony_ci
14111cb0ef41Sopenharmony_ciconst Operator* RepresentationChanger::Float64OperatorFor(
14121cb0ef41Sopenharmony_ci    IrOpcode::Value opcode) {
14131cb0ef41Sopenharmony_ci  switch (opcode) {
14141cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberAdd:
14151cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeSafeIntegerAdd:
14161cb0ef41Sopenharmony_ci    case IrOpcode::kNumberAdd:
14171cb0ef41Sopenharmony_ci      return machine()->Float64Add();
14181cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberSubtract:
14191cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeSafeIntegerSubtract:
14201cb0ef41Sopenharmony_ci    case IrOpcode::kNumberSubtract:
14211cb0ef41Sopenharmony_ci      return machine()->Float64Sub();
14221cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberMultiply:
14231cb0ef41Sopenharmony_ci    case IrOpcode::kNumberMultiply:
14241cb0ef41Sopenharmony_ci      return machine()->Float64Mul();
14251cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberDivide:
14261cb0ef41Sopenharmony_ci    case IrOpcode::kNumberDivide:
14271cb0ef41Sopenharmony_ci      return machine()->Float64Div();
14281cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberModulus:
14291cb0ef41Sopenharmony_ci    case IrOpcode::kNumberModulus:
14301cb0ef41Sopenharmony_ci      return machine()->Float64Mod();
14311cb0ef41Sopenharmony_ci    case IrOpcode::kNumberEqual:
14321cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberEqual:
14331cb0ef41Sopenharmony_ci      return machine()->Float64Equal();
14341cb0ef41Sopenharmony_ci    case IrOpcode::kNumberLessThan:
14351cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberLessThan:
14361cb0ef41Sopenharmony_ci      return machine()->Float64LessThan();
14371cb0ef41Sopenharmony_ci    case IrOpcode::kNumberLessThanOrEqual:
14381cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberLessThanOrEqual:
14391cb0ef41Sopenharmony_ci      return machine()->Float64LessThanOrEqual();
14401cb0ef41Sopenharmony_ci    case IrOpcode::kNumberAbs:
14411cb0ef41Sopenharmony_ci      return machine()->Float64Abs();
14421cb0ef41Sopenharmony_ci    case IrOpcode::kNumberAcos:
14431cb0ef41Sopenharmony_ci      return machine()->Float64Acos();
14441cb0ef41Sopenharmony_ci    case IrOpcode::kNumberAcosh:
14451cb0ef41Sopenharmony_ci      return machine()->Float64Acosh();
14461cb0ef41Sopenharmony_ci    case IrOpcode::kNumberAsin:
14471cb0ef41Sopenharmony_ci      return machine()->Float64Asin();
14481cb0ef41Sopenharmony_ci    case IrOpcode::kNumberAsinh:
14491cb0ef41Sopenharmony_ci      return machine()->Float64Asinh();
14501cb0ef41Sopenharmony_ci    case IrOpcode::kNumberAtan:
14511cb0ef41Sopenharmony_ci      return machine()->Float64Atan();
14521cb0ef41Sopenharmony_ci    case IrOpcode::kNumberAtanh:
14531cb0ef41Sopenharmony_ci      return machine()->Float64Atanh();
14541cb0ef41Sopenharmony_ci    case IrOpcode::kNumberAtan2:
14551cb0ef41Sopenharmony_ci      return machine()->Float64Atan2();
14561cb0ef41Sopenharmony_ci    case IrOpcode::kNumberCbrt:
14571cb0ef41Sopenharmony_ci      return machine()->Float64Cbrt();
14581cb0ef41Sopenharmony_ci    case IrOpcode::kNumberCeil:
14591cb0ef41Sopenharmony_ci      return machine()->Float64RoundUp().placeholder();
14601cb0ef41Sopenharmony_ci    case IrOpcode::kNumberCos:
14611cb0ef41Sopenharmony_ci      return machine()->Float64Cos();
14621cb0ef41Sopenharmony_ci    case IrOpcode::kNumberCosh:
14631cb0ef41Sopenharmony_ci      return machine()->Float64Cosh();
14641cb0ef41Sopenharmony_ci    case IrOpcode::kNumberExp:
14651cb0ef41Sopenharmony_ci      return machine()->Float64Exp();
14661cb0ef41Sopenharmony_ci    case IrOpcode::kNumberExpm1:
14671cb0ef41Sopenharmony_ci      return machine()->Float64Expm1();
14681cb0ef41Sopenharmony_ci    case IrOpcode::kNumberFloor:
14691cb0ef41Sopenharmony_ci      return machine()->Float64RoundDown().placeholder();
14701cb0ef41Sopenharmony_ci    case IrOpcode::kNumberFround:
14711cb0ef41Sopenharmony_ci      return machine()->TruncateFloat64ToFloat32();
14721cb0ef41Sopenharmony_ci    case IrOpcode::kNumberLog:
14731cb0ef41Sopenharmony_ci      return machine()->Float64Log();
14741cb0ef41Sopenharmony_ci    case IrOpcode::kNumberLog1p:
14751cb0ef41Sopenharmony_ci      return machine()->Float64Log1p();
14761cb0ef41Sopenharmony_ci    case IrOpcode::kNumberLog2:
14771cb0ef41Sopenharmony_ci      return machine()->Float64Log2();
14781cb0ef41Sopenharmony_ci    case IrOpcode::kNumberLog10:
14791cb0ef41Sopenharmony_ci      return machine()->Float64Log10();
14801cb0ef41Sopenharmony_ci    case IrOpcode::kNumberMax:
14811cb0ef41Sopenharmony_ci      return machine()->Float64Max();
14821cb0ef41Sopenharmony_ci    case IrOpcode::kNumberMin:
14831cb0ef41Sopenharmony_ci      return machine()->Float64Min();
14841cb0ef41Sopenharmony_ci    case IrOpcode::kSpeculativeNumberPow:
14851cb0ef41Sopenharmony_ci    case IrOpcode::kNumberPow:
14861cb0ef41Sopenharmony_ci      return machine()->Float64Pow();
14871cb0ef41Sopenharmony_ci    case IrOpcode::kNumberSin:
14881cb0ef41Sopenharmony_ci      return machine()->Float64Sin();
14891cb0ef41Sopenharmony_ci    case IrOpcode::kNumberSinh:
14901cb0ef41Sopenharmony_ci      return machine()->Float64Sinh();
14911cb0ef41Sopenharmony_ci    case IrOpcode::kNumberSqrt:
14921cb0ef41Sopenharmony_ci      return machine()->Float64Sqrt();
14931cb0ef41Sopenharmony_ci    case IrOpcode::kNumberTan:
14941cb0ef41Sopenharmony_ci      return machine()->Float64Tan();
14951cb0ef41Sopenharmony_ci    case IrOpcode::kNumberTanh:
14961cb0ef41Sopenharmony_ci      return machine()->Float64Tanh();
14971cb0ef41Sopenharmony_ci    case IrOpcode::kNumberTrunc:
14981cb0ef41Sopenharmony_ci      return machine()->Float64RoundTruncate().placeholder();
14991cb0ef41Sopenharmony_ci    case IrOpcode::kNumberSilenceNaN:
15001cb0ef41Sopenharmony_ci      return machine()->Float64SilenceNaN();
15011cb0ef41Sopenharmony_ci    default:
15021cb0ef41Sopenharmony_ci      UNREACHABLE();
15031cb0ef41Sopenharmony_ci  }
15041cb0ef41Sopenharmony_ci}
15051cb0ef41Sopenharmony_ci
15061cb0ef41Sopenharmony_ciNode* RepresentationChanger::TypeError(Node* node,
15071cb0ef41Sopenharmony_ci                                       MachineRepresentation output_rep,
15081cb0ef41Sopenharmony_ci                                       Type output_type,
15091cb0ef41Sopenharmony_ci                                       MachineRepresentation use) {
15101cb0ef41Sopenharmony_ci  type_error_ = true;
15111cb0ef41Sopenharmony_ci  if (!testing_type_errors_) {
15121cb0ef41Sopenharmony_ci    std::ostringstream out_str;
15131cb0ef41Sopenharmony_ci    out_str << output_rep << " (";
15141cb0ef41Sopenharmony_ci    output_type.PrintTo(out_str);
15151cb0ef41Sopenharmony_ci    out_str << ")";
15161cb0ef41Sopenharmony_ci
15171cb0ef41Sopenharmony_ci    std::ostringstream use_str;
15181cb0ef41Sopenharmony_ci    use_str << use;
15191cb0ef41Sopenharmony_ci
15201cb0ef41Sopenharmony_ci    FATAL(
15211cb0ef41Sopenharmony_ci        "RepresentationChangerError: node #%d:%s of "
15221cb0ef41Sopenharmony_ci        "%s cannot be changed to %s",
15231cb0ef41Sopenharmony_ci        node->id(), node->op()->mnemonic(), out_str.str().c_str(),
15241cb0ef41Sopenharmony_ci        use_str.str().c_str());
15251cb0ef41Sopenharmony_ci  }
15261cb0ef41Sopenharmony_ci  return node;
15271cb0ef41Sopenharmony_ci}
15281cb0ef41Sopenharmony_ci
15291cb0ef41Sopenharmony_ciNode* RepresentationChanger::InsertChangeBitToTagged(Node* node) {
15301cb0ef41Sopenharmony_ci  return jsgraph()->graph()->NewNode(simplified()->ChangeBitToTagged(), node);
15311cb0ef41Sopenharmony_ci}
15321cb0ef41Sopenharmony_ci
15331cb0ef41Sopenharmony_ciNode* RepresentationChanger::InsertChangeFloat32ToFloat64(Node* node) {
15341cb0ef41Sopenharmony_ci  return jsgraph()->graph()->NewNode(machine()->ChangeFloat32ToFloat64(), node);
15351cb0ef41Sopenharmony_ci}
15361cb0ef41Sopenharmony_ci
15371cb0ef41Sopenharmony_ciNode* RepresentationChanger::InsertChangeFloat64ToUint32(Node* node) {
15381cb0ef41Sopenharmony_ci  return jsgraph()->graph()->NewNode(machine()->ChangeFloat64ToUint32(), node);
15391cb0ef41Sopenharmony_ci}
15401cb0ef41Sopenharmony_ci
15411cb0ef41Sopenharmony_ciNode* RepresentationChanger::InsertChangeFloat64ToInt32(Node* node) {
15421cb0ef41Sopenharmony_ci  return jsgraph()->graph()->NewNode(machine()->ChangeFloat64ToInt32(), node);
15431cb0ef41Sopenharmony_ci}
15441cb0ef41Sopenharmony_ci
15451cb0ef41Sopenharmony_ciNode* RepresentationChanger::InsertChangeInt32ToFloat64(Node* node) {
15461cb0ef41Sopenharmony_ci  return jsgraph()->graph()->NewNode(machine()->ChangeInt32ToFloat64(), node);
15471cb0ef41Sopenharmony_ci}
15481cb0ef41Sopenharmony_ci
15491cb0ef41Sopenharmony_ciNode* RepresentationChanger::InsertChangeTaggedSignedToInt32(Node* node) {
15501cb0ef41Sopenharmony_ci  return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedSignedToInt32(),
15511cb0ef41Sopenharmony_ci                                     node);
15521cb0ef41Sopenharmony_ci}
15531cb0ef41Sopenharmony_ci
15541cb0ef41Sopenharmony_ciNode* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) {
15551cb0ef41Sopenharmony_ci  return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(),
15561cb0ef41Sopenharmony_ci                                     node);
15571cb0ef41Sopenharmony_ci}
15581cb0ef41Sopenharmony_ci
15591cb0ef41Sopenharmony_ciNode* RepresentationChanger::InsertChangeUint32ToFloat64(Node* node) {
15601cb0ef41Sopenharmony_ci  return jsgraph()->graph()->NewNode(machine()->ChangeUint32ToFloat64(), node);
15611cb0ef41Sopenharmony_ci}
15621cb0ef41Sopenharmony_ci
15631cb0ef41Sopenharmony_ciNode* RepresentationChanger::InsertTruncateInt64ToInt32(Node* node) {
15641cb0ef41Sopenharmony_ci  return jsgraph()->graph()->NewNode(machine()->TruncateInt64ToInt32(), node);
15651cb0ef41Sopenharmony_ci}
15661cb0ef41Sopenharmony_ci
15671cb0ef41Sopenharmony_ciNode* RepresentationChanger::InsertCheckedFloat64ToInt32(
15681cb0ef41Sopenharmony_ci    Node* node, CheckForMinusZeroMode check, const FeedbackSource& feedback,
15691cb0ef41Sopenharmony_ci    Node* use_node) {
15701cb0ef41Sopenharmony_ci  return InsertConversion(
15711cb0ef41Sopenharmony_ci      node, simplified()->CheckedFloat64ToInt32(check, feedback), use_node);
15721cb0ef41Sopenharmony_ci}
15731cb0ef41Sopenharmony_ci
15741cb0ef41Sopenharmony_ciNode* RepresentationChanger::InsertTypeOverrideForVerifier(const Type& type,
15751cb0ef41Sopenharmony_ci                                                           Node* node) {
15761cb0ef41Sopenharmony_ci  if (verification_enabled()) {
15771cb0ef41Sopenharmony_ci    DCHECK(!type.IsInvalid());
15781cb0ef41Sopenharmony_ci    node = jsgraph()->graph()->NewNode(
15791cb0ef41Sopenharmony_ci        jsgraph()->common()->SLVerifierHint(nullptr, type), node);
15801cb0ef41Sopenharmony_ci    verifier_->RecordHint(node);
15811cb0ef41Sopenharmony_ci  }
15821cb0ef41Sopenharmony_ci  return node;
15831cb0ef41Sopenharmony_ci}
15841cb0ef41Sopenharmony_ci
15851cb0ef41Sopenharmony_ciIsolate* RepresentationChanger::isolate() const { return broker_->isolate(); }
15861cb0ef41Sopenharmony_ci
15871cb0ef41Sopenharmony_ci}  // namespace compiler
15881cb0ef41Sopenharmony_ci}  // namespace internal
15891cb0ef41Sopenharmony_ci}  // namespace v8
1590