Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[JSC] Optimize more cases of something-compared-to-null/undefined
https://bugs.webkit.org/show_bug.cgi?id=148157 Patch by Benjamin Poulain <bpoulain@apple.com> on 2015-08-18 Reviewed by Geoffrey Garen and Filip Pizlo. Source/JavaScriptCore: CompareEq is fairly trivial if you assert one of the operands is either null or undefined. Under those conditions, the only way to have "true" is to have the other operand be null/undefined or have an object that masquerades to undefined. JSC already had a fast path in CompareEqConstant. With this patch, I generalize this fast path to more cases and try to eliminate the checks whenever possible. CompareEq now does the job of CompareEqConstant. If any operand can be proved to be undefined/other, its edge is set to OtherUse. Whenever any edge is OtherUse, we generate the fast code we had for CompareEqConstant. The AbstractInterpreter has additional checks to reduce the node to a constant whenever possible. There are two additional changes in this patch: -The Fixup Phase tries to set edges to OtherUse early. This is done correctly in ConstantFoldingPhase but setting it up early helps the phases relying on Clobberize. -The codegen for CompareEqConstant was improved. The reason is the comparison for ObjectOrOther could be faster just because the codegen was better. * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects): * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::parseBlock): * dfg/DFGClobberize.h: (JSC::DFG::clobberize): Deleted. * dfg/DFGConstantFoldingPhase.cpp: (JSC::DFG::ConstantFoldingPhase::foldConstants): * dfg/DFGDoesGC.cpp: (JSC::DFG::doesGC): Deleted. * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * dfg/DFGNode.h: (JSC::DFG::Node::isUndefinedOrNullConstant): * dfg/DFGNodeType.h: * dfg/DFGPredictionPropagationPhase.cpp: (JSC::DFG::PredictionPropagationPhase::propagate): Deleted. * dfg/DFGSafeToExecute.h: (JSC::DFG::safeToExecute): Deleted. * dfg/DFGSpeculativeJIT.cpp: (JSC::DFG::SpeculativeJIT::compilePeepHoleBranch): (JSC::DFG::SpeculativeJIT::compare): * dfg/DFGSpeculativeJIT.h: (JSC::DFG::SpeculativeJIT::isKnownNotOther): * dfg/DFGSpeculativeJIT32_64.cpp: (JSC::DFG::SpeculativeJIT::nonSpeculativeNonPeepholeCompareNullOrUndefined): (JSC::DFG::SpeculativeJIT::nonSpeculativePeepholeBranchNullOrUndefined): (JSC::DFG::SpeculativeJIT::nonSpeculativeNonPeepholeCompareNull): Deleted. (JSC::DFG::SpeculativeJIT::nonSpeculativePeepholeBranchNull): Deleted. (JSC::DFG::SpeculativeJIT::nonSpeculativeCompareNull): Deleted. (JSC::DFG::SpeculativeJIT::compile): Deleted. * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::nonSpeculativeNonPeepholeCompareNullOrUndefined): (JSC::DFG::SpeculativeJIT::nonSpeculativePeepholeBranchNullOrUndefined): (JSC::DFG::SpeculativeJIT::nonSpeculativeNonPeepholeCompareNull): Deleted. (JSC::DFG::SpeculativeJIT::nonSpeculativePeepholeBranchNull): Deleted. (JSC::DFG::SpeculativeJIT::nonSpeculativeCompareNull): Deleted. (JSC::DFG::SpeculativeJIT::compile): Deleted. * dfg/DFGValidate.cpp: (JSC::DFG::Validate::validate): Deleted. * dfg/DFGWatchpointCollectionPhase.cpp: (JSC::DFG::WatchpointCollectionPhase::handle): * ftl/FTLCapabilities.cpp: (JSC::FTL::canCompile): * ftl/FTLLowerDFGToLLVM.cpp: (JSC::FTL::DFG::LowerDFGToLLVM::compileCompareEq): (JSC::FTL::DFG::LowerDFGToLLVM::compileNode): Deleted. (JSC::FTL::DFG::LowerDFGToLLVM::compileCompareEqConstant): Deleted. * tests/stress/compare-eq-on-null-and-undefined-non-peephole.js: Added. (string_appeared_here.useForMath): (testUseForMath): * tests/stress/compare-eq-on-null-and-undefined-optimized-in-constant-folding.js: Added. (string_appeared_here.unreachableCodeTest): (inlinedCompareToNull): (inlinedComparedToUndefined): (warmupInlineFunctions): (testInlineFunctions): * tests/stress/compare-eq-on-null-and-undefined.js: Added. (string_appeared_here.compareConstants): (opaqueNull): (opaqueUndefined): (compareConstantsAndDynamicValues): (compareDynamicValues): (compareDynamicValueToItself): (arrayTesting): (opaqueCompare1): (testNullComparatorUpdate): (opaqueCompare2): (testUndefinedComparatorUpdate): (opaqueCompare3): (testNullAndUndefinedComparatorUpdate): LayoutTests: * js/dom/document-all-watchpoint-covers-eliminated-compare-eq-expected.txt: Added. * js/dom/document-all-watchpoint-covers-eliminated-compare-eq.html: Added. * js/dom/script-tests/document-all-watchpoint-covers-eliminated-compare-eq.js: Added. (compareFunction): Canonical link: https://commits.webkit.org/166282@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@188624 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
1 parent
7ba605f
commit ab82b54
Showing
26 changed files
with
649 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
LayoutTests/js/dom/document-all-watchpoint-covers-eliminated-compare-eq-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Test to make sure that document.all works correctly with elminated CompareEq in DFG. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS documentAllCompare.isNull is true | ||
PASS documentAllCompare.isUndefined is true | ||
PASS documentAllCompare.length is 13 | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
10 changes: 10 additions & 0 deletions
10
LayoutTests/js/dom/document-all-watchpoint-covers-eliminated-compare-eq.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
<script src="../../resources/js-test-pre.js"></script> | ||
</head> | ||
<body> | ||
<script src="script-tests/document-all-watchpoint-covers-eliminated-compare-eq.js"></script> | ||
<script src="../../resources/js-test-post.js"></script> | ||
</body> | ||
</html> |
49 changes: 49 additions & 0 deletions
49
LayoutTests/js/dom/script-tests/document-all-watchpoint-covers-eliminated-compare-eq.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
description("Test to make sure that document.all works correctly with elminated CompareEq in DFG."); | ||
|
||
function compareFunction(a) | ||
{ | ||
var length = a.length; | ||
|
||
var aIsNull = (a == null) || (null == a); | ||
var aIsUndefined = (a == undefined) || (undefined == a); | ||
|
||
if (a == null || undefined == a) | ||
return { isNull: aIsNull, isUndefined: aIsUndefined, length: length }; | ||
else | ||
return { isNull: aIsNull, isUndefined: aIsUndefined }; | ||
} | ||
|
||
// Warmup with sane objects. | ||
for (let i = 0; i < 1e4; ++i) { | ||
let result = compareFunction({ length: 5}); | ||
if (result.isNull || result.isUndefined) | ||
debug("Failed warmup with compareFunction({ length: 5})."); | ||
|
||
let object = new Object; | ||
object.length = 1; | ||
result = compareFunction(object); | ||
if (result.isNull || result.isUndefined) | ||
debug("Failed warmup with compareFunction(object)."); | ||
} | ||
|
||
let documentAll = document.all; | ||
var documentAllCompare = compareFunction(documentAll); | ||
shouldBeTrue("documentAllCompare.isNull"); | ||
shouldBeTrue("documentAllCompare.isUndefined"); | ||
shouldBe("documentAllCompare.length", "13"); | ||
|
||
for (let i = 0; i < 1e3; ++i) { | ||
let result = compareFunction({ length: 5}); | ||
if (result.isNull || result.isUndefined) | ||
debug("Failed tail with compareFunction({ length: 5})."); | ||
|
||
result = compareFunction(documentAll); | ||
if (!result.isNull || !result.isUndefined) | ||
debug("Failed tail with compareFunction(documentAll)."); | ||
|
||
let object = new Object; | ||
object.length = 1; | ||
result = compareFunction(object); | ||
if (result.isNull || result.isUndefined) | ||
debug("Failed tail with compareFunction(object)."); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.