Bug 1640504 - Optimize ToObject and ToInteger. r=iain
authorTom Schuster <evilpies@gmail.com>
Mon, 25 May 2020 10:55:00 +0000
changeset 531876 236469cc9c95f89e00b16cefb6e03357219d4715
parent 531875 4d0a8420647e268146af6e7e21b6572f1257443b
child 531877 cbee2377997906cdb93ccb13b0bd99c568bb881c
push id37447
push usernbeleuzu@mozilla.com
push dateMon, 25 May 2020 15:42:48 +0000
treeherdermozilla-central@e7641c1071ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersiain
bugs1640504
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1640504 - Optimize ToObject and ToInteger. r=iain Differential Revision: https://phabricator.services.mozilla.com/D76624
js/src/jit/CacheIR.cpp
js/src/jit/CacheIR.h
--- a/js/src/jit/CacheIR.cpp
+++ b/js/src/jit/CacheIR.cpp
@@ -5056,16 +5056,75 @@ AttachDecision CallIRGenerator::tryAttac
   // returns a string.
   writer.returnFromIC();
   cacheIRStubKind_ = BaselineCacheIRStubKind::Regular;
 
   trackAttached("ToString");
   return AttachDecision::Attach;
 }
 
+AttachDecision CallIRGenerator::tryAttachToObject(HandleFunction callee) {
+  // Need a single object argument.
+  // TODO(Warp): Support all or more conversions to object.
+  if (argc_ != 1 || !args_[0].isObject()) {
+    return AttachDecision::NoAction;
+  }
+
+  // Initialize the input operand.
+  Int32OperandId argcId(writer.setInputOperandId(0));
+
+  // Guard callee is the 'ToObject' intrinsic native function.
+  emitNativeCalleeGuard(callee);
+
+  // Guard that the argument is an object.
+  ValOperandId argId = writer.loadArgumentFixedSlot(ArgumentKind::Arg0, argc_);
+  ObjOperandId objId = writer.guardToObject(argId);
+
+  // Return the object.
+  writer.loadObjectResult(objId);
+
+  // Monitor the returned object.
+  writer.typeMonitorResult();
+  cacheIRStubKind_ = BaselineCacheIRStubKind::Monitored;
+
+  trackAttached("ToObject");
+  return AttachDecision::Attach;
+}
+
+AttachDecision CallIRGenerator::tryAttachToInteger(HandleFunction callee) {
+  // Need a single int32 argument.
+  // TODO(Warp): Support all or more conversions to integer.
+  // Make sure to update this code correctly if we ever start
+  // returning non-int32 integers.
+  if (argc_ != 1 || !args_[0].isInt32()) {
+    return AttachDecision::NoAction;
+  }
+
+  // Initialize the input operand.
+  Int32OperandId argcId(writer.setInputOperandId(0));
+
+  // Guard callee is the 'ToInteger' intrinsic native function.
+  emitNativeCalleeGuard(callee);
+
+  // Guard that the argument is an int32.
+  ValOperandId argId = writer.loadArgumentFixedSlot(ArgumentKind::Arg0, argc_);
+  Int32OperandId int32Id = writer.guardToInt32(argId);
+
+  // Return the int32.
+  writer.loadInt32Result(int32Id);
+
+  // This stub does not need to be monitored, because it always
+  // returns an int32.
+  writer.returnFromIC();
+  cacheIRStubKind_ = BaselineCacheIRStubKind::Regular;
+
+  trackAttached("ToInteger");
+  return AttachDecision::Attach;
+}
+
 AttachDecision CallIRGenerator::tryAttachStringChar(HandleFunction callee,
                                                     StringChar kind) {
   // Need one argument.
   if (argc_ != 1) {
     return AttachDecision::NoAction;
   }
 
   if (!CanAttachStringChar(thisval_, args_[0], kind)) {
@@ -5472,16 +5531,20 @@ AttachDecision CallIRGenerator::tryAttac
     case InlinableNative::ArrayJoin:
       return tryAttachArrayJoin(callee);
 
     // Intrinsics.
     case InlinableNative::IntrinsicIsSuspendedGenerator:
       return tryAttachIsSuspendedGenerator(callee);
     case InlinableNative::IntrinsicToString:
       return tryAttachToString(callee);
+    case InlinableNative::IntrinsicToObject:
+      return tryAttachToObject(callee);
+    case InlinableNative::IntrinsicToInteger:
+      return tryAttachToInteger(callee);
 
     // String natives.
     case InlinableNative::StringCharCodeAt:
       return tryAttachStringCharCodeAt(callee);
     case InlinableNative::StringCharAt:
       return tryAttachStringCharAt(callee);
 
     // Math natives.
--- a/js/src/jit/CacheIR.h
+++ b/js/src/jit/CacheIR.h
@@ -1509,16 +1509,18 @@ class MOZ_RAII CallIRGenerator : public 
                                   MutableHandleObject result);
 
   void emitNativeCalleeGuard(HandleFunction callee);
 
   AttachDecision tryAttachArrayPush(HandleFunction callee);
   AttachDecision tryAttachArrayJoin(HandleFunction callee);
   AttachDecision tryAttachIsSuspendedGenerator(HandleFunction callee);
   AttachDecision tryAttachToString(HandleFunction callee);
+  AttachDecision tryAttachToObject(HandleFunction callee);
+  AttachDecision tryAttachToInteger(HandleFunction callee);
   AttachDecision tryAttachStringChar(HandleFunction callee, StringChar kind);
   AttachDecision tryAttachStringCharCodeAt(HandleFunction callee);
   AttachDecision tryAttachStringCharAt(HandleFunction callee);
   AttachDecision tryAttachMathAbs(HandleFunction callee);
   AttachDecision tryAttachMathFloor(HandleFunction callee);
   AttachDecision tryAttachMathCeil(HandleFunction callee);
   AttachDecision tryAttachMathRound(HandleFunction callee);
   AttachDecision tryAttachMathSqrt(HandleFunction callee);