Bug 930437 - Remove unnecessary compilation aborts from Lowering::visitToInt32. r=bhackett
authorJan de Mooij <jdemooij@mozilla.com>
Sat, 26 Oct 2013 17:18:16 +0200
changeset 167110 85b01def9e0484720530b99c84d66d74a5413bb0
parent 167109 389dbd870f322e2ef8c899aa5e6652302c59039a
child 167111 e72e6e30170e4bd6f7d0e7d4b56de2b200eacbff
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbhackett
bugs930437
milestone27.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 930437 - Remove unnecessary compilation aborts from Lowering::visitToInt32. r=bhackett
js/src/jit/Lowering.cpp
js/src/jit/MIR.h
js/src/jit/TypePolicy.cpp
js/src/jit/TypePolicy.h
--- a/js/src/jit/Lowering.cpp
+++ b/js/src/jit/Lowering.cpp
@@ -1727,27 +1727,20 @@ LIRGenerator::visitToInt32(MToInt32 *con
 
       case MIRType_Double:
       {
         LDoubleToInt32 *lir = new LDoubleToInt32(useRegister(opd));
         return assignSnapshot(lir) && define(lir, convert);
       }
 
       case MIRType_String:
-        // Strings are complicated - we don't handle them yet.
-        IonSpew(IonSpew_Abort, "String to Int32 not supported yet.");
-        return false;
-
       case MIRType_Object:
-        // Objects might be effectful.
-        IonSpew(IonSpew_Abort, "Object to Int32 not supported yet.");
-        return false;
-
       case MIRType_Undefined:
-        IonSpew(IonSpew_Abort, "Undefined coerces to NaN, not int32_t.");
+        // Objects might be effectful. Undefined coerces to NaN, not int32.
+        MOZ_ASSUME_UNREACHABLE("ToInt32 invalid input type");
         return false;
 
       default:
         MOZ_ASSUME_UNREACHABLE("unexpected type");
     }
 }
 
 bool
--- a/js/src/jit/MIR.h
+++ b/js/src/jit/MIR.h
@@ -2914,17 +2914,19 @@ class MAsmJSUnsignedToFloat32
     }
 
     bool canProduceFloat32() const { return true; }
 };
 
 // Converts a primitive (either typed or untyped) to an int32. If the input is
 // not primitive at runtime, a bailout occurs. If the input cannot be converted
 // to an int32 without loss (i.e. "5.5" or undefined) then a bailout occurs.
-class MToInt32 : public MUnaryInstruction
+class MToInt32
+  : public MUnaryInstruction,
+    public ToInt32Policy
 {
     bool canBeNegativeZero_;
 
     MToInt32(MDefinition *def)
       : MUnaryInstruction(def),
         canBeNegativeZero_(true)
     {
         setResultType(MIRType_Int32);
@@ -2945,16 +2947,20 @@ class MToInt32 : public MUnaryInstructio
 
     bool canBeNegativeZero() {
         return canBeNegativeZero_;
     }
     void setCanBeNegativeZero(bool negativeZero) {
         canBeNegativeZero_ = negativeZero;
     }
 
+    TypePolicy *typePolicy() {
+        return this;
+    }
+
     bool congruentTo(MDefinition *ins) const {
         return congruentIfOperandsEqual(ins);
     }
 
     AliasSet getAliasSet() const {
         return AliasSet::None();
     }
     void computeRange();
--- a/js/src/jit/TypePolicy.cpp
+++ b/js/src/jit/TypePolicy.cpp
@@ -531,16 +531,37 @@ ToDoublePolicy::staticAdjustInputs(MInst
     if (in->type() != MIRType_Object && in->type() != MIRType_String)
         return true;
 
     in = boxAt(ins, in);
     ins->replaceOperand(0, in);
     return true;
 }
 
+bool
+ToInt32Policy::staticAdjustInputs(MInstruction *ins)
+{
+    JS_ASSERT(ins->isToInt32());
+
+    MDefinition *in = ins->getOperand(0);
+    switch (in->type()) {
+      case MIRType_Object:
+      case MIRType_String:
+      case MIRType_Undefined:
+        // Objects might be effectful. Undefined coerces to NaN, not int32.
+        in = boxAt(ins, in);
+        ins->replaceOperand(0, in);
+        break;
+      default:
+        break;
+    }
+
+    return true;
+}
+
 template <unsigned Op>
 bool
 ObjectPolicy<Op>::staticAdjustInputs(MInstruction *ins)
 {
     MDefinition *in = ins->getOperand(Op);
     if (in->type() == MIRType_Object || in->type() == MIRType_Slots ||
         in->type() == MIRType_Elements)
     {
--- a/js/src/jit/TypePolicy.h
+++ b/js/src/jit/TypePolicy.h
@@ -189,16 +189,26 @@ class ToDoublePolicy : public BoxInputsP
 {
   public:
     static bool staticAdjustInputs(MInstruction *def);
     bool adjustInputs(MInstruction *def) {
         return staticAdjustInputs(def);
     }
 };
 
+// Box objects, strings and undefined as input to a ToInt32 instruction.
+class ToInt32Policy : public BoxInputsPolicy
+{
+  public:
+    static bool staticAdjustInputs(MInstruction *def);
+    bool adjustInputs(MInstruction *def) {
+        return staticAdjustInputs(def);
+    }
+};
+
 template <unsigned Op>
 class ObjectPolicy : public BoxInputsPolicy
 {
   public:
     static bool staticAdjustInputs(MInstruction *ins);
     bool adjustInputs(MInstruction *ins) {
         return staticAdjustInputs(ins);
     }