slightly optimized binexpr evaluation for ==/!= in some cases

This commit is contained in:
Irmen de Jong 2021-12-30 02:00:36 +01:00
parent 5d2dec1803
commit b62183adcb
3 changed files with 29 additions and 7 deletions

View File

@ -45,7 +45,7 @@ X = BinExpr X = LeftExpr
*/
if(binExpr.operator in AugmentAssignmentOperators && isSimpleTarget(assignment.target)) {
if(binExpr.operator in AugmentAssignmentOperators + listOf("==", "!=") && isSimpleTarget(assignment.target)) {
if(assignment.target isSameAs binExpr.right)
return noModifications
if(assignment.target isSameAs binExpr.left) {
@ -73,6 +73,15 @@ X = BinExpr X = LeftExpr
// )
}
if(binExpr.operator == "==" || binExpr.operator == "!=") {
// don't split if the operand(s) don't fit the type of the resulting variable
val targetDt = assignment.target.inferType(program)
val leftDt = binExpr.left.inferType(program)
val rightDt = binExpr.right.inferType(program)
if(leftDt isNotAssignableTo targetDt || rightDt isNotAssignableTo targetDt)
return noModifications
}
if(binExpr.right.isSimple) {
val firstAssign = Assignment(assignment.target.copy(), binExpr.left, binExpr.left.position)
val targetExpr = assignment.target.toExpression()

View File

@ -66,7 +66,10 @@ fun compileProgram(args: CompilerArguments): CompilationResult {
program = programresult
importedFiles = imported
processAst(program, args.errors, compilationOptions)
if (compilationOptions.optimize)
if (compilationOptions.optimize) {
// println("*********** AST RIGHT BEFORE OPTIMIZING *************")
// printProgram(program)
optimizeAst(
program,
compilationOptions,
@ -74,6 +77,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult {
BuiltinFunctionsFacade(BuiltinFunctions),
compTarget
)
}
postprocessAst(program, args.errors, compilationOptions)
// println("*********** AST BEFORE ASSEMBLYGEN *************")

View File

@ -5,12 +5,21 @@ main {
sub start() {
ubyte @shared xx
ubyte @shared yy
ubyte camg
ubyte @shared interlaced = (camg & $04) != 0
yy = xx
yy = yy==7
yy++
yy = xx==7
if xx==99 {
xx++
yy++
}
txt.nl()
yy++
; if xx==99 {
; xx++
; yy++
; }
; txt.nl()
}
}