revert restriction on certain associative operator reshuffling

it caused larger generated code
This commit is contained in:
Irmen de Jong 2022-07-02 12:27:20 +02:00
parent 24d13dd120
commit b2c9b7635d
3 changed files with 21 additions and 100 deletions

View File

@ -307,13 +307,12 @@ internal class StatementReorderer(val program: Program,
val newValue = BinaryExpression(leftBinExpr.left, binExpr.operator, newRight, binExpr.position) val newValue = BinaryExpression(leftBinExpr.left, binExpr.operator, newRight, binExpr.position)
listOf(IAstModification.ReplaceNode(binExpr, newValue, assignment)) listOf(IAstModification.ReplaceNode(binExpr, newValue, assignment))
} }
else if(leftBinExpr.left.constValue(program)!=null && binExpr.right.constValue(program)!=null) { else {
// A = (x <associative-operator> A) <same-operator> y ==> A = A <associative-operator> (x <same-operator> y) // A = (x <associative-operator> A) <same-operator> y ==> A = A <associative-operator> (x <same-operator> y)
val newRight = BinaryExpression(leftBinExpr.left, binExpr.operator, binExpr.right, binExpr.position) val newRight = BinaryExpression(leftBinExpr.left, binExpr.operator, binExpr.right, binExpr.position)
val newValue = BinaryExpression(leftBinExpr.right, binExpr.operator, newRight, binExpr.position) val newValue = BinaryExpression(leftBinExpr.right, binExpr.operator, newRight, binExpr.position)
listOf(IAstModification.ReplaceNode(binExpr, newValue, assignment)) listOf(IAstModification.ReplaceNode(binExpr, newValue, assignment))
} }
else noModifications
} }
val rightBinExpr = binExpr.right as? BinaryExpression val rightBinExpr = binExpr.right as? BinaryExpression
if(rightBinExpr?.operator == binExpr.operator) { if(rightBinExpr?.operator == binExpr.operator) {

View File

@ -3,22 +3,12 @@ TODO
For next release For next release
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
- petaxian roller.p8 line 49 (also see test.p8) generates large code compared to 8.2 - logical.p8 is huge compared to 8.2
- code gen for if statements has become inefficient? vm/6502? - compiling logical.p8 to virtual with optimization generates code that is smaller,
if not a or not b but takes many more vm instructions to execute than not-optimized code!?
return 0
- code gen for while loops has become inefficient: (until loops probably as well)
(maybe solved when if statements code has been fixed)
while c64.CHRIN()!='\"' {
if c64.READST()
goto close_end
}
- petaxian.prg became quite a bit (200 bytes) larger, why!? because of the above? - petaxian.prg became quite a bit (150 bytes) larger since 8.2, what causes that
- compiling logical.p8 to virtual with optimization generates a lot larger code as without optimizations.
this is not the case for the 6502 codegen.
- add some more optimizations in vmPeepholeOptimizer - add some more optimizations in vmPeepholeOptimizer
- vm Instruction needs to know what the read-registers/memory are, and what the write-register/memory is. - vm Instruction needs to know what the read-registers/memory are, and what the write-register/memory is.

View File

@ -7,90 +7,22 @@ main {
sub start() { sub start() {
ubyte a1 = 0 ; a "pixelshader":
uword w1 = 0 sys.gfx_enable(0) ; enable lo res screen
ubyte vv ubyte shifter
if not a1 repeat {
txt.print("ok ") uword xx
else uword yy = 0
txt.print("fail ") repeat 240 {
vv = not a1 xx = 0
txt.print_ub(vv) repeat 320 {
txt.nl() sys.gfx_plot(xx, yy, xx*yy + shifter as ubyte)
a1=128 xx++
if not a1 }
txt.print("fail ") yy++
else }
txt.print("ok ") shifter+=4
vv = not a1 }
txt.print_ub(vv)
txt.nl()
if not w1
txt.print("ok ")
else
txt.print("fail ")
vv = not w1
txt.print_ub(vv)
txt.nl()
w1 = 4096
if not w1
txt.print("fail ")
else
txt.print("ok ")
vv = not w1
txt.print_ub(vv)
txt.nl()
; petaxian roller.p8 line 49
; super large in new version, ok in 8.2....
; TODO cx16.r0 = a2 + 25 + (a1/40)
; txt.setcc( a1, a2 + 25 + (a1/40), 11,22)
; if a1 and a2 {
; a1++
; }
;
; if not a1 or not a2 {
; a1++
; }
;
; if a1!=99 and not a2 {
; a1++
; }
; while a1 != a2 {
; a1++
; }
;
; while a1!='\"' {
; a1++
; }
; do {
; a1++
; } until a1==99
;
;close_end:
; a1++
; ; a "pixelshader":
; sys.gfx_enable(0) ; enable lo res screen
; ubyte shifter
;
; repeat {
; uword xx
; uword yy = 0
; repeat 240 {
; xx = 0
; repeat 320 {
; sys.gfx_plot(xx, yy, xx*yy + shifter as ubyte)
; xx++
; }
; yy++
; }
; shifter+=4
; }
} }
} }