diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index f6fd291cf15e92b8f31d814435ebb2f2c2472a4b..78a49b5f538daf0fc19c29c52ec6fb9f850b12ba 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -1705,13 +1705,25 @@ Operand PandaGen::ToNamedPropertyKey(const ir::Expression *prop, bool isComputed Operand PandaGen::ToPropertyKey(const ir::Expression *prop, bool isComputed) { Operand op = ToNamedPropertyKey(prop, isComputed); - if (!std::holds_alternative(op)) { - ASSERT(std::holds_alternative(op) || std::holds_alternative(op)); + if (std::holds_alternative(op) || (std::holds_alternative(op) && + (std::get(op) <= util::Helpers::MAX_INT32))) { return op; } VReg propReg = AllocReg(); + /** + * Store index to vreg when index > MAX_INT32 to simplify ASM interpreter If byindex-related instructions support + * index > MAX_INT32, ASM interpreter will have to add a judgment whether index needs more than 32 bits which will + * cause inefficiency of it since cases when index > MAX_INT32 can be quite rare + **/ + if (std::holds_alternative(op) && (std::get(op) > util::Helpers::MAX_INT32)) { + LoadAccumulatorFloat(prop, std::get(op)); + StoreAccumulator(prop, propReg); + return propReg; + } + + ASSERT(std::holds_alternative(op)); prop->Compile(this); StoreAccumulator(prop, propReg); diff --git a/es2panda/util/helpers.h b/es2panda/util/helpers.h index 095e409ca34e2b30d61de36abc953676ed32d43c..a5dab4112a7c946c80ea5f44d12c08636a75423b 100644 --- a/es2panda/util/helpers.h +++ b/es2panda/util/helpers.h @@ -66,6 +66,7 @@ public: uint32_t index); static const uint32_t INVALID_INDEX = 4294967295L; + static const uint32_t MAX_INT32 = 2147483647; }; template