Changeset 244238 in webkit


Ignore:
Timestamp:
Apr 12, 2019 8:04:18 PM (5 years ago)
Author:
sbarati@apple.com
Message:

r244079 logically broke shouldSpeculateInt52
https://bugs.webkit.org/show_bug.cgi?id=196884

Reviewed by Yusuke Suzuki.

JSTests:

  • microbenchmarks/int52-rand-function.js: Added.

(Math.random):

Source/JavaScriptCore:

In r244079, I changed shouldSpeculateInt52 to only return true
when the prediction is isAnyInt52Speculation(). However, it was
wrong to not to include SpecInt32 in this for two reasons:

  1. We diligently write code that first checks if we should speculate Int32.

For example:
if (shouldSpeculateInt32()) ...
else if (shouldSpeculateInt52()) ...

It would be wrong not to fall back to Int52 if we're dealing with the union of
Int32 and Int52.

It would be a performance mistake to not include Int32 here because
data flow can easily tell us that we have variables that are the union
of Int32 and Int52 values. It's better to speculate Int52 than Double
in that situation.

  1. We also write code where we ask if the inputs can be Int52, e.g, if

we know via profiling that an Add overflows, we may not emit an Int32 add.
However, we only emit such an add if both inputs can be Int52, and Int32
can trivially become Int52.

This patch recovers the 0.5-1% regression r244079 caused on JetStream 2.

  • bytecode/SpeculatedType.h:

(JSC::isInt32SpeculationForArithmetic):
(JSC::isInt32OrBooleanSpeculationForArithmetic):
(JSC::isInt32OrInt52Speculation):

  • dfg/DFGFixupPhase.cpp:

(JSC::DFG::FixupPhase::observeUseKindOnNode):

  • dfg/DFGNode.h:

(JSC::DFG::Node::shouldSpeculateInt52):

  • dfg/DFGPredictionPropagationPhase.cpp:
  • dfg/DFGVariableAccessData.cpp:

(JSC::DFG::VariableAccessData::couldRepresentInt52Impl):

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r244211 r244238  
     12019-04-12  Saam barati  <sbarati@apple.com>
     2
     3        r244079 logically broke shouldSpeculateInt52
     4        https://bugs.webkit.org/show_bug.cgi?id=196884
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * microbenchmarks/int52-rand-function.js: Added.
     9        (Math.random):
     10
    1112019-04-11  Yusuke Suzuki  <ysuzuki@apple.com>
    212
  • trunk/Source/JavaScriptCore/ChangeLog

    r244237 r244238  
     12019-04-12  Saam barati  <sbarati@apple.com>
     2
     3        r244079 logically broke shouldSpeculateInt52
     4        https://bugs.webkit.org/show_bug.cgi?id=196884
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        In r244079, I changed shouldSpeculateInt52 to only return true
     9        when the prediction is isAnyInt52Speculation(). However, it was
     10        wrong to not to include SpecInt32 in this for two reasons:
     11
     12        1. We diligently write code that first checks if we should speculate Int32.
     13        For example:
     14        if (shouldSpeculateInt32()) ...
     15        else if (shouldSpeculateInt52()) ...
     16
     17        It would be wrong not to fall back to Int52 if we're dealing with the union of
     18        Int32 and Int52.
     19
     20        It would be a performance mistake to not include Int32 here because
     21        data flow can easily tell us that we have variables that are the union
     22        of Int32 and Int52 values. It's better to speculate Int52 than Double
     23        in that situation.
     24
     25        2. We also write code where we ask if the inputs can be Int52, e.g, if
     26        we know via profiling that an Add overflows, we may not emit an Int32 add.
     27        However, we only emit such an add if both inputs can be Int52, and Int32
     28        can trivially become Int52.
     29
     30       This patch recovers the 0.5-1% regression r244079 caused on JetStream 2.
     31
     32        * bytecode/SpeculatedType.h:
     33        (JSC::isInt32SpeculationForArithmetic):
     34        (JSC::isInt32OrBooleanSpeculationForArithmetic):
     35        (JSC::isInt32OrInt52Speculation):
     36        * dfg/DFGFixupPhase.cpp:
     37        (JSC::DFG::FixupPhase::observeUseKindOnNode):
     38        * dfg/DFGNode.h:
     39        (JSC::DFG::Node::shouldSpeculateInt52):
     40        * dfg/DFGPredictionPropagationPhase.cpp:
     41        * dfg/DFGVariableAccessData.cpp:
     42        (JSC::DFG::VariableAccessData::couldRepresentInt52Impl):
     43
    1442019-04-12  Saam barati  <sbarati@apple.com>
    245
  • trunk/Source/JavaScriptCore/bytecode/SpeculatedType.h

    r244079 r244238  
    343343inline bool isInt32SpeculationForArithmetic(SpeculatedType value)
    344344{
    345     return !(value & (SpecFullDouble | SpecInt52Any));
     345    return !(value & (SpecFullDouble | SpecNonInt32AsInt52));
    346346}
    347347
    348348inline bool isInt32OrBooleanSpeculationForArithmetic(SpeculatedType value)
    349349{
    350     return !(value & (SpecFullDouble | SpecInt52Any));
     350    return !(value & (SpecFullDouble | SpecNonInt32AsInt52));
    351351}
    352352
     
    359359{
    360360    return !!value && (value & SpecInt52Any) == value;
     361}
     362
     363inline bool isInt32OrInt52Speculation(SpeculatedType value)
     364{
     365    return !!value && (value & (SpecInt32Only | SpecInt52Any)) == value;
    361366}
    362367
  • trunk/Source/JavaScriptCore/dfg/DFGFixupPhase.cpp

    r244193 r244238  
    32253225            break;
    32263226        case Int52RepUse:
    3227             if (isAnyInt52Speculation(variable->prediction()))
     3227            if (!isInt32Speculation(variable->prediction()) && isInt32OrInt52Speculation(variable->prediction()))
    32283228                m_profitabilityChanged |= variable->mergeIsProfitableToUnbox(true);
    32293229            break;
  • trunk/Source/JavaScriptCore/dfg/DFGNode.h

    r244193 r244238  
    23492349    bool shouldSpeculateInt52()
    23502350    {
    2351         return enableInt52() && isAnyInt52Speculation(prediction());
     2351        // We have to include SpecInt32Only here for two reasons:
     2352        // 1. We diligently write code that first checks if we should speculate Int32.
     2353        // For example:
     2354        // if (shouldSpeculateInt32()) ...
     2355        // else if (shouldSpeculateInt52()) ...
     2356        // This means we it's totally valid to speculate Int52 when we're dealing
     2357        // with a type that's the union of Int32 and Int52.
     2358        //
     2359        // It would be a performance mistake to not include Int32 here because we obviously
     2360        // have variables that are the union of Int32 and Int52 values, and it's better
     2361        // to speculate Int52 than double in that situation.
     2362        //
     2363        // 2. We also write code where we ask if the inputs can be Int52, like if
     2364        // we know via profiling that an Add overflows, we may not emit an Int32 add.
     2365        // However, we only emit such an add if both inputs can be Int52, and Int32
     2366        // can trivially become Int52.
     2367        //
     2368        return enableInt52() && isInt32OrInt52Speculation(prediction());
    23522369    }
    23532370   
  • trunk/Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp

    r244193 r244238  
    643643            if (isDoubleSpeculation(prediction))
    644644                node->variableAccessData()->vote(VoteDouble, weight);
    645             else if (!isFullNumberSpeculation(prediction)
    646                 || isInt32Speculation(prediction) || isAnyInt52Speculation(prediction))
     645            else if (!isFullNumberSpeculation(prediction) || isInt32OrInt52Speculation(prediction))
    647646                node->variableAccessData()->vote(VoteValue, weight);
    648647            break;
     
    735734        switch (m_currentNode->op()) {
    736735        case JSConstant: {
    737             setPrediction(speculationFromValue(m_currentNode->asJSValue()));
     736            SpeculatedType type = speculationFromValue(m_currentNode->asJSValue());
     737            if (type == SpecAnyIntAsDouble && enableInt52())
     738                type = int52AwareSpeculationFromValue(m_currentNode->asJSValue());
     739            setPrediction(type);
    738740            break;
    739741        }
  • trunk/Source/JavaScriptCore/dfg/DFGVariableAccessData.cpp

    r244079 r244238  
    182182    // The argument-aware prediction -- which merges all of an (inlined or machine)
    183183    // argument's variable access datas' predictions -- must possibly be Int52Any.
    184     return isAnyInt52Speculation(argumentAwarePrediction());
     184    return isInt32OrInt52Speculation(argumentAwarePrediction());
    185185}
    186186
Note: See TracChangeset for help on using the changeset viewer.