
CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  main::i#0 = 0
  to:main::@1
main::@1: scope:[main]  from main main::@1
  main::i#2 = phi( main/main::i#0, main::@1/main::i#1 )
  main::$0 = main::i#2 + 1
  main::SCREEN[main::i#2] = main::SCREEN[main::$0]
  main::$1 = main::SCREEN + $28
  main::$2 = main::SCREEN + $28
  main::$3 = main::i#2 + 1
  main::$1[main::i#2] = main::$2[main::$3]
  main::$4 = main::SCREEN + $50
  main::$5 = main::SCREEN + $50
  main::$6 = main::i#2 + 1
  main::$4[main::i#2] = main::$5[main::$6]
  main::$7 = main::SCREEN + $78
  main::$8 = main::SCREEN + $78
  main::$9 = main::i#2 + 1
  main::$7[main::i#2] = main::$8[main::$9]
  main::i#1 = main::i#2 + rangenext(0,$26)
  main::$10 = main::i#1 != rangelast(0,$26)
  if(main::$10) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  return 
  to:@return

void __start()
__start: scope:[__start]  from
  call main
  to:__start::@1
__start::@1: scope:[__start]  from __start
  to:__start::@return
__start::@return: scope:[__start]  from __start::@1
  return 
  to:@return

SYMBOL TABLE SSA
void __start()
void main()
number main::$0
char *main::$1
bool main::$10
char *main::$2
number main::$3
char *main::$4
char *main::$5
number main::$6
char *main::$7
char *main::$8
number main::$9
__constant char *main::SCREEN = (char *)$400
char main::i
char main::i#0
char main::i#1
char main::i#2

Adding number conversion cast (unumber) 1 in main::$0 = main::i#2 + 1
Adding number conversion cast (unumber) main::$0 in main::$0 = main::i#2 + (unumber)1
Adding number conversion cast (unumber) $28 in main::$1 = main::SCREEN + $28
Adding number conversion cast (unumber) $28 in main::$2 = main::SCREEN + $28
Adding number conversion cast (unumber) 1 in main::$3 = main::i#2 + 1
Adding number conversion cast (unumber) main::$3 in main::$3 = main::i#2 + (unumber)1
Adding number conversion cast (unumber) $50 in main::$4 = main::SCREEN + $50
Adding number conversion cast (unumber) $50 in main::$5 = main::SCREEN + $50
Adding number conversion cast (unumber) 1 in main::$6 = main::i#2 + 1
Adding number conversion cast (unumber) main::$6 in main::$6 = main::i#2 + (unumber)1
Adding number conversion cast (unumber) $78 in main::$7 = main::SCREEN + $78
Adding number conversion cast (unumber) $78 in main::$8 = main::SCREEN + $78
Adding number conversion cast (unumber) 1 in main::$9 = main::i#2 + 1
Adding number conversion cast (unumber) main::$9 in main::$9 = main::i#2 + (unumber)1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 1
Simplifying constant integer cast $28
Simplifying constant integer cast $28
Simplifying constant integer cast 1
Simplifying constant integer cast $50
Simplifying constant integer cast $50
Simplifying constant integer cast 1
Simplifying constant integer cast $78
Simplifying constant integer cast $78
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) $28
Finalized unsigned number type (char) $28
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) $50
Finalized unsigned number type (char) $50
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) $78
Finalized unsigned number type (char) $78
Finalized unsigned number type (char) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to char in main::$0 = main::i#2 + 1
Inferred type updated to char in main::$3 = main::i#2 + 1
Inferred type updated to char in main::$6 = main::i#2 + 1
Inferred type updated to char in main::$9 = main::i#2 + 1
Simple Condition main::$10 [18] if(main::i#1!=rangelast(0,$26)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [4] main::$1 = main::SCREEN + $28
Constant right-side identified [5] main::$2 = main::SCREEN + $28
Constant right-side identified [8] main::$4 = main::SCREEN + $50
Constant right-side identified [9] main::$5 = main::SCREEN + $50
Constant right-side identified [12] main::$7 = main::SCREEN + $78
Constant right-side identified [13] main::$8 = main::SCREEN + $78
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant main::i#0 = 0
Constant main::$1 = main::SCREEN+$28
Constant main::$2 = main::SCREEN+$28
Constant main::$4 = main::SCREEN+$50
Constant main::$5 = main::SCREEN+$50
Constant main::$7 = main::SCREEN+$78
Constant main::$8 = main::SCREEN+$78
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [16] main::i#1 = ++ main::i#2 to ++
Resolved ranged comparison value [18] if(main::i#1!=rangelast(0,$26)) goto main::@1 to $27
Removing unused procedure __start
Removing unused procedure block __start
Removing unused procedure block __start::@1
Removing unused procedure block __start::@return
Successful SSA optimization PassNEliminateEmptyStart
Adding number conversion cast (unumber) $27 in [10] if(main::i#1!=$27) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $27
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $27
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings main::i#0
Constant inlined main::$1 = main::SCREEN+$28
Constant inlined main::$2 = main::SCREEN+$28
Constant inlined main::$5 = main::SCREEN+$50
Constant inlined main::i#0 = 0
Constant inlined main::$4 = main::SCREEN+$50
Constant inlined main::$7 = main::SCREEN+$78
Constant inlined main::$8 = main::SCREEN+$78
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in assignment (main::SCREEN+1)[main::$0]
Consolidated array index constant in assignment (main::SCREEN+$28+1)[main::$3]
Consolidated array index constant in assignment (main::SCREEN+$50+1)[main::$6]
Consolidated array index constant in assignment (main::SCREEN+$78+1)[main::$9]
Successful SSA optimization Pass2ConstantAdditionElimination
Alias main::i#2 = main::$0 main::$3 main::$6 main::$9 
Successful SSA optimization Pass2AliasElimination
Added new block during phi lifting main::@2(between main::@1 and main::@1)
Adding NOP phi() at start of main
CALL GRAPH

Created 1 initial phi equivalence classes
Coalesced [9] main::i#3 = main::i#1
Coalesced down to 1 phi equivalence classes
Culled Empty Block label main::@2
Adding NOP phi() at start of main

FINAL CONTROL FLOW GRAPH

void main()
main: scope:[main]  from
  [0] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@1
  [1] main::i#2 = phi( main/0, main::@1/main::i#1 )
  [2] main::SCREEN[main::i#2] = (main::SCREEN+1)[main::i#2]
  [3] (main::SCREEN+$28)[main::i#2] = (main::SCREEN+$28+1)[main::i#2]
  [4] (main::SCREEN+$50)[main::i#2] = (main::SCREEN+$50+1)[main::i#2]
  [5] (main::SCREEN+$78)[main::i#2] = (main::SCREEN+$78+1)[main::i#2]
  [6] main::i#1 = ++ main::i#2
  [7] if(main::i#1!=$27) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [8] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
char main::i
char main::i#1 // 16.5
char main::i#2 // 21.999999999999996

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [2] main::SCREEN[main::i#2] = (main::SCREEN+1)[main::i#2] [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::i#2 main::i#1 ]
Statement [3] (main::SCREEN+$28)[main::i#2] = (main::SCREEN+$28+1)[main::i#2] [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Statement [4] (main::SCREEN+$50)[main::i#2] = (main::SCREEN+$50+1)[main::i#2] [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Statement [5] (main::SCREEN+$78)[main::i#2] = (main::SCREEN+$78+1)[main::i#2] [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Statement [2] main::SCREEN[main::i#2] = (main::SCREEN+1)[main::i#2] [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Statement [3] (main::SCREEN+$28)[main::i#2] = (main::SCREEN+$28+1)[main::i#2] [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Statement [4] (main::SCREEN+$50)[main::i#2] = (main::SCREEN+$50+1)[main::i#2] [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Statement [5] (main::SCREEN+$78)[main::i#2] = (main::SCREEN+$78+1)[main::i#2] [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:2 [ main::i#2 main::i#1 ] : zp[1]:2 , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 38.5: zp[1]:2 [ main::i#2 main::i#1 ] 
Uplift Scope [] 

Uplifting [main] best 561 combination reg byte x [ main::i#2 main::i#1 ] 
Uplifting [] best 561 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// A sub-expression that should not be optimized (+1 to a pointer)
  // Upstart
  // Commodore 64 PRG executable file
.file [name="subexpr-optimize-1.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
.segment Code
  // main
main: {
    .label SCREEN = $400
    // [1] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    jmp __b1
    // [1] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  __b1_from___b1:
    // [1] phi main::i#2 = main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [2] main::SCREEN[main::i#2] = (main::SCREEN+1)[main::i#2] -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx 
    lda SCREEN+1,x
    sta SCREEN,x
    // [3] (main::SCREEN+$28)[main::i#2] = (main::SCREEN+$28+1)[main::i#2] -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx 
    lda SCREEN+$28+1,x
    sta SCREEN+$28,x
    // [4] (main::SCREEN+$50)[main::i#2] = (main::SCREEN+$50+1)[main::i#2] -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx 
    lda SCREEN+$50+1,x
    sta SCREEN+$50,x
    // [5] (main::SCREEN+$78)[main::i#2] = (main::SCREEN+$78+1)[main::i#2] -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx 
    lda SCREEN+$78+1,x
    sta SCREEN+$78,x
    // [6] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [7] if(main::i#1!=$27) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$27
    bne __b1_from___b1
    jmp __breturn
    // main::@return
  __breturn:
    // [8] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp __b1
Removing instruction jmp __breturn
Succesful ASM optimization Pass5NextJumpElimination
Replacing label __b1_from___b1 with __b1
Removing instruction __b1_from___b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction __b1_from_main:
Removing instruction __breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Removing instruction jmp __b1
Succesful ASM optimization Pass5NextJumpElimination

FINAL SYMBOL TABLE
void main()
__constant char *main::SCREEN = (char *) 1024
char main::i
char main::i#1 // reg byte x 16.5
char main::i#2 // reg byte x 21.999999999999996

reg byte x [ main::i#2 main::i#1 ]


FINAL ASSEMBLER
Score: 471

  // File Comments
// A sub-expression that should not be optimized (+1 to a pointer)
  // Upstart
  // Commodore 64 PRG executable file
.file [name="subexpr-optimize-1.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
  // Global Constants & labels
.segment Code
  // main
main: {
    .label SCREEN = $400
    // [1] phi from main to main::@1 [phi:main->main::@1]
    // [1] phi main::i#2 = 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 
    ldx #0
    // [1] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
    // [1] phi main::i#2 = main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // SCREEN[i] = SCREEN[i+1]
    // [2] main::SCREEN[main::i#2] = (main::SCREEN+1)[main::i#2] -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx 
    lda SCREEN+1,x
    sta SCREEN,x
    // (SCREEN+40)[i] = (SCREEN+40)[i+1]
    // [3] (main::SCREEN+$28)[main::i#2] = (main::SCREEN+$28+1)[main::i#2] -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx 
    lda SCREEN+$28+1,x
    sta SCREEN+$28,x
    // (SCREEN+80)[i] = (SCREEN+80)[i+1]
    // [4] (main::SCREEN+$50)[main::i#2] = (main::SCREEN+$50+1)[main::i#2] -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx 
    lda SCREEN+$50+1,x
    sta SCREEN+$50,x
    // (SCREEN+120)[i] = (SCREEN+120)[i+1]
    // [5] (main::SCREEN+$78)[main::i#2] = (main::SCREEN+$78+1)[main::i#2] -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx 
    lda SCREEN+$78+1,x
    sta SCREEN+$78,x
    // for(byte i: 0..38)
    // [6] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [7] if(main::i#1!=$27) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$27
    bne __b1
    // main::@return
    // }
    // [8] return 
    rts
}
  // File Data

