Changeset 247390 in webkit


Ignore:
Timestamp:
Jul 12, 2019 10:11:31 AM (5 years ago)
Author:
Justin Michaud
Message:

B3 should reduce (integer) Sub(Neg(x), y) to Neg(Add(x, y))
https://bugs.webkit.org/show_bug.cgi?id=196371

Reviewed by Keith Miller.

JSTests:

  • microbenchmarks/mul-immediate-sub.js: Added.

(doTest):

Source/JavaScriptCore:

Adding these strength reductions gives 2x a (x86) and 3x (arm64) performance improvement
on the microbenchmark.

  • b3/B3ReduceStrength.cpp:
  • b3/testb3.cpp:

(JSC::B3::testSubSub):
(JSC::B3::testSubSub2):
(JSC::B3::testSubAdd):
(JSC::B3::testSubFirstNeg):
(JSC::B3::run):

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r247387 r247390  
     12019-07-12  Justin Michaud  <justin_michaud@apple.com>
     2
     3        B3 should reduce (integer) Sub(Neg(x), y) to Neg(Add(x, y))
     4        https://bugs.webkit.org/show_bug.cgi?id=196371
     5
     6        Reviewed by Keith Miller.
     7
     8        * microbenchmarks/mul-immediate-sub.js: Added.
     9        (doTest):
     10
    1112019-07-12  Caio Lima  <ticaiolima@gmail.com>
    212
  • trunk/Source/JavaScriptCore/ChangeLog

    r247387 r247390  
     12019-07-12  Justin Michaud  <justin_michaud@apple.com>
     2
     3        B3 should reduce (integer) Sub(Neg(x), y) to Neg(Add(x, y))
     4        https://bugs.webkit.org/show_bug.cgi?id=196371
     5
     6        Reviewed by Keith Miller.
     7
     8        Adding these strength reductions gives 2x a (x86) and 3x (arm64) performance improvement
     9        on the microbenchmark.
     10
     11        * b3/B3ReduceStrength.cpp:
     12        * b3/testb3.cpp:
     13        (JSC::B3::testSubSub):
     14        (JSC::B3::testSubSub2):
     15        (JSC::B3::testSubAdd):
     16        (JSC::B3::testSubFirstNeg):
     17        (JSC::B3::run):
     18
    1192019-07-12  Caio Lima  <ticaiolima@gmail.com>
    220
  • trunk/Source/JavaScriptCore/b3/B3ReduceStrength.cpp

    r245192 r247390  
    649649                if (m_value->child(1)->opcode() == Neg) {
    650650                    replaceWithNew<Value>(Add, m_value->origin(), m_value->child(0), m_value->child(1)->child(0));
     651                    break;
     652                }
     653
     654                // Turn this: Sub(Neg(value), value2)
     655                // Into this: Neg(Add(value, value2))
     656                if (m_value->child(0)->opcode() == Neg) {
     657                    replaceWithNew<Value>(Neg, m_value->origin(),
     658                        m_insertionSet.insert<Value>(m_index, Add, m_value->origin(), m_value->child(0)->child(0), m_value->child(1)));
     659                    break;
     660                }
     661
     662                // Turn this: Sub(Sub(a, b), c)
     663                // Into this: Sub(a, Add(b, c))
     664                if (m_value->child(0)->opcode() == Sub) {
     665                    replaceWithNew<Value>(Sub, m_value->origin(), m_value->child(0)->child(0),
     666                        m_insertionSet.insert<Value>(m_index, Add, m_value->origin(), m_value->child(0)->child(1), m_value->child(1)));
     667                    break;
     668                }
     669
     670                // Turn this: Sub(a, Sub(b, c))
     671                // Into this: Add(Sub(a, b), c)
     672                if (m_value->child(1)->opcode() == Sub) {
     673                    replaceWithNew<Value>(Add, m_value->origin(),
     674                        m_insertionSet.insert<Value>(m_index, Sub, m_value->origin(), m_value->child(0), m_value->child(1)->child(0)),
     675                        m_value->child(1)->child(1));
     676                    break;
     677                }
     678
     679                // Turn this: Sub(Add(a, b), c)
     680                // Into this: Add(a, Sub(b, c))
     681                if (m_value->child(0)->opcode() == Add) {
     682                    replaceWithNew<Value>(Add, m_value->origin(), m_value->child(0)->child(0),
     683                        m_insertionSet.insert<Value>(m_index, Sub, m_value->origin(), m_value->child(0)->child(1), m_value->child(1)));
    651684                    break;
    652685                }
  • trunk/Source/JavaScriptCore/b3/testb3.cpp

    r247363 r247390  
    21892189    root->appendNewControlValue(proc, Return, Origin(), negArgumentMinusOne);
    21902190    CHECK(compileAndRun<int>(proc, a) == -a - 1);
     2191}
     2192
     2193void testSubSub(int a, int b, int c)
     2194{
     2195    Procedure proc;
     2196    BasicBlock* root = proc.addBlock();
     2197    root->appendNewControlValue(
     2198        proc, Return, Origin(),
     2199        root->appendNew<Value>(
     2200            proc, Sub, Origin(),
     2201            root->appendNew<Value>(proc, Sub, Origin(),
     2202                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
     2203                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1)),
     2204            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR2)));
     2205
     2206    CHECK(compileAndRun<int>(proc, a, b, c) == (a-b)-c);
     2207}
     2208
     2209void testSubSub2(int a, int b, int c)
     2210{
     2211    Procedure proc;
     2212    BasicBlock* root = proc.addBlock();
     2213    root->appendNewControlValue(
     2214        proc, Return, Origin(),
     2215        root->appendNew<Value>(
     2216            proc, Sub, Origin(),
     2217            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
     2218            root->appendNew<Value>(proc, Sub, Origin(),
     2219                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1),
     2220                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR2))));
     2221
     2222    CHECK(compileAndRun<int>(proc, a, b, c) == a-(b-c));
     2223}
     2224
     2225void testSubAdd(int a, int b, int c)
     2226{
     2227    Procedure proc;
     2228    BasicBlock* root = proc.addBlock();
     2229    root->appendNewControlValue(
     2230        proc, Return, Origin(),
     2231        root->appendNew<Value>(
     2232            proc, Sub, Origin(),
     2233            root->appendNew<Value>(proc, Add, Origin(),
     2234                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
     2235                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1)),
     2236            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR2)));
     2237
     2238    CHECK(compileAndRun<int>(proc, a, b, c) == (a+b)-c);
     2239}
     2240
     2241void testSubFirstNeg(int a, int b)
     2242{
     2243    Procedure proc;
     2244    BasicBlock* root = proc.addBlock();
     2245    root->appendNewControlValue(
     2246        proc, Return, Origin(),
     2247        root->appendNew<Value>(
     2248            proc, Sub, Origin(),
     2249            root->appendNew<Value>(proc, Neg, Origin(),
     2250                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)),
     2251            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1)));
     2252
     2253    CHECK(compileAndRun<int>(proc, a, b) == (-a)-b);
    21912254}
    21922255
     
    1745717520    RUN_BINARY(testNegMulArgImm, int64Operands(), int64Operands());
    1745817521    RUN_TERNARY(testSubMulMulArgs, int64Operands(), int64Operands(), int64Operands());
     17522
     17523    RUN_TERNARY(testSubSub, int32Operands(), int32Operands(), int32Operands());
     17524    RUN_TERNARY(testSubSub2, int32Operands(), int32Operands(), int32Operands());
     17525    RUN_TERNARY(testSubAdd, int32Operands(), int32Operands(), int32Operands());
     17526    RUN_BINARY(testSubFirstNeg, int32Operands(), int32Operands());
    1745917527
    1746017528    RUN(testSubArgs32(1, 1));
Note: See TracChangeset for help on using the changeset viewer.