Changeset 191838 in webkit
- Timestamp:
- Oct 30, 2015 9:03:58 PM (9 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r191837 r191838 1 2015-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 1 33 2015-10-30 Benjamin Poulain <bpoulain@apple.com> 2 34 -
trunk/Source/JavaScriptCore/b3/B3LowerToAir.cpp
r191816 r191838 548 548 } 549 549 } 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 } 550 565 551 566 bool tryAnd(Value* left, Value* right) … … 574 589 } 575 590 } 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 577 603 bool tryStoreAndLoad(Value* left, Value* right, Value*) 578 604 { -
trunk/Source/JavaScriptCore/b3/B3LoweringMatcher.patterns
r191816 r191838 32 32 33 33 Add = Add(left, right) 34 Sub = Sub(left, right) 34 35 And = BitAnd(left, right) 35 36 36 37 StoreAddLoad = Store(Add(left, right), address) 38 StoreSubLoad = Store(Add(left, right), address) 37 39 StoreAndLoad = Store(BitAnd(left, right), address) 38 40 Store = Store(value, address) -
trunk/Source/JavaScriptCore/b3/B3ReduceStrength.cpp
r191816 r191838 108 108 // Turn this: Add(constant1, constant2) 109 109 // 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 } 111 122 break; 112 123 113 124 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 114 132 // Turn this: Sub(value, constant) 115 133 // Into this: Add(value, -constant) … … 123 141 } 124 142 125 // Turn this: Sub(constant1, constant2)126 // Into this: constant1 - constant2127 replaceWithNewValue(m_value->child(0)->subConstant(m_proc, m_value->child(1)));128 143 break; 129 144 -
trunk/Source/JavaScriptCore/b3/air/AirOpcode.opcodes
r191816 r191838 78 78 Add64 U:G, U:G, D:G 79 79 Imm, Tmp, Tmp 80 81 Sub32 U:G, UD:G 82 Tmp, Tmp 83 Imm, Addr 84 Imm, Tmp 85 Addr, Tmp 86 Tmp, Addr 87 88 Sub64 U:G, UD:G 89 Tmp, Tmp 90 Imm, Tmp 80 91 81 92 Lea UA:G, D:G -
trunk/Source/JavaScriptCore/b3/testb3.cpp
r191816 r191838 135 135 } 136 136 137 void 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 151 void 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 137 165 void testAddArgs32(int a, int b) 138 166 { … … 151 179 152 180 CHECK(compileAndRun<int>(proc, a, b) == a + b); 181 } 182 183 void 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 197 void 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 211 void 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 225 void 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 243 void 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 259 void 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); 153 273 } 154 274 … … 269 389 CHECK(!compileAndRun<int>(proc)); 270 390 CHECK(slot == 37 + amount); 391 } 392 393 void 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); 271 415 } 272 416 … … 945 1089 RUN(testLoad42()); 946 1090 RUN(testArg(43)); 1091 947 1092 RUN(testAddArgs(1, 1)); 948 1093 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)); 949 1100 RUN(testAddArgs32(1, 1)); 950 1101 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 951 1130 RUN(testStore(44)); 952 1131 RUN(testStoreConstant(49)); … … 957 1136 RUN(testAdd1Ptr(bitwise_cast<intptr_t>(vm))); 958 1137 RUN(testStoreAddLoad(46)); 1138 RUN(testStoreSubLoad(46)); 959 1139 RUN(testStoreAddLoadInterference(52)); 960 1140 RUN(testStoreAddAndLoad(47, 0xffff));
Note: See TracChangeset
for help on using the changeset viewer.