Ignore:
Timestamp:
Aug 28, 2015, 6:57:05 PM (10 years ago)
Author:
[email protected]
Message:

[JSC][x86] Improve the compare functions when comparing with zero
https://bugs.webkit.org/show_bug.cgi?id=148536

Patch by Benjamin Poulain <[email protected]> on 2015-08-28
Reviewed by Geoffrey Garen.

This patch has two parts:
1) The macro assembler gets an additional cmp->test optimization

for LessThan and GreaterThanOrEqual.
Instead of comparing the value with an immediate, test the value
with itself and use the flag.

2) Extend the DFG JIT optimization of compare.

In particular, use the same optimization in compileInt32Compare()
as we have in compilePeepHoleBooleanBranch().
The generator compileInt32Compare() is unfortunately very
common due to MoveHints placed between the Compare node and the Branch
node.

  • assembler/MacroAssembler.h:

(JSC::MacroAssembler::compare32):

  • assembler/MacroAssemblerX86Common.h:

(JSC::MacroAssemblerX86Common::branch32):
(JSC::MacroAssemblerX86Common::compare32):

  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::SpeculativeJIT::compilePeepHoleBooleanBranch):

  • dfg/DFGSpeculativeJIT64.cpp:

(JSC::DFG::SpeculativeJIT::compileInt32Compare):

File:
1 edited

Legend:

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

    r189130 r189136  
    11251125    Jump branch32(RelationalCondition cond, RegisterID left, TrustedImm32 right)
    11261126    {
    1127         if (((cond == Equal) || (cond == NotEqual)) && !right.m_value)
     1127        if (!right.m_value && (cond == Equal || cond == NotEqual || cond == LessThan || cond == GreaterThanOrEqual)) {
     1128            ResultCondition resultCondition;
     1129            switch (cond) {
     1130            case Equal:
     1131                resultCondition = Zero;
     1132                break;
     1133            case NotEqual:
     1134                resultCondition = NonZero;
     1135                break;
     1136            case LessThan:
     1137                resultCondition = Signed;
     1138                break;
     1139            case GreaterThanOrEqual:
     1140                resultCondition = PositiveOrZero;
     1141                break;
     1142            default:
     1143                RELEASE_ASSERT_NOT_REACHED();
     1144            }
    11281145            m_assembler.testl_rr(left, left);
    1129         else
    1130             m_assembler.cmpl_ir(right.m_value, left);
     1146            return Jump(m_assembler.jCC(x86Condition(resultCondition)));
     1147        }
     1148        m_assembler.cmpl_ir(right.m_value, left);
    11311149        return Jump(m_assembler.jCC(x86Condition(cond)));
    11321150    }
     
    14381456    void compare32(RelationalCondition cond, RegisterID left, TrustedImm32 right, RegisterID dest)
    14391457    {
    1440         if (((cond == Equal) || (cond == NotEqual)) && !right.m_value)
     1458        if (!right.m_value && (cond == Equal || cond == NotEqual || cond == LessThan || cond == GreaterThanOrEqual)) {
     1459            ResultCondition resultCondition;
     1460            switch (cond) {
     1461            case Equal:
     1462                resultCondition = Zero;
     1463                break;
     1464            case NotEqual:
     1465                resultCondition = NonZero;
     1466                break;
     1467            case LessThan:
     1468                resultCondition = Signed;
     1469                break;
     1470            case GreaterThanOrEqual:
     1471                resultCondition = PositiveOrZero;
     1472                break;
     1473            default:
     1474                RELEASE_ASSERT_NOT_REACHED();
     1475            }
    14411476            m_assembler.testl_rr(left, left);
    1442         else
    1443             m_assembler.cmpl_ir(right.m_value, left);
     1477            set32(x86Condition(resultCondition), dest);
     1478            return;
     1479        }
     1480        m_assembler.cmpl_ir(right.m_value, left);
    14441481        set32(x86Condition(cond), dest);
    14451482    }
Note: See TracChangeset for help on using the changeset viewer.