
CONTROL FLOW GRAPH SSA

void main()
main: scope:[main]  from __start
  main::b#0 = 0
  to:main::@1
main::@1: scope:[main]  from main main::@1
  main::b#2 = phi( main/main::b#0, main::@1/main::b#1 )
  main::$0 = $55 << main::b#2
  main::screen[main::b#2] = main::$0
  main::b#1 = main::b#2 + rangenext(0,7)
  main::$1 = main::b#1 != rangelast(0,7)
  if(main::$1) 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
bool main::$1
char main::b
char main::b#0
char main::b#1
char main::b#2
__constant char *main::screen = (char *)$400

Adding number conversion cast (unumber) $55 in main::$0 = $55 << main::b#2
Adding number conversion cast (unumber) main::$0 in main::$0 = (unumber)$55 << main::b#2
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast $55
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $55
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to char in main::$0 = $55 << main::b#2
Simple Condition main::$1 [6] if(main::b#1!=rangelast(0,7)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::b#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [4] main::b#1 = ++ main::b#2 to ++
Resolved ranged comparison value [6] if(main::b#1!=rangelast(0,7)) goto main::@1 to 8
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) 8 in [4] if(main::b#1!=8) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 8
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 8
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings main::b#0
Constant inlined main::b#0 = 0
Successful SSA optimization Pass2ConstantInlining
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 [7] main::b#3 = main::b#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::b#2 = phi( main/0, main::@1/main::b#1 )
  [2] main::$0 = $55 << main::b#2
  [3] main::screen[main::b#2] = main::$0
  [4] main::b#1 = ++ main::b#2
  [5] if(main::b#1!=8) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [6] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
char main::$0 // 22.0
char main::b
char main::b#1 // 16.5
char main::b#2 // 14.666666666666666

Initial phi equivalence classes
[ main::b#2 main::b#1 ]
Added variable main::$0 to live range equivalence class [ main::$0 ]
Complete equivalence classes
[ main::b#2 main::b#1 ]
[ main::$0 ]
Allocated zp[1]:2 [ main::b#2 main::b#1 ]
Allocated zp[1]:3 [ main::$0 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [2] main::$0 = $55 << main::b#2 [ main::b#2 main::$0 ] (  [ main::b#2 main::$0 ] { }  ) always clobbers reg byte a 
Removing always clobbered register reg byte a as potential for zp[1]:2 [ main::b#2 main::b#1 ]
Statement [2] main::$0 = $55 << main::b#2 [ main::b#2 main::$0 ] (  [ main::b#2 main::$0 ] { }  ) always clobbers reg byte a 
Potential registers zp[1]:2 [ main::b#2 main::b#1 ] : zp[1]:2 , reg byte x , reg byte y , 
Potential registers zp[1]:3 [ main::$0 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 31.17: zp[1]:2 [ main::b#2 main::b#1 ] 22: zp[1]:3 [ main::$0 ] 
Uplift Scope [] 

Uplifting [main] best 511 combination zp[1]:2 [ main::b#2 main::b#1 ] reg byte a [ main::$0 ] 
Uplifting [] best 511 combination 
Attempting to uplift remaining variables inzp[1]:2 [ main::b#2 main::b#1 ]
Uplifting [main] best 511 combination zp[1]:2 [ main::b#2 main::b#1 ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Rolling constants by a variable amount
  // Upstart
  // Commodore 64 PRG executable file
.file [name="roll-variable.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
    .label b = 2
    // [1] phi from main to main::@1 [phi:main->main::@1]
  __b1_from_main:
    // [1] phi main::b#2 = 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z b
    jmp __b1
    // [1] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  __b1_from___b1:
    // [1] phi main::b#2 = main::b#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp __b1
    // main::@1
  __b1:
    // [2] main::$0 = $55 << main::b#2 -- vbuaa=vbuc1_rol_vbuz1 
    lda #$55
    ldy.z b
    cpy #0
    beq !e+
  !:
    asl
    dey
    bne !-
  !e:
    // [3] main::screen[main::b#2] = main::$0 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy.z b
    sta screen,y
    // [4] main::b#1 = ++ main::b#2 -- vbuz1=_inc_vbuz1 
    inc.z b
    // [5] if(main::b#1!=8) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #8
    cmp.z b
    bne __b1_from___b1
    jmp __breturn
    // main::@return
  __breturn:
    // [6] 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()
char main::$0 // reg byte a 22.0
char main::b
char main::b#1 // b zp[1]:2 16.5
char main::b#2 // b zp[1]:2 14.666666666666666
__constant char *main::screen = (char *) 1024

zp[1]:2 [ main::b#2 main::b#1 ]
reg byte a [ main::$0 ]


FINAL ASSEMBLER
Score: 421

  // File Comments
// Rolling constants by a variable amount
  // Upstart
  // Commodore 64 PRG executable file
.file [name="roll-variable.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
    .label b = 2
    // [1] phi from main to main::@1 [phi:main->main::@1]
    // [1] phi main::b#2 = 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 
    lda #0
    sta.z b
    // [1] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
    // [1] phi main::b#2 = main::b#1 [phi:main::@1->main::@1#0] -- register_copy 
    // main::@1
  __b1:
    // $55 << b
    // [2] main::$0 = $55 << main::b#2 -- vbuaa=vbuc1_rol_vbuz1 
    lda #$55
    ldy.z b
    cpy #0
    beq !e+
  !:
    asl
    dey
    bne !-
  !e:
    // screen[b] = $55 << b
    // [3] main::screen[main::b#2] = main::$0 -- pbuc1_derefidx_vbuz1=vbuaa 
    ldy.z b
    sta screen,y
    // for( byte b: 0..7)
    // [4] main::b#1 = ++ main::b#2 -- vbuz1=_inc_vbuz1 
    inc.z b
    // [5] if(main::b#1!=8) goto main::@1 -- vbuz1_neq_vbuc1_then_la1 
    lda #8
    cmp.z b
    bne __b1
    // main::@return
    // }
    // [6] return 
    rts
}
  // File Data

