Eliminating unused variable with no statement main::$4

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+0*$28)[main::i#2] = main::$0
  main::$1 = main::i#2 * 2
  (main::SCREEN+1*$28)[main::i#2] = main::$1
  main::$2 = main::i#2 * 4
  (main::SCREEN+2*$28)[main::i#2] = main::$2
  main::$3 = main::i#2 * 8
  (main::SCREEN+3*$28)[main::i#2] = main::$3
  main::sb#0 = - (signed char)main::i#2
  main::$5 = main::sb#0 * 2
  (main::SCREEN+5*$28)[main::i#2] = (char)main::$5
  main::i#1 = main::i#2 + rangenext(0,$a)
  main::$6 = main::i#1 != rangelast(0,$a)
  if(main::$6) 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
number main::$1
number main::$2
number main::$3
number main::$5
bool main::$6
__constant char * const main::SCREEN = (char *)$400
char main::i
char main::i#0
char main::i#1
char main::i#2
signed char main::sb
signed char main::sb#0

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) 0*$28 in (main::SCREEN+0*$28)[main::i#2] = main::$0
Adding number conversion cast (unumber) 2 in main::$1 = main::i#2 * 2
Adding number conversion cast (unumber) main::$1 in main::$1 = main::i#2 * (unumber)2
Adding number conversion cast (unumber) 1*$28 in (main::SCREEN+1*$28)[main::i#2] = main::$1
Adding number conversion cast (unumber) 4 in main::$2 = main::i#2 * 4
Adding number conversion cast (unumber) main::$2 in main::$2 = main::i#2 * (unumber)4
Adding number conversion cast (unumber) 2*$28 in (main::SCREEN+2*$28)[main::i#2] = main::$2
Adding number conversion cast (unumber) 8 in main::$3 = main::i#2 * 8
Adding number conversion cast (unumber) main::$3 in main::$3 = main::i#2 * (unumber)8
Adding number conversion cast (unumber) 3*$28 in (main::SCREEN+3*$28)[main::i#2] = main::$3
Adding number conversion cast (snumber) 2 in main::$5 = main::sb#0 * 2
Adding number conversion cast (snumber) main::$5 in main::$5 = main::sb#0 * (snumber)2
Adding number conversion cast (unumber) 5*$28 in (main::SCREEN+5*$28)[main::i#2] = (char)main::$5
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant pointer cast (char *) 1024
Simplifying constant integer cast 1
Simplifying constant integer cast 2
Simplifying constant integer cast 4
Simplifying constant integer cast 8
Simplifying constant integer cast 2
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) 2
Finalized unsigned number type (char) 4
Finalized unsigned number type (char) 8
Finalized signed number type (signed char) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to char in main::$0 = main::i#2 * 1
Inferred type updated to char in main::$1 = main::i#2 * 2
Inferred type updated to char in main::$2 = main::i#2 * 4
Inferred type updated to char in main::$3 = main::i#2 * 8
Inferred type updated to signed char in main::$5 = main::sb#0 * 2
Simple Condition main::$6 [15] if(main::i#1!=rangelast(0,$a)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [13] main::i#1 = ++ main::i#2 to ++
Resolved ranged comparison value [15] if(main::i#1!=rangelast(0,$a)) goto main::@1 to $b
Simplifying constant evaluating to zero (char)0*$28 in [3] (main::SCREEN+(char)0*$28)[main::i#2] = main::$0
Successful SSA optimization PassNSimplifyConstantZero
Simplifying expression containing zero main::SCREEN in [3] (main::SCREEN+0)[main::i#2] = main::$0
Successful SSA optimization PassNSimplifyExpressionWithZero
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) $b in [13] if(main::i#1!=$b) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast $b
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (char) $b
Successful SSA optimization PassNFinalizeNumberTypeConversions
Rewriting multiplication to remove identity multiply [1] main::$0 = main::i#2 * 1
Rewriting multiplication to use shift [3] main::$1 = main::i#2 * 2
Rewriting multiplication to use shift [5] main::$2 = main::i#2 * 4
Rewriting multiplication to use shift [7] main::$3 = main::i#2 * 8
Rewriting multiplication to use shift [10] main::$5 = main::sb#0 * 2
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings main::i#0
Constant inlined main::i#0 = 0
Successful SSA optimization Pass2ConstantInlining
Alias main::i#2 = main::$0 
Successful SSA optimization Pass2AliasElimination
Finalized unsigned number type (char) 1
Finalized unsigned number type (char) $28
Finalized unsigned number type (char) 2
Finalized unsigned number type (char) $28
Finalized unsigned number type (char) 3
Finalized unsigned number type (char) $28
Finalized unsigned number type (char) 5
Finalized unsigned number type (char) $28
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simplifying constant integer cast 1*$28
Simplifying constant integer cast 2*$28
Simplifying constant integer cast 3*$28
Simplifying constant integer cast 5*$28
Successful SSA optimization PassNCastSimplification
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 [15] 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::i#2
  [3] main::$1 = main::i#2 << 1
  [4] (main::SCREEN+1*$28)[main::i#2] = main::$1
  [5] main::$2 = main::i#2 << 2
  [6] (main::SCREEN+2*$28)[main::i#2] = main::$2
  [7] main::$3 = main::i#2 << 3
  [8] (main::SCREEN+3*$28)[main::i#2] = main::$3
  [9] main::sb#0 = - (signed char)main::i#2
  [10] main::$5 = main::sb#0 << 1
  [11] (main::SCREEN+5*$28)[main::i#2] = (char)main::$5
  [12] main::i#1 = ++ main::i#2
  [13] if(main::i#1!=$b) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [14] return 
  to:@return


VARIABLE REGISTER WEIGHTS
void main()
char main::$1 // 22.0
char main::$2 // 22.0
char main::$3 // 22.0
signed char main::$5 // 11.0
char main::i
char main::i#1 // 16.5
char main::i#2 // 11.0
signed char main::sb
signed char main::sb#0 // 22.0

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
Added variable main::$1 to live range equivalence class [ main::$1 ]
Added variable main::$2 to live range equivalence class [ main::$2 ]
Added variable main::$3 to live range equivalence class [ main::$3 ]
Added variable main::sb#0 to live range equivalence class [ main::sb#0 ]
Added variable main::$5 to live range equivalence class [ main::$5 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::$1 ]
[ main::$2 ]
[ main::$3 ]
[ main::sb#0 ]
[ main::$5 ]
Allocated zp[1]:2 [ main::i#2 main::i#1 ]
Allocated zp[1]:3 [ main::$1 ]
Allocated zp[1]:4 [ main::$2 ]
Allocated zp[1]:5 [ main::$3 ]
Allocated zp[1]:6 [ main::sb#0 ]
Allocated zp[1]:7 [ main::$5 ]
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [3] main::$1 = main::i#2 << 1 [ main::i#2 main::$1 ] (  [ main::i#2 main::$1 ] { }  ) 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 [5] main::$2 = main::i#2 << 2 [ main::i#2 main::$2 ] (  [ main::i#2 main::$2 ] { }  ) always clobbers reg byte a 
Statement [7] main::$3 = main::i#2 << 3 [ main::i#2 main::$3 ] (  [ main::i#2 main::$3 ] { }  ) always clobbers reg byte a 
Statement [9] main::sb#0 = - (signed char)main::i#2 [ main::i#2 main::sb#0 ] (  [ main::i#2 main::sb#0 ] { }  ) always clobbers reg byte a 
Statement [10] main::$5 = main::sb#0 << 1 [ main::i#2 main::$5 ] (  [ main::i#2 main::$5 ] { }  ) always clobbers reg byte a 
Statement [2] main::SCREEN[main::i#2] = main::i#2 [ main::i#2 ] (  [ main::i#2 ] { }  ) always clobbers reg byte a 
Statement [3] main::$1 = main::i#2 << 1 [ main::i#2 main::$1 ] (  [ main::i#2 main::$1 ] { }  ) always clobbers reg byte a 
Statement [5] main::$2 = main::i#2 << 2 [ main::i#2 main::$2 ] (  [ main::i#2 main::$2 ] { }  ) always clobbers reg byte a 
Statement [7] main::$3 = main::i#2 << 3 [ main::i#2 main::$3 ] (  [ main::i#2 main::$3 ] { }  ) always clobbers reg byte a 
Statement [9] main::sb#0 = - (signed char)main::i#2 [ main::i#2 main::sb#0 ] (  [ main::i#2 main::sb#0 ] { }  ) always clobbers reg byte a 
Statement [10] main::$5 = main::sb#0 << 1 [ main::i#2 main::$5 ] (  [ main::i#2 main::$5 ] { }  ) 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 , 
Potential registers zp[1]:3 [ main::$1 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:4 [ main::$2 ] : zp[1]:4 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:5 [ main::$3 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:6 [ main::sb#0 ] : zp[1]:6 , reg byte a , reg byte x , reg byte y , 
Potential registers zp[1]:7 [ main::$5 ] : zp[1]:7 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 27.5: zp[1]:2 [ main::i#2 main::i#1 ] 22: zp[1]:3 [ main::$1 ] 22: zp[1]:4 [ main::$2 ] 22: zp[1]:5 [ main::$3 ] 22: zp[1]:6 [ main::sb#0 ] 11: zp[1]:7 [ main::$5 ] 
Uplift Scope [] 

Uplifting [main] best 851 combination reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$1 ] reg byte a [ main::$2 ] reg byte a [ main::$3 ] zp[1]:6 [ main::sb#0 ] zp[1]:7 [ main::$5 ] 
Limited combination testing to 100 combinations of 3072 possible.
Uplifting [] best 851 combination 
Attempting to uplift remaining variables inzp[1]:6 [ main::sb#0 ]
Uplifting [main] best 791 combination reg byte a [ main::sb#0 ] 
Attempting to uplift remaining variables inzp[1]:7 [ main::$5 ]
Uplifting [main] best 731 combination reg byte a [ main::$5 ] 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Check that multiplication by factors of 2 is converted to shifts
  // Upstart
  // Commodore 64 PRG executable file
.file [name="multiply-2s.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::i#2 -- pbuc1_derefidx_vbuxx=vbuxx 
    txa
    sta SCREEN,x
    // [3] main::$1 = main::i#2 << 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // [4] (main::SCREEN+1*$28)[main::i#2] = main::$1 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN+1*$28,x
    // [5] main::$2 = main::i#2 << 2 -- vbuaa=vbuxx_rol_2 
    txa
    asl
    asl
    // [6] (main::SCREEN+2*$28)[main::i#2] = main::$2 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN+2*$28,x
    // [7] main::$3 = main::i#2 << 3 -- vbuaa=vbuxx_rol_3 
    txa
    asl
    asl
    asl
    // [8] (main::SCREEN+3*$28)[main::i#2] = main::$3 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN+3*$28,x
    // [9] main::sb#0 = - (signed char)main::i#2 -- vbsaa=_neg_vbsxx 
    // And a single signed byte
    txa
    eor #$ff
    clc
    adc #1
    // [10] main::$5 = main::sb#0 << 1 -- vbsaa=vbsaa_rol_1 
    asl
    // [11] (main::SCREEN+5*$28)[main::i#2] = (char)main::$5 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN+5*$28,x
    // [12] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [13] if(main::i#1!=$b) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$b
    bne __b1_from___b1
    jmp __breturn
    // main::@return
  __breturn:
    // [14] 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::$1 // reg byte a 22.0
char main::$2 // reg byte a 22.0
char main::$3 // reg byte a 22.0
signed char main::$5 // reg byte a 11.0
__constant char * const main::SCREEN = (char *) 1024
char main::i
char main::i#1 // reg byte x 16.5
char main::i#2 // reg byte x 11.0
signed char main::sb
signed char main::sb#0 // reg byte a 22.0

reg byte x [ main::i#2 main::i#1 ]
reg byte a [ main::$1 ]
reg byte a [ main::$2 ]
reg byte a [ main::$3 ]
reg byte a [ main::sb#0 ]
reg byte a [ main::$5 ]


FINAL ASSEMBLER
Score: 641

  // File Comments
// Check that multiplication by factors of 2 is converted to shifts
  // Upstart
  // Commodore 64 PRG executable file
.file [name="multiply-2s.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+0*40)[i] = i*1
    // [2] main::SCREEN[main::i#2] = main::i#2 -- pbuc1_derefidx_vbuxx=vbuxx 
    txa
    sta SCREEN,x
    // i*2
    // [3] main::$1 = main::i#2 << 1 -- vbuaa=vbuxx_rol_1 
    txa
    asl
    // (SCREEN+1*40)[i] = i*2
    // [4] (main::SCREEN+1*$28)[main::i#2] = main::$1 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN+1*$28,x
    // i*4
    // [5] main::$2 = main::i#2 << 2 -- vbuaa=vbuxx_rol_2 
    txa
    asl
    asl
    // (SCREEN+2*40)[i] = i*4
    // [6] (main::SCREEN+2*$28)[main::i#2] = main::$2 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN+2*$28,x
    // i*8
    // [7] main::$3 = main::i#2 << 3 -- vbuaa=vbuxx_rol_3 
    txa
    asl
    asl
    asl
    // (SCREEN+3*40)[i] = i*8
    // [8] (main::SCREEN+3*$28)[main::i#2] = main::$3 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN+3*$28,x
    // signed byte sb = -(signed byte)i
    // [9] main::sb#0 = - (signed char)main::i#2 -- vbsaa=_neg_vbsxx 
    // And a single signed byte
    txa
    eor #$ff
    clc
    adc #1
    // sb*2
    // [10] main::$5 = main::sb#0 << 1 -- vbsaa=vbsaa_rol_1 
    asl
    // (SCREEN+5*40)[i] = (byte)(sb*2)
    // [11] (main::SCREEN+5*$28)[main::i#2] = (char)main::$5 -- pbuc1_derefidx_vbuxx=vbuaa 
    sta SCREEN+5*$28,x
    // for(byte i: 0..10)
    // [12] main::i#1 = ++ main::i#2 -- vbuxx=_inc_vbuxx 
    inx
    // [13] if(main::i#1!=$b) goto main::@1 -- vbuxx_neq_vbuc1_then_la1 
    cpx #$b
    bne __b1
    // main::@return
    // }
    // [14] return 
    rts
}
  // File Data

