mirror of
https://github.com/irmen/prog8.git
synced 2024-11-27 03:50:27 +00:00
reorder const for all associative operators
This commit is contained in:
parent
f40bcc219f
commit
ff54d6abd7
@ -415,8 +415,9 @@ internal class ConstantFoldingOptimizer(private val program: Program) : AstWalke
|
||||
// todo: this implements only a small set of possible reorderings at this time
|
||||
if(expr.operator==subExpr.operator) {
|
||||
// both operators are the same.
|
||||
// If + or *, we can simply shuffle the const operands around to optimize.
|
||||
if(expr.operator=="+" || expr.operator=="*") {
|
||||
|
||||
// If associative, we can simply shuffle the const operands around to optimize.
|
||||
if(expr.operator in associativeOperators) {
|
||||
return if(leftIsConst) {
|
||||
if(subleftIsConst)
|
||||
ShuffleOperands(expr, null, subExpr, subExpr.right, null, null, expr.left)
|
||||
|
@ -7,6 +7,20 @@ main {
|
||||
|
||||
sub start() {
|
||||
|
||||
ubyte ub
|
||||
uword uw
|
||||
word w
|
||||
byte b
|
||||
float f
|
||||
|
||||
|
||||
ub = 4 | ub | 2
|
||||
ub = ub | 2 | 7
|
||||
ub = 4 | 2 | ub
|
||||
|
||||
ub = 4 + ub + 2
|
||||
ub = ub + 2 + 7
|
||||
ub = 4 + 2 + ub
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user