Ignore:
Timestamp:
Aug 16, 2015, 1:13:50 AM (10 years ago)
Author:
[email protected]
Message:

[JSC] Use (x + x) instead of (x * 2) when possible
https://bugs.webkit.org/show_bug.cgi?id=148051

Patch by Benjamin Poulain <[email protected]> on 2015-08-16
Reviewed by Michael Saboff.

When multiplying a number by 2, JSC was loading a constant "2"
in register and multiplying it with the first number:

mov $0x4000000000000000, %rcx
movd %rcx, %xmm0
mulsd %xmm0, %xmm1

This is a problem for a few reasons.
1) "movd %rcx, %xmm0" only set half of XMM0. This instruction

has to wait for any preceding instruction on XMM0 to finish
before executing.

2) The load and transform itself is large and unecessary.

To fix that, I added a StrengthReductionPhase to transform
multiplications by 2 into a addition.

Unfortunately, that turned the code into:

movsd %xmm0 %xmm1
mulsd %xmm1 %xmm0

The reason is GenerationInfo::canReuse() was not accounting
for nodes using other nodes multiple times.

After fixing that too, we now have the multiplications by 2
done as:

addsd %xmm0 %xmm0

  • dfg/DFGGenerationInfo.h:

(JSC::DFG::GenerationInfo::useCount):
(JSC::DFG::GenerationInfo::canReuse): Deleted.

  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::FPRTemporary::FPRTemporary):

  • dfg/DFGSpeculativeJIT.h:

(JSC::DFG::SpeculativeJIT::canReuse):
(JSC::DFG::GPRTemporary::GPRTemporary):

  • dfg/DFGStrengthReductionPhase.cpp:

(JSC::DFG::StrengthReductionPhase::handleNode):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/dfg/DFGGenerationInfo.h

    r183307 r188519  
    190190    // their last use; in some cases it may be safe to reuse the same
    191191    // machine register for the result of the operation.
    192     bool canReuse()
    193     {
    194         ASSERT(m_useCount);
    195         return m_useCount == 1;
     192    uint32_t useCount()
     193    {
     194        ASSERT(m_useCount);
     195        return m_useCount;
    196196    }
    197197
Note: See TracChangeset for help on using the changeset viewer.