Reduce redundant doubleToInt32(i2f(x)) chains to simply x.
Reduce redundant doubleToInt32(i2f(x)) chains to simply x.
--- 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);