Changeset 191838 in webkit


Ignore:
Timestamp:
Oct 30, 2015 9:03:58 PM (9 years ago)
Author:
benjamin@webkit.org
Message:

[JSC] Add lowering for B3's Sub operation with integers
https://bugs.webkit.org/show_bug.cgi?id=150749

Patch by Benjamin Poulain <bpoulain@apple.com> on 2015-10-30
Reviewed by Filip Pizlo.

  • b3/B3LowerToAir.cpp:

(JSC::B3::Air::LowerToAir::trySub):
(JSC::B3::Air::LowerToAir::tryStoreSubLoad):

  • b3/B3LoweringMatcher.patterns:

Identical to Add but obviously NotCommutative.

  • b3/B3ReduceStrength.cpp:

Turn Add/Sub with zero into an identity. I only added for
Add since Sub with a constant is always turned into an Add.

Also switched the Sub optimizations to put the strongest first.

  • b3/air/AirOpcode.opcodes:
  • b3/testb3.cpp:

(JSC::B3::testAddArgImm):
(JSC::B3::testAddImmArg):
(JSC::B3::testSubArgs):
(JSC::B3::testSubArgImm):
(JSC::B3::testSubImmArg):
(JSC::B3::testSubArgs32):
(JSC::B3::testSubArgImm32):
(JSC::B3::testSubImmArg32):
(JSC::B3::testStoreSubLoad):
(JSC::B3::run):

Location:
trunk/Source/JavaScriptCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r191837 r191838  
     12015-10-30  Benjamin Poulain  <bpoulain@apple.com>
     2
     3        [JSC] Add lowering for B3's Sub operation with integers
     4        https://bugs.webkit.org/show_bug.cgi?id=150749
     5
     6        Reviewed by Filip Pizlo.
     7
     8        * b3/B3LowerToAir.cpp:
     9        (JSC::B3::Air::LowerToAir::trySub):
     10        (JSC::B3::Air::LowerToAir::tryStoreSubLoad):
     11        * b3/B3LoweringMatcher.patterns:
     12        Identical to Add but obviously NotCommutative.
     13
     14        * b3/B3ReduceStrength.cpp:
     15        Turn Add/Sub with zero into an identity. I only added for
     16        Add since Sub with a constant is always turned into an Add.
     17
     18        Also switched the Sub optimizations to put the strongest first.
     19
     20        * b3/air/AirOpcode.opcodes:
     21        * b3/testb3.cpp:
     22        (JSC::B3::testAddArgImm):
     23        (JSC::B3::testAddImmArg):
     24        (JSC::B3::testSubArgs):
     25        (JSC::B3::testSubArgImm):
     26        (JSC::B3::testSubImmArg):
     27        (JSC::B3::testSubArgs32):
     28        (JSC::B3::testSubArgImm32):
     29        (JSC::B3::testSubImmArg32):
     30        (JSC::B3::testStoreSubLoad):
     31        (JSC::B3::run):
     32
    1332015-10-30  Benjamin Poulain  <bpoulain@apple.com>
    234
  • trunk/Source/JavaScriptCore/b3/B3LowerToAir.cpp

    r191816 r191838  
    548548        }
    549549    }
     550
     551    bool trySub(Value* left, Value* right)
     552    {
     553        switch (left->type()) {
     554        case Int32:
     555            appendBinOp<Sub32>(left, right);
     556            return true;
     557        case Int64:
     558            appendBinOp<Sub64>(left, right);
     559            return true;
     560        default:
     561            // FIXME: Implement more types!
     562            return false;
     563        }
     564    }
    550565   
    551566    bool tryAnd(Value* left, Value* right)
     
    574589        }
    575590    }
    576    
     591
     592    bool tryStoreSubLoad(Value* left, Value* right, Value*)
     593    {
     594        switch (left->type()) {
     595        case Int32:
     596            return tryAppendStoreBinOp<Sub32, NotCommutative>(left, right);
     597        default:
     598            // FIXME: Implement more types!
     599            return false;
     600        }
     601    }
     602
    577603    bool tryStoreAndLoad(Value* left, Value* right, Value*)
    578604    {
  • trunk/Source/JavaScriptCore/b3/B3LoweringMatcher.patterns

    r191816 r191838  
    3232
    3333Add = Add(left, right)
     34Sub = Sub(left, right)
    3435And = BitAnd(left, right)
    3536
    3637StoreAddLoad = Store(Add(left, right), address)
     38StoreSubLoad = Store(Add(left, right), address)
    3739StoreAndLoad = Store(BitAnd(left, right), address)
    3840Store = Store(value, address)
  • trunk/Source/JavaScriptCore/b3/B3ReduceStrength.cpp

    r191816 r191838  
    108108            // Turn this: Add(constant1, constant2)
    109109            // Into this: constant1 + constant2
    110             replaceWithNewValue(m_value->child(0)->addConstant(m_proc, m_value->child(1)));
     110            if (Value* constantAdd = m_value->child(0)->addConstant(m_proc, m_value->child(1))) {
     111                replaceWithNewValue(constantAdd);
     112                break;
     113            }
     114
     115            // Turn this: Add(value, zero)
     116            // Into an Identity.
     117            if (m_value->child(1)->isInt(0)) {
     118                m_value->replaceWithIdentity(m_value->child(0));
     119                m_changed = true;
     120                break;
     121            }
    111122            break;
    112123
    113124        case Sub:
     125            // Turn this: Sub(constant1, constant2)
     126            // Into this: constant1 - constant2
     127            if (Value* constantSub = m_value->child(0)->subConstant(m_proc, m_value->child(1))) {
     128                replaceWithNewValue(constantSub);
     129                break;
     130            }
     131
    114132            // Turn this: Sub(value, constant)
    115133            // Into this: Add(value, -constant)
     
    123141            }
    124142
    125             // Turn this: Sub(constant1, constant2)
    126             // Into this: constant1 - constant2
    127             replaceWithNewValue(m_value->child(0)->subConstant(m_proc, m_value->child(1)));
    128143            break;
    129144
  • trunk/Source/JavaScriptCore/b3/air/AirOpcode.opcodes

    r191816 r191838  
    7878Add64 U:G, U:G, D:G
    7979    Imm, Tmp, Tmp
     80
     81Sub32 U:G, UD:G
     82    Tmp, Tmp
     83    Imm, Addr
     84    Imm, Tmp
     85    Addr, Tmp
     86    Tmp, Addr
     87
     88Sub64 U:G, UD:G
     89    Tmp, Tmp
     90    Imm, Tmp
    8091
    8192Lea UA:G, D:G
  • trunk/Source/JavaScriptCore/b3/testb3.cpp

    r191816 r191838  
    135135}
    136136
     137void testAddArgImm(int a, int b)
     138{
     139    Procedure proc;
     140    BasicBlock* root = proc.addBlock();
     141    root->appendNew<ControlValue>(
     142        proc, Return, Origin(),
     143        root->appendNew<Value>(
     144            proc, Add, Origin(),
     145            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
     146            root->appendNew<Const64Value>(proc, Origin(), b)));
     147
     148    CHECK(compileAndRun<int>(proc, a) == a + b);
     149}
     150
     151void testAddImmArg(int a, int b)
     152{
     153    Procedure proc;
     154    BasicBlock* root = proc.addBlock();
     155    root->appendNew<ControlValue>(
     156        proc, Return, Origin(),
     157        root->appendNew<Value>(
     158            proc, Add, Origin(),
     159            root->appendNew<Const64Value>(proc, Origin(), a),
     160            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)));
     161
     162    CHECK(compileAndRun<int>(proc, b) == a + b);
     163}
     164
    137165void testAddArgs32(int a, int b)
    138166{
     
    151179
    152180    CHECK(compileAndRun<int>(proc, a, b) == a + b);
     181}
     182
     183void testSubArgs(int a, int b)
     184{
     185    Procedure proc;
     186    BasicBlock* root = proc.addBlock();
     187    root->appendNew<ControlValue>(
     188        proc, Return, Origin(),
     189        root->appendNew<Value>(
     190            proc, Sub, Origin(),
     191            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
     192            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1)));
     193
     194    CHECK(compileAndRun<int>(proc, a, b) == a - b);
     195}
     196
     197void testSubArgImm(int64_t a, int64_t b)
     198{
     199    Procedure proc;
     200    BasicBlock* root = proc.addBlock();
     201    root->appendNew<ControlValue>(
     202        proc, Return, Origin(),
     203        root->appendNew<Value>(
     204            proc, Sub, Origin(),
     205            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0),
     206            root->appendNew<Const64Value>(proc, Origin(), b)));
     207
     208    CHECK(compileAndRun<int64_t>(proc, a) == a - b);
     209}
     210
     211void testSubImmArg(int a, int b)
     212{
     213    Procedure proc;
     214    BasicBlock* root = proc.addBlock();
     215    root->appendNew<ControlValue>(
     216        proc, Return, Origin(),
     217        root->appendNew<Value>(
     218            proc, Sub, Origin(),
     219            root->appendNew<Const64Value>(proc, Origin(), a),
     220            root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)));
     221
     222    CHECK(compileAndRun<int>(proc, b) == a - b);
     223}
     224
     225void testSubArgs32(int a, int b)
     226{
     227    Procedure proc;
     228    BasicBlock* root = proc.addBlock();
     229    root->appendNew<ControlValue>(
     230        proc, Return, Origin(),
     231        root->appendNew<Value>(
     232            proc, Sub, Origin(),
     233            root->appendNew<Value>(
     234                proc, Trunc, Origin(),
     235                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)),
     236            root->appendNew<Value>(
     237                proc, Trunc, Origin(),
     238                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR1))));
     239
     240    CHECK(compileAndRun<int>(proc, a, b) == a - b);
     241}
     242
     243void testSubArgImm32(int a, int b)
     244{
     245    Procedure proc;
     246    BasicBlock* root = proc.addBlock();
     247    root->appendNew<ControlValue>(
     248        proc, Return, Origin(),
     249        root->appendNew<Value>(
     250            proc, Sub, Origin(),
     251            root->appendNew<Value>(
     252                proc, Trunc, Origin(),
     253                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0)),
     254            root->appendNew<Const32Value>(proc, Origin(), b)));
     255
     256    CHECK(compileAndRun<int>(proc, a) == a - b);
     257}
     258
     259void testSubImmArg32(int a, int b)
     260{
     261    Procedure proc;
     262    BasicBlock* root = proc.addBlock();
     263    root->appendNew<ControlValue>(
     264        proc, Return, Origin(),
     265        root->appendNew<Value>(
     266            proc, Sub, Origin(),
     267            root->appendNew<Const32Value>(proc, Origin(), a),
     268            root->appendNew<Value>(
     269                proc, Trunc, Origin(),
     270                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0))));
     271
     272    CHECK(compileAndRun<int>(proc, b) == a - b);
    153273}
    154274
     
    269389    CHECK(!compileAndRun<int>(proc));
    270390    CHECK(slot == 37 + amount);
     391}
     392
     393void testStoreSubLoad(int amount)
     394{
     395    Procedure proc;
     396    BasicBlock* root = proc.addBlock();
     397    int32_t startValue = std::numeric_limits<int32_t>::min();
     398    int32_t slot = startValue;
     399    ConstPtrValue* slotPtr = root->appendNew<ConstPtrValue>(proc, Origin(), &slot);
     400    root->appendNew<MemoryValue>(
     401        proc, Store, Origin(),
     402        root->appendNew<Value>(
     403            proc, Sub, Origin(),
     404            root->appendNew<MemoryValue>(proc, Load, Int32, Origin(), slotPtr),
     405            root->appendNew<Value>(
     406                proc, Trunc, Origin(),
     407                root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0))),
     408        slotPtr);
     409    root->appendNew<ControlValue>(
     410        proc, Return, Origin(),
     411        root->appendNew<Const32Value>(proc, Origin(), 0));
     412
     413    CHECK(!compileAndRun<int>(proc, amount));
     414    CHECK(slot == startValue - amount);
    271415}
    272416
     
    9451089    RUN(testLoad42());
    9461090    RUN(testArg(43));
     1091
    9471092    RUN(testAddArgs(1, 1));
    9481093    RUN(testAddArgs(1, 2));
     1094    RUN(testAddArgImm(1, 2));
     1095    RUN(testAddArgImm(0, 2));
     1096    RUN(testAddArgImm(1, 0));
     1097    RUN(testAddImmArg(1, 2));
     1098    RUN(testAddImmArg(0, 2));
     1099    RUN(testAddImmArg(1, 0));
    9491100    RUN(testAddArgs32(1, 1));
    9501101    RUN(testAddArgs32(1, 2));
     1102
     1103    RUN(testSubArgs(1, 1));
     1104    RUN(testSubArgs(1, 2));
     1105    RUN(testSubArgs(13, -42));
     1106    RUN(testSubArgs(-13, 42));
     1107    RUN(testSubArgImm(1, 1));
     1108    RUN(testSubArgImm(1, 2));
     1109    RUN(testSubArgImm(13, -42));
     1110    RUN(testSubArgImm(-13, 42));
     1111    RUN(testSubArgImm(42, 0));
     1112    RUN(testSubImmArg(1, 1));
     1113    RUN(testSubImmArg(1, 2));
     1114    RUN(testSubImmArg(13, -42));
     1115    RUN(testSubImmArg(-13, 42));
     1116
     1117    RUN(testSubArgs32(1, 1));
     1118    RUN(testSubArgs32(1, 2));
     1119    RUN(testSubArgs32(13, -42));
     1120    RUN(testSubArgs32(-13, 42));
     1121    RUN(testSubArgImm32(1, 1));
     1122    RUN(testSubArgImm32(1, 2));
     1123    RUN(testSubArgImm32(13, -42));
     1124    RUN(testSubArgImm32(-13, 42));
     1125    RUN(testSubImmArg32(1, 1));
     1126    RUN(testSubImmArg32(1, 2));
     1127    RUN(testSubImmArg32(13, -42));
     1128    RUN(testSubImmArg32(-13, 42));
     1129
    9511130    RUN(testStore(44));
    9521131    RUN(testStoreConstant(49));
     
    9571136    RUN(testAdd1Ptr(bitwise_cast<intptr_t>(vm)));
    9581137    RUN(testStoreAddLoad(46));
     1138    RUN(testStoreSubLoad(46));
    9591139    RUN(testStoreAddLoadInterference(52));
    9601140    RUN(testStoreAddAndLoad(47, 0xffff));
Note: See TracChangeset for help on using the changeset viewer.