
CONTROL FLOW GRAPH SSA
@begin: scope:[]  from
  (dword) DVAL#0 ← (dword/signed dword) 131072
  (byte*) SCREEN#0 ← ((byte*)) (word/signed word/dword/signed dword) 1024
  to:@1
main: scope:[main]  from @1
  (dword~) main::$0 ← (dword) DVAL#0 / (word/signed word/dword/signed dword) 1024
  (word~) main::$1 ← ((word)) (dword~) main::$0
  (byte~) main::$2 ← < (word~) main::$1
  *((byte*) SCREEN#0 + (byte/signed byte/word/signed word/dword/signed dword) 0) ← (byte~) main::$2
  (dword~) main::$3 ← (dword) DVAL#0 / (word/signed word/dword/signed dword) 1024
  (word~) main::$4 ← ((word)) (dword~) main::$3
  (byte~) main::$5 ← > (word~) main::$4
  *((byte*) SCREEN#0 + (byte/signed byte/word/signed word/dword/signed dword) 1) ← (byte~) main::$5
  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
(dword) DVAL
(dword) DVAL#0
(byte*) SCREEN
(byte*) SCREEN#0
(void()) main()
(dword~) main::$0
(word~) main::$1
(byte~) main::$2
(dword~) main::$3
(word~) main::$4
(byte~) main::$5
(label) main::@return

Culled Empty Block (label) @2
Successful SSA optimization Pass2CullEmptyBlocks
Constant (const dword) DVAL#0 = 131072
Constant (const byte*) SCREEN#0 = ((byte*))1024
Successful SSA optimization Pass2ConstantIdentification
Constant (const dword) main::$0 = DVAL#0/1024
Constant (const dword) main::$3 = DVAL#0/1024
Successful SSA optimization Pass2ConstantIdentification
Constant (const word) main::$1 = ((word))main::$0
Constant (const word) main::$4 = ((word))main::$3
Successful SSA optimization Pass2ConstantIdentification
Constant (const byte) main::$2 = <main::$1
Constant (const byte) main::$5 = >main::$4
Successful SSA optimization Pass2ConstantIdentification
Consolidated array index constant in *(SCREEN#0+0)
Consolidated array index constant in *(SCREEN#0+1)
Successful SSA optimization Pass2ConstantAdditionElimination
Constant inlined main::$1 = ((word))(const dword) DVAL#0/(word/signed word/dword/signed dword) 1024
Constant inlined main::$2 = <((word))(const dword) DVAL#0/(word/signed word/dword/signed dword) 1024
Constant inlined main::$0 = (const dword) DVAL#0/(word/signed word/dword/signed dword) 1024
Constant inlined main::$5 = >((word))(const dword) DVAL#0/(word/signed word/dword/signed dword) 1024
Constant inlined main::$3 = (const dword) DVAL#0/(word/signed word/dword/signed dword) 1024
Constant inlined main::$4 = ((word))(const dword) DVAL#0/(word/signed word/dword/signed dword) 1024
Successful SSA optimization Pass2ConstantInlining
Simplifying constant plus zero SCREEN#0+0
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @1
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
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*) SCREEN#0) ← <((word))(const dword) DVAL#0/(word/signed word/dword/signed dword) 1024
  [5] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← >((word))(const dword) DVAL#0/(word/signed word/dword/signed dword) 1024
  to:main::@return
main::@return: scope:[main]  from main
  [6] return 
  to:@return


VARIABLE REGISTER WEIGHTS
(dword) DVAL
(byte*) SCREEN
(void()) main()

Initial phi equivalence classes
Complete equivalence classes

INITIAL ASM
//SEG0 File Comments
// Illustrates problem with constant evaluation of lo/hi-operator
// $20000 /$400 results in a byte value - confusing the lo/hi-evaluation
// which currently relies on getting the type from the literal value.
// A fix could be adding support for "declared" types for constant literal values
// - enabling the lo/hi to know that their operand is a word (from the cast).
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .const DVAL = $20000
  .label SCREEN = $400
//SEG3 @begin
bbegin:
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
//SEG5 @1
b1:
//SEG6 [2] call main 
  jsr main
//SEG7 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
//SEG8 @end
bend:
//SEG9 main
main: {
  //SEG10 [4] *((const byte*) SCREEN#0) ← <((word))(const dword) DVAL#0/(word/signed word/dword/signed dword) 1024 -- _deref_pbuc1=vbuc2 
    lda #DVAL/$400
    sta SCREEN
  //SEG11 [5] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← >((word))(const dword) DVAL#0/(word/signed word/dword/signed dword) 1024 -- _deref_pbuc1=vbuc2 
    lda #0
    sta SCREEN+1
    jmp breturn
  //SEG12 main::@return
  breturn:
  //SEG13 [6] return 
    rts
}

REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] *((const byte*) SCREEN#0) ← <((word))(const dword) DVAL#0/(word/signed word/dword/signed dword) 1024 [ ] ( main:2 [ ] ) always clobbers reg byte a 
Statement [5] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← >((word))(const dword) DVAL#0/(word/signed word/dword/signed dword) 1024 [ ] ( main:2 [ ] ) always clobbers reg byte a 

REGISTER UPLIFT SCOPES
Uplift Scope [main] 
Uplift Scope [] 

Uplifting [main] best 33 combination 
Uplifting [] best 33 combination 

ASSEMBLER BEFORE OPTIMIZATION
//SEG0 File Comments
// Illustrates problem with constant evaluation of lo/hi-operator
// $20000 /$400 results in a byte value - confusing the lo/hi-evaluation
// which currently relies on getting the type from the literal value.
// A fix could be adding support for "declared" types for constant literal values
// - enabling the lo/hi to know that their operand is a word (from the cast).
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .const DVAL = $20000
  .label SCREEN = $400
//SEG3 @begin
bbegin:
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
b1_from_bbegin:
  jmp b1
//SEG5 @1
b1:
//SEG6 [2] call main 
  jsr main
//SEG7 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
  jmp bend
//SEG8 @end
bend:
//SEG9 main
main: {
  //SEG10 [4] *((const byte*) SCREEN#0) ← <((word))(const dword) DVAL#0/(word/signed word/dword/signed dword) 1024 -- _deref_pbuc1=vbuc2 
    lda #DVAL/$400
    sta SCREEN
  //SEG11 [5] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← >((word))(const dword) DVAL#0/(word/signed word/dword/signed dword) 1024 -- _deref_pbuc1=vbuc2 
    lda #0
    sta SCREEN+1
    jmp breturn
  //SEG12 main::@return
  breturn:
  //SEG13 [6] return 
    rts
}

ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
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
(dword) DVAL
(const dword) DVAL#0 DVAL = (dword/signed dword) 131072
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) 1024
(void()) main()
(label) main::@return



FINAL ASSEMBLER
Score: 18

//SEG0 File Comments
// Illustrates problem with constant evaluation of lo/hi-operator
// $20000 /$400 results in a byte value - confusing the lo/hi-evaluation
// which currently relies on getting the type from the literal value.
// A fix could be adding support for "declared" types for constant literal values
// - enabling the lo/hi to know that their operand is a word (from the cast).
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG2 Global Constants & labels
  .const DVAL = $20000
  .label SCREEN = $400
//SEG3 @begin
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
//SEG5 @1
//SEG6 [2] call main 
//SEG7 [3] phi from @1 to @end [phi:@1->@end]
//SEG8 @end
//SEG9 main
main: {
  //SEG10 [4] *((const byte*) SCREEN#0) ← <((word))(const dword) DVAL#0/(word/signed word/dword/signed dword) 1024 -- _deref_pbuc1=vbuc2 
    lda #DVAL/$400
    sta SCREEN
  //SEG11 [5] *((const byte*) SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← >((word))(const dword) DVAL#0/(word/signed word/dword/signed dword) 1024 -- _deref_pbuc1=vbuc2 
    lda #0
    sta SCREEN+1
  //SEG12 main::@return
  //SEG13 [6] return 
    rts
}

