Culled Empty Block (label) main::@2

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@1
main: scope:[main]  from @1
  (byte*) main::screen#0 ← ((byte*)) (number) $400
  (word) main::i#0 ← (number) 0
  to:main::@1
main::@1: scope:[main]  from main main::@1
  (word) main::i#2 ← phi( main/(word) main::i#0 main::@1/(word) main::i#1 )
  *((byte*) main::screen#0 + (word) main::i#2) ← (byte) 'a'
  (word) main::i#1 ← (word) main::i#2 + (number) $28
  (bool~) main::$0 ← (word) main::i#1 < (number) $3e8
  if((bool~) main::$0) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  return 
  to:@return
@1: scope:[]  from @begin
  call main 
  to:@2
@2: scope:[]  from @1
  to:@end
@end: scope:[]  from @2

SYMBOL TABLE SSA
(label) @1
(label) @2
(label) @begin
(label) @end
(void()) main()
(bool~) main::$0
(label) main::@1
(label) main::@return
(word) main::i
(word) main::i#0
(word) main::i#1
(word) main::i#2
(byte*) main::screen
(byte*) main::screen#0

Adding number conversion cast (unumber) 0 in (word) main::i#0 ← (number) 0
Adding number conversion cast (unumber) $28 in (word) main::i#1 ← (word) main::i#2 + (number) $28
Adding number conversion cast (unumber) $3e8 in (bool~) main::$0 ← (word) main::i#1 < (number) $3e8
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) main::screen#0 ← (byte*)(number) $400
Inlining cast (word) main::i#0 ← (unumber)(number) 0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast $28
Simplifying constant integer cast $3e8
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) $28
Finalized unsigned number type (word) $3e8
Successful SSA optimization PassNFinalizeNumberTypeConversions
Simple Condition (bool~) main::$0 [6] if((word) main::i#1<(word) $3e8) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) main::screen#0 = (byte*) 1024
Constant (const word) main::i#0 = 0
Successful SSA optimization Pass2ConstantIdentification
De-inlining pointer[w] to *(pointer+w)   [3] *((const byte*) main::screen#0 + (word) main::i#2) ← (byte) 'a'
Successful SSA optimization Pass2DeInlineWordDerefIdx
Inlining constant with var siblings (const word) main::i#0
Constant inlined main::i#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Added new block during phi lifting main::@3(between main::@1 and main::@1)
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @2
Adding NOP phi() at start of @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2 

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

FINAL CONTROL FLOW GRAPH
@begin: scope:[]  from
  [0] phi()
  to:@1
@1: scope:[]  from @begin
  [1] phi()
  [2] call main 
  to:@end
@end: scope:[]  from @1
  [3] phi()
main: scope:[main]  from @1
  [4] phi()
  to:main::@1
main::@1: scope:[main]  from main main::@1
  [5] (word) main::i#2 ← phi( main/(byte) 0 main::@1/(word) main::i#1 )
  [6] (byte*~) main::$1 ← (const byte*) main::screen#0 + (word) main::i#2
  [7] *((byte*~) main::$1) ← (byte) 'a'
  [8] (word) main::i#1 ← (word) main::i#2 + (byte) $28
  [9] if((word) main::i#1<(word) $3e8) goto main::@1
  to:main::@return
main::@return: scope:[main]  from main::@1
  [10] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte*~) main::$1 22.0
(word) main::i
(word) main::i#1 16.5
(word) main::i#2 11.0
(byte*) main::screen

Initial phi equivalence classes
[ main::i#2 main::i#1 ]
Added variable main::$1 to zero page equivalence class [ main::$1 ]
Complete equivalence classes
[ main::i#2 main::i#1 ]
[ main::$1 ]
Allocated zp ZP_WORD:2 [ main::i#2 main::i#1 ]
Allocated zp ZP_WORD:4 [ main::$1 ]

INITIAL ASM
  // File Comments
// Tests that array-indexing by a word variable is turned into pointer addition
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @begin
bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
  // @1
b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from_b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
  // @end
bend:
  // main
main: {
    .label screen = $400
    .label i = 2
    .label _1 = 4
    // [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [5] phi (word) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vwuz1=vbuc1 
    lda #<0
    sta i
    lda #>0
    sta i+1
    jmp b1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
    // [5] phi (word) main::i#2 = (word) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] (byte*~) main::$1 ← (const byte*) main::screen#0 + (word) main::i#2 -- pbuz1=pbuc1_plus_vwuz2 
    lda i
    clc
    adc #<screen
    sta _1
    lda i+1
    adc #>screen
    sta _1+1
    // [7] *((byte*~) main::$1) ← (byte) 'a' -- _deref_pbuz1=vbuc1 
    lda #'a'
    ldy #0
    sta (_1),y
    // [8] (word) main::i#1 ← (word) main::i#2 + (byte) $28 -- vwuz1=vwuz1_plus_vbuc1 
    lda #$28
    clc
    adc i
    sta i
    bcc !+
    inc i+1
  !:
    // [9] if((word) main::i#1<(word) $3e8) goto main::@1 -- vwuz1_lt_vwuc1_then_la1 
    lda i+1
    cmp #>$3e8
    bcc b1_from_b1
    bne !+
    lda i
    cmp #<$3e8
    bcc b1_from_b1
  !:
    jmp breturn
    // main::@return
  breturn:
    // [10] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (byte*~) main::$1 ← (const byte*) main::screen#0 + (word) main::i#2 [ main::i#2 main::$1 ] ( main:2 [ main::i#2 main::$1 ] ) always clobbers reg byte a 
Statement [7] *((byte*~) main::$1) ← (byte) 'a' [ main::i#2 ] ( main:2 [ main::i#2 ] ) always clobbers reg byte a reg byte y 
Statement [8] (word) main::i#1 ← (word) main::i#2 + (byte) $28 [ main::i#1 ] ( main:2 [ main::i#1 ] ) always clobbers reg byte a 
Statement [9] if((word) main::i#1<(word) $3e8) goto main::@1 [ main::i#1 ] ( main:2 [ main::i#1 ] ) always clobbers reg byte a 
Potential registers zp ZP_WORD:2 [ main::i#2 main::i#1 ] : zp ZP_WORD:2 , 
Potential registers zp ZP_WORD:4 [ main::$1 ] : zp ZP_WORD:4 , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 27.5: zp ZP_WORD:2 [ main::i#2 main::i#1 ] 22: zp ZP_WORD:4 [ main::$1 ] 
Uplift Scope [] 

Uplifting [main] best 838 combination zp ZP_WORD:2 [ main::i#2 main::i#1 ] zp ZP_WORD:4 [ main::$1 ] 
Uplifting [] best 838 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests that array-indexing by a word variable is turned into pointer addition
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
  // Global Constants & labels
  // @begin
bbegin:
  // [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
  // @1
b1:
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
main_from_b1:
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
  // @end
bend:
  // main
main: {
    .label screen = $400
    .label i = 2
    .label _1 = 4
    // [5] phi from main to main::@1 [phi:main->main::@1]
  b1_from_main:
    // [5] phi (word) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vwuz1=vbuc1 
    lda #<0
    sta i
    lda #>0
    sta i+1
    jmp b1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
  b1_from_b1:
    // [5] phi (word) main::i#2 = (word) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    jmp b1
    // main::@1
  b1:
    // [6] (byte*~) main::$1 ← (const byte*) main::screen#0 + (word) main::i#2 -- pbuz1=pbuc1_plus_vwuz2 
    lda i
    clc
    adc #<screen
    sta _1
    lda i+1
    adc #>screen
    sta _1+1
    // [7] *((byte*~) main::$1) ← (byte) 'a' -- _deref_pbuz1=vbuc1 
    lda #'a'
    ldy #0
    sta (_1),y
    // [8] (word) main::i#1 ← (word) main::i#2 + (byte) $28 -- vwuz1=vwuz1_plus_vbuc1 
    lda #$28
    clc
    adc i
    sta i
    bcc !+
    inc i+1
  !:
    // [9] if((word) main::i#1<(word) $3e8) goto main::@1 -- vwuz1_lt_vwuc1_then_la1 
    lda i+1
    cmp #>$3e8
    bcc b1_from_b1
    bne !+
    lda i
    cmp #<$3e8
    bcc b1_from_b1
  !:
    jmp breturn
    // main::@return
  breturn:
    // [10] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction lda #>0
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Replacing label b1_from_b1 with b1
Replacing label b1_from_b1 with b1
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction main_from_b1:
Removing instruction bend_from_b1:
Removing instruction b1_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction b1_from_main:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction jmp b1
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(void()) main()
(byte*~) main::$1 $1 zp ZP_WORD:4 22.0
(label) main::@1
(label) main::@return
(word) main::i
(word) main::i#1 i zp ZP_WORD:2 16.5
(word) main::i#2 i zp ZP_WORD:2 11.0
(byte*) main::screen
(const byte*) main::screen#0 screen = (byte*) 1024

zp ZP_WORD:2 [ main::i#2 main::i#1 ]
zp ZP_WORD:4 [ main::$1 ]


FINAL ASSEMBLER
Score: 716

  // File Comments
// Tests that array-indexing by a word variable is turned into pointer addition
  // Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
  // Global Constants & labels
  // @begin
  // [1] phi from @begin to @1 [phi:@begin->@1]
  // @1
  // [2] call main 
  // [4] phi from @1 to main [phi:@1->main]
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    .label screen = $400
    .label i = 2
    .label _1 = 4
    // [5] phi from main to main::@1 [phi:main->main::@1]
    // [5] phi (word) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vwuz1=vbuc1 
    lda #<0
    sta i
    sta i+1
    // [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
    // [5] phi (word) main::i#2 = (word) main::i#1 [phi:main::@1->main::@1#0] -- register_copy 
    // main::@1
  b1:
    // screen[i] = 'a'
    // [6] (byte*~) main::$1 ← (const byte*) main::screen#0 + (word) main::i#2 -- pbuz1=pbuc1_plus_vwuz2 
    lda i
    clc
    adc #<screen
    sta _1
    lda i+1
    adc #>screen
    sta _1+1
    // [7] *((byte*~) main::$1) ← (byte) 'a' -- _deref_pbuz1=vbuc1 
    lda #'a'
    ldy #0
    sta (_1),y
    // i+=40
    // [8] (word) main::i#1 ← (word) main::i#2 + (byte) $28 -- vwuz1=vwuz1_plus_vbuc1 
    lda #$28
    clc
    adc i
    sta i
    bcc !+
    inc i+1
  !:
    // for( word i=0;i<1000;i+=40)
    // [9] if((word) main::i#1<(word) $3e8) goto main::@1 -- vwuz1_lt_vwuc1_then_la1 
    lda i+1
    cmp #>$3e8
    bcc b1
    bne !+
    lda i
    cmp #<$3e8
    bcc b1
  !:
    // main::@return
    // }
    // [10] return 
    rts
}
  // File Data

