Changeset 37417 in webkit for trunk/JavaScriptCore/VM/Machine.cpp


Ignore:
Timestamp:
Oct 8, 2008, 3:53:13 AM (17 years ago)
Author:
[email protected]
Message:

2008-10-08 Maciej Stachowiak <[email protected]>

Reviewed by Oliver Hunt.

Re-landing the following fix with the crashing bug in it fixed (r37405):


  • optimize away multiplication by constant 1.0


2.3% speedup on v8 RayTrace benchmark

Apparently it's not uncommon for JavaScript code to multiply by
constant 1.0 in the mistaken belief that this converts integer to
floating point and that there is any operational difference.

  • VM/CTI.cpp: (JSC::CTI::privateCompileMainPass): Optimize to_jsnumber for case where parameter is already number. (JSC::CTI::privateCompileSlowCases): ditto
  • VM/Machine.cpp: (JSC::Machine::privateExecute): ditto
  • kjs/grammar.y: (makeMultNode): Transform as follows: +FOO * BAR ==> FOO * BAR FOO * +BAR ==> FOO * BAR FOO * 1 ==> +FOO 1 * FOO ==> +FOO (makeDivNode): Transform as follows: +FOO / BAR ==> FOO / BAR FOO / +BAR ==> FOO / BAR (makeSubNode): Transform as follows: +FOO - BAR ==> FOO - BAR FOO - +BAR ==> FOO - BAR
  • kjs/nodes.h: (JSC::ExpressionNode::stripUnaryPlus): Helper for above grammar.y changes (JSC::UnaryPlusNode::stripUnaryPlus): ditto
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/VM/Machine.cpp

    r37408 r37417  
    18161816        int dst = (++vPC)->u.operand;
    18171817        int src = (++vPC)->u.operand;
    1818         JSValue* result = r[src].jsValue(exec)->toJSNumber(exec);
    1819         VM_CHECK_EXCEPTION();
    1820 
    1821         r[dst] = result;
     1818
     1819        JSValue* srcVal = r[src].jsValue(exec);
     1820
     1821        if (LIKELY(JSImmediate::isNumber(srcVal) || static_cast<JSCell*>(srcVal)->structureID()->typeInfo().type() == NumberType)) {
     1822            r[dst] = r[src];
     1823        } else {
     1824            JSValue* result = srcVal->toJSNumber(exec);
     1825            VM_CHECK_EXCEPTION();
     1826            r[dst] = result;
     1827        }
    18221828
    18231829        ++vPC;
Note: See TracChangeset for help on using the changeset viewer.