Skip to content

Commit 76bb84e

Browse files
committed
Merge pull request #3080 from rfk/rfk/fix-native-registerize-harder
Fix input-register-conflict checking in native registerizeHarder
2 parents 7fd7898 + 20aafad commit 76bb84e

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

tools/js-optimizer.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2879,7 +2879,7 @@ function registerizeHarder(ast) {
28792879

28802880
// Traverse the tree in execution order and synthesize a basic flow-graph.
28812881
// It's convenient to build a kind of "dual" graph where the nodes identify
2882-
// the junctions between blocks at which control-flow may branch, and each
2882+
// the junctions between blocks at which control-flow may branch, and each
28832883
// basic block is an edge connecting two such junctions.
28842884
// For each junction we store:
28852885
// * set of blocks that originate at the junction
@@ -2977,9 +2977,9 @@ function registerizeHarder(ast) {
29772977
}
29782978

29792979
function markNonLocalJump(type, label) {
2980-
// Complete a block via 'return', 'break' or 'continue'.
2980+
// Complete a block via 'return', 'break' or 'continue'.
29812981
// This joins the targetted junction and then sets the current junction to null.
2982-
// Any code traversed before we get back an existing junction is dead code.
2982+
// Any code traversed before we get back to an existing junction is dead code.
29832983
if (type === 'return') {
29842984
joinJunction(EXIT_JUNCTION);
29852985
} else {
@@ -3850,7 +3850,7 @@ function registerizeHarder(ast) {
38503850
}
38513851
}
38523852
}
3853-
// If we managed to create an "x=x" assignments, remove them.
3853+
// If we managed to create any "x=x" assignments, remove them.
38543854
for (var j = 0; j < maybeRemoveNodes.length; j++) {
38553855
var node = maybeRemoveNodes[j][1];
38563856
if (node[2][1] === node[3][1]) {

tools/optimizer/optimizer.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -2512,7 +2512,7 @@ void registerizeHarder(Ref ast) {
25122512

25132513
// Traverse the tree in execution order and synthesize a basic flow-graph.
25142514
// It's convenient to build a kind of "dual" graph where the nodes identify
2515-
// the junctions between blocks at which control-flow may branch, and each
2515+
// the junctions between blocks at which control-flow may branch, and each
25162516
// basic block is an edge connecting two such junctions.
25172517
// For each junction we store:
25182518
// * set of blocks that originate at the junction
@@ -2646,9 +2646,9 @@ void registerizeHarder(Ref ast) {
26462646
};
26472647

26482648
auto markNonLocalJump = [&](IString type, IString label) {
2649-
// Complete a block via RETURN, BREAK or CONTINUE.
2649+
// Complete a block via RETURN, BREAK or CONTINUE.
26502650
// This joins the targetted junction and then sets the current junction to null.
2651-
// Any code traversed before we get back an existing junction is dead code.
2651+
// Any code traversed before we get back to an existing junction is dead code.
26522652
if (type == RETURN) {
26532653
joinJunction(EXIT_JUNCTION, false);
26542654
} else {
@@ -3467,9 +3467,11 @@ void registerizeHarder(Ref ast) {
34673467
for (int k = freeRegs.size() - 1; k >= 0; k--) {
34683468
reg = freeRegs[k];
34693469
// Check for conflict with input registers.
3470-
if (block->firstKillLoc[name] <= inputDeadLoc[reg]) {
3471-
if (name != inputVarsByReg[reg]) {
3472-
continue;
3470+
if (inputDeadLoc.count(reg) > 0) {
3471+
if (block->firstKillLoc[name] <= inputDeadLoc[reg]) {
3472+
if (name != inputVarsByReg[reg]) {
3473+
continue;
3474+
}
34733475
}
34743476
}
34753477
// Found one!
@@ -3497,7 +3499,7 @@ void registerizeHarder(Ref ast) {
34973499
}
34983500
}
34993501
}
3500-
// If we managed to create an "x=x" assignments, remove them.
3502+
// If we managed to create any "x=x" assignments, remove them.
35013503
for (int j = 0; j < maybeRemoveNodes.size(); j++) {
35023504
Ref node = maybeRemoveNodes[j].second;
35033505
if (node[2][1] == node[3][1]) {

tools/test-js-optimizer-asm-regs-harder-output2.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ function _doit(i2, i3, i1) {
1313
i2 = i2 | 0;
1414
i3 = i3 | 0;
1515
i1 = i1 | 0;
16-
var i4 = 0;
17-
i4 = STACKTOP;
16+
i2 = STACKTOP;
1817
_printf(__str | 0, (tempInt = STACKTOP, STACKTOP = STACKTOP + 8 | 0, HEAP32[(tempInt & 16777215) >> 2] = i3, HEAP32[(tempInt + 4 & 16777215) >> 2] = i1, tempInt));
19-
STACKTOP = i4;
18+
STACKTOP = i2;
2019
return 0 | 0;
2120
}
2221

0 commit comments

Comments
 (0)