Reduce redundant doubleToInt32(i2f(x)) chains to simply x.
authorAndreas Gal <gal@mozilla.com>
Sun, 06 Jul 2008 17:32:21 -0700
changeset 17472 f6179396df600b85b1b6cda53ee18db24fa06576
parent 17471 0b810d0bf2e7572dbc69b66fce1c3a8b323560bf
child 17473 fdab515b3c8acd9f82177744961a47262e627aa9
push id1452
push usershaver@mozilla.com
push dateFri, 22 Aug 2008 00:08:22 +0000
treeherderautoland@d13bb0868596 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone1.9.1a1pre
Reduce redundant doubleToInt32(i2f(x)) chains to simply x.
js/src/jstracer.cpp
js/src/trace.js
--- a/js/src/jstracer.cpp
+++ b/js/src/jstracer.cpp
@@ -250,16 +250,19 @@ public:
             if (s0->isop(LIR_fadd) || s0->isop(LIR_fsub) || s0->isop(LIR_fmul)) {
                 LInsp lhs = s0->oprnd1();
                 LInsp rhs = s0->oprnd2();
                 if (isPromote(lhs) && isPromote(rhs)) {
                     LOpcode op = LOpcode(s0->opcode() & ~LIR64);
                     return out->ins2(op, demote(out, lhs), demote(out, rhs));
                 }
             }
+            if (s0->isop(LIR_i2f) || s0->isop(LIR_u2f)) {
+                return s0->oprnd1();
+            }
             break;
         case F_BoxDouble:
             LInsp s1 = args[1];
             if (s1->isop(LIR_i2f)) {
                 LInsp i = s1->oprnd1();
                 return out->insCall(F_BoxInt32, &i);
             }
             break;
@@ -666,18 +669,27 @@ TraceRecorder::guard(bool expected, LIns
     lir->insGuard(expected ? LIR_xf : LIR_xt,
                   cond,
                   snapshot());
 }
 
 bool
 TraceRecorder::checkType(jsval& v, int type)
 {
-    if (type == JSVAL_DOUBLE && isNumber(v))
+    /* we initially start all numbers out as JSVAL_DOUBLE so this can't be integer here */
+    JS_ASSERT(type != JSVAL_INT);
+    if (type == JSVAL_DOUBLE && isNumber(v)) {
+        /* lets see whether this is an integer value that we are propagating across the
+           loop */
+        LIns* i = get(&v);
+        if (i->isop(LIR_i2f)) {
+            printf("yes!\n");
+        }
         return true;
+    }
     return JSVAL_TAG(v) == (jsuint)type;
 }
 
 /* Make sure that all loop-carrying values have a stable type along the loop edge. */
 bool
 TraceRecorder::verifyTypeStability(JSStackFrame* fp, JSFrameRegs& regs, char* m)
 {
     if (fp != entryFrame)
--- a/js/src/trace.js
+++ b/js/src/trace.js
@@ -1,13 +1,15 @@
 f = function() {
 	var q = 1;
 	//for (var j = 0; j < 500; ++j)
-	for (var i = 0; i < 5000; ++i)
-		q += 2.5;
+	for (var i = 0; i < 5000; ++i) {
+		q += 2;
+		q += 2;
 		//++q;
+	}
 	print("q=" + q + " i=" + i);
 }
 
 var before = Date.now();
 f();
 var after = Date.now();
 print(after - before);