Don't fold MMod when it could change its result type (bug 725061, r=jandem).
authorDavid Anderson <danderson@mozilla.com>
Thu, 09 Feb 2012 12:04:42 -0800
changeset 112678 fa22733dd172711de4d3bd644105d1ebec1073b3
parent 112677 28c66941856b4e3dd262a13503fa94da669aed90
child 112679 902e1b6364c4742a786e4d9f282e6f80d7119628
push id239
push userakeybl@mozilla.com
push dateThu, 03 Jan 2013 21:54:43 +0000
treeherdermozilla-release@3a7b66445659 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs725061
milestone13.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
Don't fold MMod when it could change its result type (bug 725061, r=jandem).
js/src/ion/MIR.cpp
js/src/jit-test/tests/ion/bug725061.js
--- a/js/src/ion/MIR.cpp
+++ b/js/src/ion/MIR.cpp
@@ -555,16 +555,24 @@ MDiv::foldsTo(bool useValueNumbers)
     // 0 / x -> 0
     // x / 1 -> x
     if (IsConstant(lhs(), 0) || IsConstant(rhs(), 1))
         return lhs();
 
     return this;
 }
 
+static inline MDefinition *
+TryFold(MDefinition *original, MDefinition *replacement)
+{
+    if (original->type() == replacement->type())
+        return replacement;
+    return original;
+}
+
 MDefinition *
 MMod::foldsTo(bool useValueNumbers)
 {
     if (specialization_ == MIRType_None)
         return this;
 
     if (MDefinition *folded = EvaluateConstantOperands(this))
         return folded;
@@ -584,32 +592,32 @@ MMod::foldsTo(bool useValueNumbers)
     if (lhsConstant && lhsd == NaN)
         return lhs();
 
     // x % NaN -> NaN
     if (rhsConstant && rhsd == NaN)
         return rhs();
 
     // x % y -> NaN (where y == 0 || y == -0)
-    if (rhsConstant && (rhsd == 0 || rhsd == -0))
-        return MConstant::New(rt->NaNValue);
+    if (rhsConstant && (rhsd == 0))
+        return TryFold(this, MConstant::New(rt->NaNValue));
 
     // NOTE: y cannot be NaN, 0, or -0 at this point
     // x % y -> x (where x == 0 || x == -0)
-    if (lhsConstant && (lhsd == 0 || lhsd == -0))
-        return lhs();
+    if (lhsConstant && (lhsd == 0))
+        return TryFold(this, lhs());
 
     // x % y -> NaN (where x == Inf || x == -Inf)
     if (lhsConstant && (lhsd == Inf || lhsd == -Inf))
-        return MConstant::New(rt->NaNValue);
+        return TryFold(this, MConstant::New(rt->NaNValue));
 
     // NOTE: y cannot be NaN, Inf, or -Inf at this point
     // x % y -> x (where y == Inf || y == -Inf)
     if (rhsConstant && (rhsd == Inf || rhsd == -Inf))
-        return lhs();
+        return TryFold(this, lhs());
 
     return this;
 }
 
 MDefinition *
 MMul::foldsTo(bool useValueNumbers)
 {
     MDefinition *out = MBinaryArithInstruction::foldsTo(useValueNumbers);
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/ion/bug725061.js
@@ -0,0 +1,12 @@
+function testInt(n, result) {
+    var x = 0;
+    for (var i = 0; i < 15; i++) {
+        if (x % 2 == 0)
+            x = 10;
+        else
+            x %=  0;
+    }
+    for (var i = 0; i < 15; i++) {    }
+}
+testInt(2147483647, 2147483647);
+testInt(-2147483648, -2147483648);