Identified constant variable (byte*) main::screen

CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  to:@1
main: scope:[main]  from @1
  (byte*) main::screen#0 ← ((byte*)) (number) $400
  (byte) main::a#0 ← (byte) 0
  (byte) main::a#1 ← (byte) 'c'
  *((byte*) main::screen#0 + (number) 0) ← (byte) main::a#1
  *((byte*) main::screen#0 + (number) $28) ← (byte) main::a#1
  *((byte*) main::screen#0 + (number) 1) ← (byte) 'm'
  (byte) main::a#2 ← *((byte*) main::screen#0 + (number) 1)
  *((byte*) main::screen#0 + (number) $29) ← (byte) main::a#2
  (byte) main::a#3 ← (byte) 'l'
  (number~) main::$0 ← (number) 1 + (byte) main::a#3
  *((byte*) main::screen#0 + (number) 2) ← (number~) main::$0
  *((byte*) main::screen#0 + (number) $2a) ← (byte) main::a#3
  to:main::@return
main::@return: scope:[main]  from main
  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()
(number~) main::$0
(label) main::@return
(byte) main::a
(byte) main::a#0
(byte) main::a#1
(byte) main::a#2
(byte) main::a#3
(byte*) main::screen
(byte*) main::screen#0

Adding number conversion cast (unumber) 0 in *((byte*) main::screen#0 + (number) 0) ← (byte) main::a#1
Adding number conversion cast (unumber) $28 in *((byte*) main::screen#0 + (number) $28) ← (byte) main::a#1
Adding number conversion cast (unumber) 1 in *((byte*) main::screen#0 + (number) 1) ← (byte) 'm'
Adding number conversion cast (unumber) $29 in *((byte*) main::screen#0 + (number) $29) ← (byte) main::a#2
Adding number conversion cast (unumber) 1 in (number~) main::$0 ← (number) 1 + (byte) main::a#3
Adding number conversion cast (unumber) main::$0 in (number~) main::$0 ← (unumber)(number) 1 + (byte) main::a#3
Adding number conversion cast (unumber) 2 in *((byte*) main::screen#0 + (number) 2) ← (unumber~) main::$0
Adding number conversion cast (unumber) $2a in *((byte*) main::screen#0 + (number) $2a) ← (byte) main::a#3
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) main::screen#0 ← (byte*)(number) $400
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast 0
Simplifying constant integer cast $28
Simplifying constant integer cast 1
Simplifying constant integer cast $29
Simplifying constant integer cast 1
Simplifying constant integer cast 2
Simplifying constant integer cast $2a
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) $28
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) $29
Finalized unsigned number type (byte) 1
Finalized unsigned number type (byte) 2
Finalized unsigned number type (byte) $2a
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) main::$0 ← (byte) 1 + (byte) main::a#3
Constant (const byte*) main::screen#0 = (byte*) 1024
Constant (const byte) main::a#0 = 0
Constant (const byte) main::a#1 = 'c'
Constant (const byte) main::a#3 = 'l'
Successful SSA optimization Pass2ConstantIdentification
Simplifying expression containing zero main::screen#0 in [3] *((const byte*) main::screen#0 + (byte) 0) ← (const byte) main::a#1
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused constant (const byte) main::a#0
Successful SSA optimization PassNEliminateUnusedVars
Constant right-side identified [5] (byte~) main::$0 ← (byte) 1 + (const byte) main::a#3
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const byte) main::$0 = 1+main::a#3
Successful SSA optimization Pass2ConstantIdentification
Inlining constant with var siblings (const byte) main::a#1
Inlining constant with var siblings (const byte) main::a#3
Constant inlined main::a#3 = (byte) 'l'
Constant inlined main::$0 = (byte) 1+(byte) 'l'
Constant inlined main::a#1 = (byte) 'c'
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(main::screen#0+$28)
Consolidated array index constant in *(main::screen#0+1)
Consolidated array index constant in *(main::screen#0+1)
Consolidated array index constant in *(main::screen#0+$29)
Consolidated array index constant in *(main::screen#0+2)
Consolidated array index constant in *(main::screen#0+$2a)
Successful SSA optimization Pass2ConstantAdditionElimination
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
CALL GRAPH
Calls in [] to main:2 

Created 0 initial phi equivalence classes
Coalesced down to 0 phi equivalence classes
Culled Empty Block (label) @2
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
Adding NOP phi() at start of @end

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] *((const byte*) main::screen#0) ← (byte) 'c'
  [5] *((const byte*) main::screen#0+(byte) $28) ← (byte) 'c'
  [6] *((const byte*) main::screen#0+(byte) 1) ← (byte) 'm'
  [7] (byte) main::a#2 ← *((const byte*) main::screen#0+(byte) 1)
  [8] *((const byte*) main::screen#0+(byte) $29) ← (byte) main::a#2
  [9] *((const byte*) main::screen#0+(byte) 2) ← (byte) 1+(byte) 'l'
  [10] *((const byte*) main::screen#0+(byte) $2a) ← (byte) 'l'
  to:main::@return
main::@return: scope:[main]  from main
  [11] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(void()) main()
(byte) main::a
(byte) main::a#2 4.0
(byte*) main::screen

Initial phi equivalence classes
Added variable main::a#2 to zero page equivalence class [ main::a#2 ]
Complete equivalence classes
[ main::a#2 ]
Allocated zp ZP_BYTE:2 [ main::a#2 ]

INITIAL ASM
  // File Comments
// Tests that chained assignments work as intended
  // 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 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
  // @end
bend:
  // main
main: {
    .label screen = $400
    .label a = 2
    // [4] *((const byte*) main::screen#0) ← (byte) 'c' -- _deref_pbuc1=vbuc2 
    lda #'c'
    sta screen
    // [5] *((const byte*) main::screen#0+(byte) $28) ← (byte) 'c' -- _deref_pbuc1=vbuc2 
    lda #'c'
    sta screen+$28
    // [6] *((const byte*) main::screen#0+(byte) 1) ← (byte) 'm' -- _deref_pbuc1=vbuc2 
    lda #'m'
    sta screen+1
    // [7] (byte) main::a#2 ← *((const byte*) main::screen#0+(byte) 1) -- vbuz1=_deref_pbuc1 
    lda screen+1
    sta a
    // [8] *((const byte*) main::screen#0+(byte) $29) ← (byte) main::a#2 -- _deref_pbuc1=vbuz1 
    lda a
    sta screen+$29
    // [9] *((const byte*) main::screen#0+(byte) 2) ← (byte) 1+(byte) 'l' -- _deref_pbuc1=vbuc2 
    lda #1+'l'
    sta screen+2
    // [10] *((const byte*) main::screen#0+(byte) $2a) ← (byte) 'l' -- _deref_pbuc1=vbuc2 
    // Chained assignment with a modification of the result
    lda #'l'
    sta screen+$2a
    jmp breturn
    // main::@return
  breturn:
    // [11] return 
    rts
}
  // File Data

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] *((const byte*) main::screen#0) ← (byte) 'c' [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [5] *((const byte*) main::screen#0+(byte) $28) ← (byte) 'c' [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [6] *((const byte*) main::screen#0+(byte) 1) ← (byte) 'm' [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [9] *((const byte*) main::screen#0+(byte) 2) ← (byte) 1+(byte) 'l' [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [10] *((const byte*) main::screen#0+(byte) $2a) ← (byte) 'l' [ ] ( main:2 [ ] ) always clobbers reg byte a 
Potential registers zp ZP_BYTE:2 [ main::a#2 ] : zp ZP_BYTE:2 , reg byte a , reg byte x , reg byte y , 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 4: zp ZP_BYTE:2 [ main::a#2 ] 
Uplift Scope [] 

Uplifting [main] best 59 combination reg byte a [ main::a#2 ] 
Uplifting [] best 59 combination 

ASSEMBLER BEFORE OPTIMIZATION
  // File Comments
// Tests that chained assignments work as intended
  // 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 
  jsr main
  // [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
  // @end
bend:
  // main
main: {
    .label screen = $400
    // [4] *((const byte*) main::screen#0) ← (byte) 'c' -- _deref_pbuc1=vbuc2 
    lda #'c'
    sta screen
    // [5] *((const byte*) main::screen#0+(byte) $28) ← (byte) 'c' -- _deref_pbuc1=vbuc2 
    lda #'c'
    sta screen+$28
    // [6] *((const byte*) main::screen#0+(byte) 1) ← (byte) 'm' -- _deref_pbuc1=vbuc2 
    lda #'m'
    sta screen+1
    // [7] (byte) main::a#2 ← *((const byte*) main::screen#0+(byte) 1) -- vbuaa=_deref_pbuc1 
    lda screen+1
    // [8] *((const byte*) main::screen#0+(byte) $29) ← (byte) main::a#2 -- _deref_pbuc1=vbuaa 
    sta screen+$29
    // [9] *((const byte*) main::screen#0+(byte) 2) ← (byte) 1+(byte) 'l' -- _deref_pbuc1=vbuc2 
    lda #1+'l'
    sta screen+2
    // [10] *((const byte*) main::screen#0+(byte) $2a) ← (byte) 'l' -- _deref_pbuc1=vbuc2 
    // Chained assignment with a modification of the result
    lda #'l'
    sta screen+$2a
    jmp breturn
    // main::@return
  breturn:
    // [11] return 
    rts
}
  // File Data

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
Removing instruction lda #'c'
Removing instruction lda screen+1
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Removing instruction b1_from_bbegin:
Removing instruction b1:
Removing instruction bend_from_b1:
Succesful ASM optimization Pass5RedundantLabelElimination
Removing instruction bend:
Removing instruction breturn:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination

FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(void()) main()
(label) main::@return
(byte) main::a
(byte) main::a#2 reg byte a 4.0
(byte*) main::screen
(const byte*) main::screen#0 screen = (byte*) 1024

reg byte a [ main::a#2 ]


FINAL ASSEMBLER
Score: 38

  // File Comments
// Tests that chained assignments work as intended
  // 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 
  // [3] phi from @1 to @end [phi:@1->@end]
  // @end
  // main
main: {
    .label screen = $400
    // screen[0] = a = 'c'
    // [4] *((const byte*) main::screen#0) ← (byte) 'c' -- _deref_pbuc1=vbuc2 
    lda #'c'
    sta screen
    // screen[40] = a
    // [5] *((const byte*) main::screen#0+(byte) $28) ← (byte) 'c' -- _deref_pbuc1=vbuc2 
    sta screen+$28
    // screen[1] = 'm'
    // [6] *((const byte*) main::screen#0+(byte) 1) ← (byte) 'm' -- _deref_pbuc1=vbuc2 
    lda #'m'
    sta screen+1
    // a = screen[1] = 'm'
    // [7] (byte) main::a#2 ← *((const byte*) main::screen#0+(byte) 1) -- vbuaa=_deref_pbuc1 
    // screen[41] = a
    // [8] *((const byte*) main::screen#0+(byte) $29) ← (byte) main::a#2 -- _deref_pbuc1=vbuaa 
    sta screen+$29
    // screen[2] = 1 + (a = 'l')
    // [9] *((const byte*) main::screen#0+(byte) 2) ← (byte) 1+(byte) 'l' -- _deref_pbuc1=vbuc2 
    lda #1+'l'
    sta screen+2
    // screen[42] = a
    // [10] *((const byte*) main::screen#0+(byte) $2a) ← (byte) 'l' -- _deref_pbuc1=vbuc2 
    // Chained assignment with a modification of the result
    lda #'l'
    sta screen+$2a
    // main::@return
    // }
    // [11] return 
    rts
}
  // File Data

