mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
fix invalid const optimization with multiplication
This commit is contained in:
parent
8e6b91cb9e
commit
806654fc44
@ -233,7 +233,10 @@ class ConstantFoldingOptimizer(private val program: Program, private val errors:
|
|||||||
}
|
}
|
||||||
else if(leftBinExpr.operator=="*" && rightBinExpr.operator=="*"){
|
else if(leftBinExpr.operator=="*" && rightBinExpr.operator=="*"){
|
||||||
if (c1 != null && c2 != null && c1==c2) {
|
if (c1 != null && c2 != null && c1==c2) {
|
||||||
//(X * C) <plusmin> (Y * C) => (X <plusmin> Y) * C
|
//(X * C) <plusmin> (Y * C) => (X <plusmin> Y) * C (only if types of X and Y are the same!)
|
||||||
|
val xDt = leftBinExpr.left.inferType(program)
|
||||||
|
val yDt = rightBinExpr.left.inferType(program)
|
||||||
|
if(xDt==yDt) {
|
||||||
val xwithy = BinaryExpression(leftBinExpr.left, expr.operator, rightBinExpr.left, expr.position)
|
val xwithy = BinaryExpression(leftBinExpr.left, expr.operator, rightBinExpr.left, expr.position)
|
||||||
val newExpr = BinaryExpression(xwithy, "*", c1, expr.position)
|
val newExpr = BinaryExpression(xwithy, "*", c1, expr.position)
|
||||||
modifications += IAstModification.ReplaceNode(expr, newExpr, parent)
|
modifications += IAstModification.ReplaceNode(expr, newExpr, parent)
|
||||||
@ -241,6 +244,7 @@ class ConstantFoldingOptimizer(private val program: Program, private val errors:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(rightconst!=null && (expr.operator=="<<" || expr.operator==">>")) {
|
if(rightconst!=null && (expr.operator=="<<" || expr.operator==">>")) {
|
||||||
val dt = expr.left.inferType(program)
|
val dt = expr.left.inferType(program)
|
||||||
|
Loading…
Reference in New Issue
Block a user