Revision: 17652
Author:   [email protected]
Date:     Tue Nov 12 14:40:23 2013 UTC
Log:      Merged r17441 into 3.21 branch.

Fix uint32-to-smi conversion in Lithium

BUG=chromium:309623
[email protected]

Review URL: https://codereview.chromium.org/66783007
http://code.google.com/p/v8/source/detail?r=17652

Added:
 /branches/3.21/test/mjsunit/regress/regress-crbug-309623.js
Modified:
 /branches/3.21/src/arm/lithium-arm.cc
 /branches/3.21/src/arm/lithium-arm.h
 /branches/3.21/src/arm/lithium-codegen-arm.cc
 /branches/3.21/src/hydrogen-uint32-analysis.cc
 /branches/3.21/src/ia32/lithium-codegen-ia32.cc
 /branches/3.21/src/ia32/lithium-ia32.cc
 /branches/3.21/src/ia32/lithium-ia32.h
 /branches/3.21/src/version.cc
 /branches/3.21/src/x64/lithium-codegen-x64.cc
 /branches/3.21/src/x64/lithium-x64.cc
 /branches/3.21/src/x64/lithium-x64.h

=======================================
--- /dev/null
+++ /branches/3.21/test/mjsunit/regress/regress-crbug-309623.js Tue Nov 12 14:40:23 2013 UTC
@@ -0,0 +1,46 @@
+// Copyright 2013 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Flags: --allow-natives-syntax
+
+var u = new Uint32Array(2);
+u[0] = 1;
+u[1] = 0xEE6B2800;
+
+var a = [0, 1, 2];
+a[0] = 0;  // Kill the COW.
+assertTrue(%HasFastSmiElements(a));
+
+function foo(i) {
+  a[0] = u[i];
+  return a[0];
+}
+
+assertEquals(u[0], foo(0));
+assertEquals(u[0], foo(0));
+%OptimizeFunctionOnNextCall(foo);
+assertEquals(u[1], foo(1));
=======================================
--- /branches/3.21/src/arm/lithium-arm.cc       Wed Sep 18 15:29:06 2013 UTC
+++ /branches/3.21/src/arm/lithium-arm.cc       Tue Nov 12 14:40:23 2013 UTC
@@ -2006,8 +2006,9 @@
     } else if (to.IsSmi()) {
       HValue* val = instr->value();
       LOperand* value = UseRegister(val);
-      LInstruction* result =
-          DefineSameAsFirst(new(zone()) LInteger32ToSmi(value));
+      LInstruction* result = val->CheckFlag(HInstruction::kUint32)
+          ? DefineSameAsFirst(new(zone()) LUint32ToSmi(value))
+          : DefineSameAsFirst(new(zone()) LInteger32ToSmi(value));
       if (val->HasRange() && val->range()->IsInSmiRange()) {
         return result;
       }
=======================================
--- /branches/3.21/src/arm/lithium-arm.h        Wed Sep 18 15:29:06 2013 UTC
+++ /branches/3.21/src/arm/lithium-arm.h        Tue Nov 12 14:40:23 2013 UTC
@@ -185,6 +185,7 @@
   V(Typeof)                                     \
   V(TypeofIsAndBranch)                          \
   V(Uint32ToDouble)                             \
+  V(Uint32ToSmi)                                \
   V(UnknownOSRValue)                            \
   V(ValueOf)                                    \
   V(WrapReceiver)
@@ -2031,6 +2032,19 @@
 };


+class LUint32ToSmi V8_FINAL : public LTemplateInstruction<1, 1, 0> {
+ public:
+  explicit LUint32ToSmi(LOperand* value) {
+    inputs_[0] = value;
+  }
+
+  LOperand* value() { return inputs_[0]; }
+
+  DECLARE_CONCRETE_INSTRUCTION(Uint32ToSmi, "uint32-to-smi")
+  DECLARE_HYDROGEN_ACCESSOR(Change)
+};
+
+
 class LNumberTagI V8_FINAL : public LTemplateInstruction<1, 1, 0> {
  public:
   explicit LNumberTagI(LOperand* value) {
=======================================
--- /branches/3.21/src/arm/lithium-codegen-arm.cc Wed Sep 18 15:29:06 2013 UTC +++ /branches/3.21/src/arm/lithium-codegen-arm.cc Tue Nov 12 14:40:23 2013 UTC
@@ -4649,9 +4649,7 @@

 void LCodeGen::DoInteger32ToSmi(LInteger32ToSmi* instr) {
   LOperand* input = instr->value();
-  ASSERT(input->IsRegister());
   LOperand* output = instr->result();
-  ASSERT(output->IsRegister());
   __ SmiTag(ToRegister(output), ToRegister(input), SetCC);
   if (!instr->hydrogen()->value()->HasRange() ||
       !instr->hydrogen()->value()->range()->IsInSmiRange()) {
@@ -4668,6 +4666,18 @@
   __ vmov(flt_scratch, ToRegister(input));
   __ vcvt_f64_u32(ToDoubleRegister(output), flt_scratch);
 }
+
+
+void LCodeGen::DoUint32ToSmi(LUint32ToSmi* instr) {
+  LOperand* input = instr->value();
+  LOperand* output = instr->result();
+  if (!instr->hydrogen()->value()->HasRange() ||
+      !instr->hydrogen()->value()->range()->IsInSmiRange()) {
+    __ tst(ToRegister(input), Operand(0xc0000000));
+    DeoptimizeIf(ne, instr->environment());
+  }
+  __ SmiTag(ToRegister(output), ToRegister(input));
+}


 void LCodeGen::DoNumberTagI(LNumberTagI* instr) {
=======================================
--- /branches/3.21/src/hydrogen-uint32-analysis.cc Tue Aug 13 17:09:37 2013 UTC +++ /branches/3.21/src/hydrogen-uint32-analysis.cc Tue Nov 12 14:40:23 2013 UTC
@@ -35,8 +35,17 @@
   // Operations that operate on bits are safe.
   if (use->IsBitwise() || use->IsShl() || use->IsSar() || use->IsShr()) {
     return true;
-  } else if (use->IsChange() || use->IsSimulate()) {
-    // Conversions and deoptimization have special support for unt32.
+  } else if (use->IsSimulate()) {
+    // Deoptimization has special support for uint32.
+    return true;
+  } else if (use->IsChange()) {
+    // Conversions have special support for uint32.
+    // This ASSERT guards that the conversion in question is actually
+    // implemented. Do not extend the whitelist without adding
+    // support to LChunkBuilder::DoChange().
+    ASSERT(HChange::cast(use)->to().IsDouble() ||
+           HChange::cast(use)->to().IsSmi() ||
+           HChange::cast(use)->to().IsTagged());
     return true;
   } else if (use->IsStoreKeyed()) {
     HStoreKeyed* store = HStoreKeyed::cast(use);
=======================================
--- /branches/3.21/src/ia32/lithium-codegen-ia32.cc Wed Sep 18 15:29:06 2013 UTC +++ /branches/3.21/src/ia32/lithium-codegen-ia32.cc Tue Nov 12 14:40:23 2013 UTC
@@ -5010,6 +5010,17 @@
                 ToRegister(input),
                 ToDoubleRegister(temp));
 }
+
+
+void LCodeGen::DoUint32ToSmi(LUint32ToSmi* instr) {
+  Register input = ToRegister(instr->value());
+  if (!instr->hydrogen()->value()->HasRange() ||
+      !instr->hydrogen()->value()->range()->IsInSmiRange()) {
+    __ test(input, Immediate(0xc0000000));
+    DeoptimizeIf(not_zero, instr->environment());
+  }
+  __ SmiTag(input);
+}


 void LCodeGen::DoNumberTagI(LNumberTagI* instr) {
=======================================
--- /branches/3.21/src/ia32/lithium-ia32.cc     Wed Sep 18 15:29:06 2013 UTC
+++ /branches/3.21/src/ia32/lithium-ia32.cc     Tue Nov 12 14:40:23 2013 UTC
@@ -2015,8 +2015,9 @@
     } else if (to.IsSmi()) {
       HValue* val = instr->value();
       LOperand* value = UseRegister(val);
-      LInstruction* result =
-          DefineSameAsFirst(new(zone()) LInteger32ToSmi(value));
+      LInstruction* result = val->CheckFlag(HInstruction::kUint32)
+           ? DefineSameAsFirst(new(zone()) LUint32ToSmi(value))
+           : DefineSameAsFirst(new(zone()) LInteger32ToSmi(value));
       if (val->HasRange() && val->range()->IsInSmiRange()) {
         return result;
       }
=======================================
--- /branches/3.21/src/ia32/lithium-ia32.h      Wed Sep 18 15:29:06 2013 UTC
+++ /branches/3.21/src/ia32/lithium-ia32.h      Tue Nov 12 14:40:23 2013 UTC
@@ -184,6 +184,7 @@
   V(Typeof)                                     \
   V(TypeofIsAndBranch)                          \
   V(Uint32ToDouble)                             \
+  V(Uint32ToSmi)                                \
   V(UnknownOSRValue)                            \
   V(ValueOf)                                    \
   V(WrapReceiver)
@@ -2105,6 +2106,19 @@
 };


+class LUint32ToSmi V8_FINAL : public LTemplateInstruction<1, 1, 0> {
+ public:
+  explicit LUint32ToSmi(LOperand* value) {
+    inputs_[0] = value;
+  }
+
+  LOperand* value() { return inputs_[0]; }
+
+  DECLARE_CONCRETE_INSTRUCTION(Uint32ToSmi, "uint32-to-smi")
+  DECLARE_HYDROGEN_ACCESSOR(Change)
+};
+
+
 class LNumberTagI V8_FINAL : public LTemplateInstruction<1, 1, 0> {
  public:
   explicit LNumberTagI(LOperand* value) {
=======================================
--- /branches/3.21/src/version.cc       Tue Nov 12 14:33:19 2013 UTC
+++ /branches/3.21/src/version.cc       Tue Nov 12 14:40:23 2013 UTC
@@ -35,7 +35,7 @@
 #define MAJOR_VERSION     3
 #define MINOR_VERSION     21
 #define BUILD_NUMBER      18
-#define PATCH_LEVEL       5
+#define PATCH_LEVEL       6
 // Use 1 for candidates and 0 otherwise.
 // (Boolean macro values are not supported by all preprocessors.)
 #define IS_CANDIDATE_VERSION 0
=======================================
--- /branches/3.21/src/x64/lithium-codegen-x64.cc Wed Sep 18 15:29:06 2013 UTC +++ /branches/3.21/src/x64/lithium-codegen-x64.cc Tue Nov 12 14:40:23 2013 UTC
@@ -4477,6 +4477,22 @@
                 ToRegister(input),
                 ToDoubleRegister(temp));
 }
+
+
+void LCodeGen::DoUint32ToSmi(LUint32ToSmi* instr) {
+  LOperand* input = instr->value();
+  ASSERT(input->IsRegister());
+  LOperand* output = instr->result();
+  if (!instr->hydrogen()->value()->HasRange() ||
+      !instr->hydrogen()->value()->range()->IsInSmiRange() ||
+      instr->hydrogen()->value()->range()->upper() == kMaxInt) {
+ // The Range class can't express upper bounds in the (kMaxInt, kMaxUint32] + // interval, so we treat kMaxInt as a sentinel for this entire interval.
+    __ testl(ToRegister(input), Immediate(0x80000000));
+    DeoptimizeIf(not_zero, instr->environment());
+  }
+  __ Integer32ToSmi(ToRegister(output), ToRegister(input));
+}


 void LCodeGen::DoNumberTagI(LNumberTagI* instr) {
=======================================
--- /branches/3.21/src/x64/lithium-x64.cc       Wed Sep 18 15:29:06 2013 UTC
+++ /branches/3.21/src/x64/lithium-x64.cc       Tue Nov 12 14:40:23 2013 UTC
@@ -1899,10 +1899,18 @@
     } else if (to.IsSmi()) {
       HValue* val = instr->value();
       LOperand* value = UseRegister(val);
-      LInstruction* result =
-          DefineAsRegister(new(zone()) LInteger32ToSmi(value));
-      if (val->HasRange() && val->range()->IsInSmiRange()) {
-        return result;
+      LInstruction* result = NULL;
+      if (val->CheckFlag(HInstruction::kUint32)) {
+        result = DefineAsRegister(new(zone()) LUint32ToSmi(value));
+        if (val->HasRange() && val->range()->IsInSmiRange() &&
+            val->range()->upper() != kMaxInt) {
+          return result;
+        }
+      } else {
+        result = DefineAsRegister(new(zone()) LInteger32ToSmi(value));
+        if (val->HasRange() && val->range()->IsInSmiRange()) {
+          return result;
+        }
       }
       return AssignEnvironment(result);
     } else {
=======================================
--- /branches/3.21/src/x64/lithium-x64.h        Wed Sep 18 15:29:06 2013 UTC
+++ /branches/3.21/src/x64/lithium-x64.h        Tue Nov 12 14:40:23 2013 UTC
@@ -182,6 +182,7 @@
   V(Typeof)                                     \
   V(TypeofIsAndBranch)                          \
   V(Uint32ToDouble)                             \
+  V(Uint32ToSmi)                                \
   V(UnknownOSRValue)                            \
   V(ValueOf)                                    \
   V(WrapReceiver)
@@ -1967,6 +1968,19 @@
 };


+class LUint32ToSmi V8_FINAL : public LTemplateInstruction<1, 1, 0> {
+ public:
+  explicit LUint32ToSmi(LOperand* value) {
+    inputs_[0] = value;
+  }
+
+  LOperand* value() { return inputs_[0]; }
+
+  DECLARE_CONCRETE_INSTRUCTION(Uint32ToSmi, "uint32-to-smi")
+  DECLARE_HYDROGEN_ACCESSOR(Change)
+};
+
+
 class LNumberTagI V8_FINAL : public LTemplateInstruction<1, 1, 0> {
  public:
   explicit LNumberTagI(LOperand* value) {

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to