Ignore:
Timestamp:
Aug 12, 2008, 8:17:19 PM (17 years ago)
Author:
[email protected]
Message:

Add peephole optimisation to 'op_not... jfalse...' (eg. if(!...) )

Reviewed by Geoff Garen

This is a very slight win in sunspider, and a fairly substantial win
in hot code that does if(!...), etc.

File:
1 edited

Legend:

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

    r35651 r35703  
    434434}
    435435
     436void CodeGenerator::retrieveLastUnaryOp(int& dstIndex, int& srcIndex)
     437{
     438    ASSERT(instructions().size() >= 3);
     439    size_t size = instructions().size();
     440    dstIndex = instructions().at(size - 2).u.operand;
     441    srcIndex = instructions().at(size - 1).u.operand;
     442}
     443
    436444void ALWAYS_INLINE CodeGenerator::rewindBinaryOp()
    437445{
    438446    ASSERT(instructions().size() >= 4);
    439447    instructions().shrink(instructions().size() - 4);
     448}
     449
     450void ALWAYS_INLINE CodeGenerator::rewindUnaryOp()
     451{
     452    ASSERT(instructions().size() >= 3);
     453    instructions().shrink(instructions().size() - 3);
    440454}
    441455
     
    491505            return target;
    492506        }
     507    } else if (m_lastOpcodeID == op_not) {
     508        int dstIndex;
     509        int srcIndex;
     510
     511        retrieveLastUnaryOp(dstIndex, srcIndex);
     512
     513        if (cond->index() == dstIndex && cond->isTemporary() && !cond->refCount()) {
     514            rewindUnaryOp();
     515            emitOpcode(target->isForwardLabel() ? op_jtrue : op_loop_if_true);
     516            instructions().append(srcIndex);
     517            instructions().append(target->offsetFrom(instructions().size()));
     518            return target;
     519        }       
    493520    }
    494521
Note: See TracChangeset for help on using the changeset viewer.