Changeset 207060 in webkit


Ignore:
Timestamp:
Oct 11, 2016 12:28:08 AM (8 years ago)
Author:
sbarati@apple.com
Message:

ValueAdd should be constant folded if the operands are constant String,Primitive or Primitive,String
https://bugs.webkit.org/show_bug.cgi?id=163182

Reviewed by Filip Pizlo.

JSTests:

  • microbenchmarks/string-add-constant-folding.js: Added.

(assert):
(runTests):
(add):
(test):

Source/JavaScriptCore:

This code pattern shows up in Dromaeo, so it's worth optimizing for.
This might also show up in real world JS code due to inlining and other
types of constant folding.

  • dfg/DFGByteCodeParser.cpp:

(JSC::DFG::ByteCodeParser::parseBlock):

  • dfg/DFGLazyJSValue.cpp:

(JSC::DFG::LazyJSValue::getValue):

  • dfg/DFGStrengthReductionPhase.cpp:

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

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r206948 r207060  
     12016-10-11  Saam Barati  <sbarati@apple.com>
     2
     3        ValueAdd should be constant folded if the operands are constant String,Primitive or Primitive,String
     4        https://bugs.webkit.org/show_bug.cgi?id=163182
     5
     6        Reviewed by Filip Pizlo.
     7
     8        * microbenchmarks/string-add-constant-folding.js: Added.
     9        (assert):
     10        (runTests):
     11        (add):
     12        (test):
     13
    1142016-10-07  Mark Lam  <mark.lam@apple.com>
    215
  • trunk/Source/JavaScriptCore/ChangeLog

    r207054 r207060  
     12016-10-11  Saam Barati  <sbarati@apple.com>
     2
     3        ValueAdd should be constant folded if the operands are constant String,Primitive or Primitive,String
     4        https://bugs.webkit.org/show_bug.cgi?id=163182
     5
     6        Reviewed by Filip Pizlo.
     7
     8        This code pattern shows up in Dromaeo, so it's worth optimizing for.
     9        This might also show up in real world JS code due to inlining and other
     10        types of constant folding.
     11
     12        * dfg/DFGByteCodeParser.cpp:
     13        (JSC::DFG::ByteCodeParser::parseBlock):
     14        * dfg/DFGLazyJSValue.cpp:
     15        (JSC::DFG::LazyJSValue::getValue):
     16        * dfg/DFGStrengthReductionPhase.cpp:
     17        (JSC::DFG::StrengthReductionPhase::handleNode):
     18
    1192016-10-10  Zan Dobersek  <zdobersek@igalia.com>
    220
  • trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp

    r206870 r207060  
    42404240                // FIXME: When the bytecode is not compiled in the baseline JIT, byValInfo becomes null.
    42414241                // At that time, there is no information.
    4242                 if (byValInfo && byValInfo->stubInfo && !byValInfo->tookSlowPath && !m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadIdent) && !m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadCell)) {
     4242                if (byValInfo
     4243                    && byValInfo->stubInfo
     4244                    && !byValInfo->tookSlowPath
     4245                    && !m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadIdent)
     4246                    && !m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadType)
     4247                    && !m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadCell)) {
    42434248                    compiledAsPutById = true;
    42444249                    unsigned identifierNumber = m_graph.identifiers().ensure(byValInfo->cachedId.impl());
  • trunk/Source/JavaScriptCore/dfg/DFGLazyJSValue.cpp

    r201470 r207060  
    5252        return jsSingleCharacterString(&vm, u.character);
    5353    case KnownStringImpl:
    54     case NewStringImpl:
    5554        return jsString(&vm, u.stringImpl);
     55    case NewStringImpl:
     56        return jsString(&vm, AtomicStringImpl::add(u.stringImpl));
    5657    }
    5758    RELEASE_ASSERT_NOT_REACHED();
  • trunk/Source/JavaScriptCore/dfg/DFGStrengthReductionPhase.cpp

    r205462 r207060  
    323323        // https://bugs.webkit.org/show_bug.cgi?id=155204
    324324
     325        case ValueAdd: {
     326            if (m_node->child1()->isConstant()
     327                && m_node->child2()->isConstant()
     328                && (!!m_node->child1()->tryGetString(m_graph) || !!m_node->child2()->tryGetString(m_graph))) {
     329                auto tryGetConstantString = [&] (Node* node) -> String {
     330                    String string = node->tryGetString(m_graph);
     331                    if (!string.isEmpty())
     332                        return string;
     333                    JSValue value = node->constant()->value();
     334                    if (!value)
     335                        return String();
     336                    if (value.isInt32())
     337                        return String::number(value.asInt32());
     338                    if (value.isNumber())
     339                        return String::numberToStringECMAScript(value.asNumber());
     340                    if (value.isBoolean())
     341                        return value.asBoolean() ? ASCIILiteral("true") : ASCIILiteral("false");
     342                    if (value.isNull())
     343                        return ASCIILiteral("null");
     344                    if (value.isUndefined())
     345                        return ASCIILiteral("undefined");
     346                    return String();
     347                };
     348
     349                String leftString = tryGetConstantString(m_node->child1().node());
     350                if (!leftString)
     351                    break;
     352                String rightString = tryGetConstantString(m_node->child2().node());
     353                if (!rightString)
     354                    break;
     355
     356                StringBuilder builder;
     357                builder.append(leftString);
     358                builder.append(rightString);
     359                m_node->convertToLazyJSConstant(
     360                    m_graph, LazyJSValue::newString(m_graph, builder.toString()));
     361                m_changed = true;
     362            }
     363            break;
     364        }
     365
    325366        case MakeRope:
    326         case ValueAdd:
    327367        case StrCat: {
    328368            String leftString = m_node->child1()->tryGetString(m_graph);
Note: See TracChangeset for help on using the changeset viewer.