tweak common subexpression optimization for array lookups

This commit is contained in:
Irmen de Jong 2024-01-07 22:37:15 +01:00
parent 37fa3b34a2
commit 4a4b6c04a1

View File

@ -25,10 +25,16 @@ private fun walkAst(root: PtNode, act: (node: PtNode, depth: Int) -> Boolean) {
private fun optimizeCommonSubExpressions(program: PtProgram, errors: IErrorReporter): Int {
fun extractableSubExpr(expr: PtExpression): Boolean {
return if(expr is PtBinaryExpression)
!expr.left.isSimple() || !expr.right.isSimple() || (expr.operator !in LogicalOperators && expr.operator !in BitwiseOperators)
val result = if(expr is PtBinaryExpression)
expr.type !in ByteDatatypes ||
!expr.left.isSimple() ||
!expr.right.isSimple() ||
(expr.operator !in LogicalOperators && expr.operator !in BitwiseOperators)
else if (expr is PtArrayIndexer && expr.type !in ByteDatatypes)
true
else
!expr.isSimple()
return result
}
// for each Binaryexpression, recurse to find a common subexpression pair therein.