asmoptimizer that removes redundant branches on boolean in A

This commit is contained in:
Irmen de Jong 2024-03-05 20:19:13 +01:00
parent 9826d7c494
commit 9f1bd2d7d6
3 changed files with 19 additions and 16 deletions

View File

@ -540,6 +540,24 @@ private fun optimizeJsrRtsAndOtherCombinations(linesByFour: Sequence<List<Indexe
mods += Modification(lines[3].index, true, null)
}
}
/*
beq +
lda #1
+
beq label_xxxx_shortcut / bne label_xxxx_shortcut
or *_afterif labels.
This gets generated after certain if conditions, and only the branch instruction is needed in these cases.
*/
if(tfirst=="beq +" && tsecond=="lda #1" && tthird=="+") {
if((tfourth.startsWith("beq label_") || tfourth.startsWith("bne label_")) && (tfourth.endsWith("_shortcut") || tfourth.endsWith("_afterif"))) {
mods.add(Modification(lines[0].index, true, null))
mods.add(Modification(lines[1].index, true, null))
mods.add(Modification(lines[2].index, true, null))
}
}
}
return mods
}

View File

@ -1396,6 +1396,7 @@ internal class AssignmentAsmGen(private val program: PtProgram,
// non short-circuit evaluation is *likely* shorter and faster because of the simple operands.
assignResultIntoA(expr.right, expr.operator, expr.left)
} else {
// non short-circuit evaluation is *likely* shorter and faster because of the simple operands.
assignResultIntoA(expr.left, expr.operator, expr.right)
}

View File

@ -1,22 +1,6 @@
TODO
====
the not changed (master branch) Petaxian compiled with -nostrictbool is a lot smaller than the updated (boolean branch) compiled without.
What is the difference! ...:
beq +
lda #1
[possibly another label here]
+ beq label_xxxx_shortcut / bne label_xxxx_shortcut
or *_afterif labels.
if x>=GUN_MAX_RIGHT and not leftmost ; uses many Scratch vars ...
...
--> add more special cases for PrefixExpression "not" to IfElseAsmgen? AssignmentAsmgen?
===== ====== =======
VM 6502 what