Changeset 195422 in webkit
- Timestamp:
- Jan 21, 2016 2:56:21 PM (8 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r195419 r195422 1 2016-01-21 Benjamin Poulain <benjamin@webkit.org> 2 3 [JSC] foldPathConstants() makes invalid assumptions with Switch 4 https://bugs.webkit.org/show_bug.cgi?id=153324 5 6 Reviewed by Filip Pizlo. 7 8 If a Switch() has two cases pointing to the same basic block, foldPathConstants() 9 was adding two override for that block with two different constants. 10 If the block with the Switch dominates the target, both override were equally valid 11 and we were assuming any of the constants as the value in the target block. 12 13 See testSwitchTargettingSameBlockFoldPathConstant() for an example that breaks. 14 15 This patch adds checks to ignore any block that is reached more than 16 once by the control value. 17 18 * b3/B3FoldPathConstants.cpp: 19 * b3/B3Generate.cpp: 20 (JSC::B3::generateToAir): 21 * b3/testb3.cpp: 22 (JSC::B3::testSwitchTargettingSameBlock): 23 (JSC::B3::testSwitchTargettingSameBlockFoldPathConstant): 24 (JSC::B3::run): 25 1 26 2016-01-21 Filip Pizlo <fpizlo@apple.com> 2 27 -
trunk/Source/JavaScriptCore/b3/B3FoldPathConstants.cpp
r195395 r195422 91 91 switch (branch->opcode()) { 92 92 case Branch: 93 if (branch->successorBlock(0) == branch->successorBlock(1)) 94 continue; 93 95 addOverride( 94 96 block, branch->child(0), … … 98 100 Override::constant(branch->successorBlock(1), 0)); 99 101 break; 100 case Switch: 102 case Switch: { 103 HashMap<BasicBlock*, unsigned> targetUses; 104 for (const SwitchCase& switchCase : *branch->as<SwitchValue>()) 105 targetUses.add(switchCase.targetBlock(), 0).iterator->value++; 106 101 107 for (const SwitchCase& switchCase : *branch->as<SwitchValue>()) { 108 if (targetUses.find(switchCase.targetBlock())->value != 1) 109 continue; 110 102 111 addOverride( 103 112 block, branch->child(0), … … 105 114 } 106 115 break; 116 } 107 117 default: 108 118 break; -
trunk/Source/JavaScriptCore/b3/B3Generate.cpp
r195417 r195422 92 92 if (optLevel >= 1) { 93 93 reduceStrength(procedure); 94 94 95 95 // FIXME: Add more optimizations here. 96 96 // https://bugs.webkit.org/show_bug.cgi?id=150507 -
trunk/Source/JavaScriptCore/b3/testb3.cpp
r195395 r195422 8428 8428 CHECK(!invoke<int32_t>(*code, degree * gap, 42, 11)); 8429 8429 CHECK(!invoke<int32_t>(*code, degree * gap + 1, 42, 11)); 8430 } 8431 8432 void testSwitchTargettingSameBlock() 8433 { 8434 Procedure proc; 8435 BasicBlock* root = proc.addBlock(); 8436 8437 BasicBlock* terminate = proc.addBlock(); 8438 terminate->appendNew<ControlValue>( 8439 proc, Return, Origin(), 8440 terminate->appendNew<Const32Value>(proc, Origin(), 5)); 8441 8442 SwitchValue* switchValue = root->appendNew<SwitchValue>( 8443 proc, Origin(), 8444 root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0), 8445 FrequentedBlock(terminate)); 8446 8447 BasicBlock* otherTarget = proc.addBlock(); 8448 otherTarget->appendNew<ControlValue>( 8449 proc, Return, Origin(), 8450 otherTarget->appendNew<Const32Value>(proc, Origin(), 42)); 8451 switchValue->appendCase(SwitchCase(3, FrequentedBlock(otherTarget))); 8452 switchValue->appendCase(SwitchCase(13, FrequentedBlock(otherTarget))); 8453 8454 auto code = compile(proc); 8455 8456 for (unsigned i = 0; i < 20; ++i) { 8457 int32_t expected = (i == 3 || i == 13) ? 42 : 5; 8458 CHECK(invoke<int32_t>(*code, i) == expected); 8459 } 8460 } 8461 8462 void testSwitchTargettingSameBlockFoldPathConstant() 8463 { 8464 Procedure proc; 8465 BasicBlock* root = proc.addBlock(); 8466 8467 BasicBlock* terminate = proc.addBlock(); 8468 terminate->appendNew<ControlValue>( 8469 proc, Return, Origin(), 8470 terminate->appendNew<Const32Value>(proc, Origin(), 42)); 8471 8472 Value* argument = root->appendNew<ArgumentRegValue>(proc, Origin(), GPRInfo::argumentGPR0); 8473 SwitchValue* switchValue = root->appendNew<SwitchValue>( 8474 proc, Origin(), 8475 argument, 8476 FrequentedBlock(terminate)); 8477 8478 BasicBlock* otherTarget = proc.addBlock(); 8479 otherTarget->appendNew<ControlValue>( 8480 proc, Return, Origin(), argument); 8481 switchValue->appendCase(SwitchCase(3, FrequentedBlock(otherTarget))); 8482 switchValue->appendCase(SwitchCase(13, FrequentedBlock(otherTarget))); 8483 8484 auto code = compile(proc); 8485 8486 for (unsigned i = 0; i < 20; ++i) { 8487 int32_t expected = (i == 3 || i == 13) ? i : 42; 8488 CHECK(invoke<int32_t>(*code, i) == expected); 8489 } 8430 8490 } 8431 8491 … … 10385 10445 RUN(testSwitchChillDiv(100, 1)); 10386 10446 RUN(testSwitchChillDiv(100, 100)); 10447 10448 RUN(testSwitchTargettingSameBlock()); 10449 RUN(testSwitchTargettingSameBlockFoldPathConstant()); 10387 10450 10388 10451 RUN(testTrunc(0));
Note: See TracChangeset
for help on using the changeset viewer.