Ignore:
Timestamp:
Apr 20, 2011, 1:47:53 PM (14 years ago)
Author:
[email protected]
Message:

Bug 59022 - DFG JIT - Optimize branch-on-relational-compare

Reviewed by Oliver Hunt.

If a relational compare (< or <=) is immediately followed by a branch,
we can combine the two, avoiding generation of a boolean into a register.

  • assembler/MacroAssemblerX86Common.h:

(JSC::MacroAssemblerX86Common::branch32):
(JSC::MacroAssemblerX86Common::invert):
(JSC::MacroAssemblerX86Common::commute):

  • dfg/DFGNode.h:

(JSC::DFG::Node::adjustedRefCount):

  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::SpeculativeJIT::compilePeepHoleBranch):
(JSC::DFG::SpeculativeJIT::compile):

  • dfg/DFGSpeculativeJIT.h:

(JSC::DFG::SpeculativeJIT::isJSConstantWithInt32Value):
(JSC::DFG::SpeculativeJIT::detectPeepHoleBranch):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/assembler/MacroAssemblerX86Common.h

    r84399 r84413  
    819819    }
    820820   
     821    Jump branch32(RelationalCondition cond, TrustedImm32 left, RegisterID right)
     822    {
     823        if (((cond == Equal) || (cond == NotEqual)) && !left.m_value)
     824            m_assembler.testl_rr(right, right);
     825        else
     826            m_assembler.cmpl_ir(left.m_value, right);
     827        return Jump(m_assembler.jCC(x86Condition(commute(cond))));
     828    }
     829   
    821830    Jump branch32(RelationalCondition cond, RegisterID left, Address right)
    822831    {
     
    11591168        m_assembler.setCC_r(x86Condition(cond), dest);
    11601169        m_assembler.movzbl_rr(dest, dest);
     1170    }
     1171
     1172    // Invert a relational condition, e.g. == becomes !=, < becomes >=, etc.
     1173    static RelationalCondition invert(RelationalCondition cond)
     1174    {
     1175        return static_cast<RelationalCondition>(cond ^ 1);
     1176    }
     1177
     1178    // Commute a relational condition, returns a new condition that will produce
     1179    // the same results given the same inputs but with their positions exchanged.
     1180    static RelationalCondition commute(RelationalCondition cond)
     1181    {
     1182        // Equality is commutative!
     1183        if (cond == Equal || cond == NotEqual)
     1184            return cond;
     1185
     1186        // Based on the values of x86 condition codes, remap > with < and >= with <=
     1187        if (cond >= LessThan) {
     1188            ASSERT(cond == LessThan || cond == LessThanOrEqual || cond == GreaterThan || cond == GreaterThanOrEqual);
     1189            return static_cast<RelationalCondition>(X86Assembler::ConditionL + X86Assembler::ConditionG - cond);
     1190        }
     1191
     1192        // As above, for unsigned conditions.
     1193        ASSERT(cond == Below || cond == BelowOrEqual || cond == Above || cond == AboveOrEqual);
     1194        return static_cast<RelationalCondition>(X86Assembler::ConditionB + X86Assembler::ConditionA - cond);
    11611195    }
    11621196
Note: See TracChangeset for help on using the changeset viewer.