Skip to content

Commit 59be588

Browse files
committed
Add optimization case for simple assignations to temporaries.
1 parent ed5740e commit 59be588

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

src/Jitter_Optimize.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,29 @@ bool CJitter::CopyPropagation(StatementList& statements)
12841284
innerStatement.jmpCondition = outerStatement.jmpCondition;
12851285
changed = true;
12861286
}
1287+
//Substitute src operand of a statement if our defining statement (outerStatement) is a OP_MOV
1288+
//Example:
1289+
//outerDstSymbol -> t0
1290+
//Before:
1291+
// - t0 = r0
1292+
// - r1 = t0 & r2
1293+
//After:
1294+
// - t0 = r0
1295+
// - r1 = r0 & r2
1296+
//After substitution, t0 will not be used anymore making outerStatement eligible for removal
1297+
else if(outerStatement.op == OP_MOV)
1298+
{
1299+
auto replacementSym = outerStatement.src1;
1300+
innerStatement.VisitSources(
1301+
[&](SymbolRefPtr& symbol, bool) {
1302+
if(symbol->Equals(outerDstSymbol))
1303+
{
1304+
symbol = replacementSym;
1305+
changed = true;
1306+
}
1307+
});
1308+
assert(changed);
1309+
}
12871310
//Find all the add/sub constant and add them together
12881311
//Example
12891312
//outerDstSymbol -> t0

0 commit comments

Comments
 (0)