1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-10-21 17:24:39 +00:00
kickc/src/test/ref/const-signed-promotion.log

429 lines
15 KiB
Plaintext

Fixing pointer array-indexing *((signed word[3]) world + (byte) main::i)
Fixing pointer array-indexing *((signed word[3]) world + (number) 0)
Adding pointer type conversion cast (signed word*) main::screen in (signed word*) main::screen ← (number) $400
Identified constant variable (signed word*) main::screen
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
(signed word[3]) world#0 ← { fill( 3, 0) }
to:@1
main: scope:[main] from @1
(byte) main::i#0 ← (byte) 0
to:main::@1
main::@1: scope:[main] from main main::@1
(byte) main::i#2 ← phi( main/(byte) main::i#0 main::@1/(byte) main::i#1 )
(byte~) main::$1 ← (byte) main::i#2 * (const byte) SIZEOF_SIGNED_WORD
*((signed word[3]) world#0 + (byte~) main::$1) ← (number) $190
(byte) main::i#1 ← (byte) main::i#2 + rangenext(0,2)
(bool~) main::$0 ← (byte) main::i#1 != rangelast(0,2)
if((bool~) main::$0) goto main::@1
to:main::@2
main::@2: scope:[main] from main::@1
(signed word*) main::screen#0 ← ((signed word*)) (number) $400
(number~) main::$2 ← (number) 0 * (const byte) SIZEOF_SIGNED_WORD
*((signed word*) main::screen#0) ← *((signed word[3]) world#0 + (number~) main::$2)
to:main::@return
main::@return: scope:[main] from main::@2
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
(const byte) SIZEOF_SIGNED_WORD = (byte) 2
(void()) main()
(bool~) main::$0
(byte~) main::$1
(number~) main::$2
(label) main::@1
(label) main::@2
(label) main::@return
(byte) main::i
(byte) main::i#0
(byte) main::i#1
(byte) main::i#2
(signed word*) main::screen
(signed word*) main::screen#0
(signed word[3]) world
(signed word[3]) world#0
Adding number conversion cast (snumber) $190 in *((signed word[3]) world#0 + (byte~) main::$1) ← (number) $190
Adding number conversion cast (unumber) 0 in (number~) main::$2 ← (number) 0 * (const byte) SIZEOF_SIGNED_WORD
Adding number conversion cast (unumber) main::$2 in (number~) main::$2 ← (unumber)(number) 0 * (const byte) SIZEOF_SIGNED_WORD
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast *((signed word[3]) world#0 + (byte~) main::$1) ← (snumber)(number) $190
Inlining cast (signed word*) main::screen#0 ← (signed word*)(number) $400
Successful SSA optimization Pass2InlineCast
Simplifying constant integer cast $190
Simplifying constant pointer cast (signed word*) 1024
Simplifying constant integer cast 0
Successful SSA optimization PassNCastSimplification
Finalized signed number type (signed word) $190
Finalized unsigned number type (byte) 0
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inferred type updated to byte in (unumber~) main::$2 ← (byte) 0 * (const byte) SIZEOF_SIGNED_WORD
Simple Condition (bool~) main::$0 [7] if((byte) main::i#1!=rangelast(0,2)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant right-side identified [0] (signed word[3]) world#0 ← { fill( 3, 0) }
Constant right-side identified [9] (byte~) main::$2 ← (byte) 0 * (const byte) SIZEOF_SIGNED_WORD
Successful SSA optimization Pass2ConstantRValueConsolidation
Constant (const signed word[3]) world#0 = { fill( 3, 0) }
Constant (const byte) main::i#0 = 0
Constant (const signed word*) main::screen#0 = (signed word*) 1024
Constant (const byte) main::$2 = 0*SIZEOF_SIGNED_WORD
Successful SSA optimization Pass2ConstantIdentification
Resolved ranged next value [5] main::i#1 ← ++ main::i#2 to ++
Resolved ranged comparison value [7] if(main::i#1!=rangelast(0,2)) goto main::@1 to (number) 3
Simplifying constant evaluating to zero (byte) 0*(const byte) SIZEOF_SIGNED_WORD in
Successful SSA optimization PassNSimplifyConstantZero
Simplifying expression containing zero world#0 in [10] *((const signed word*) main::screen#0) ← *((const signed word[3]) world#0 + (const byte) main::$2)
Successful SSA optimization PassNSimplifyExpressionWithZero
Eliminating unused constant (const byte) main::$2
Successful SSA optimization PassNEliminateUnusedVars
Adding number conversion cast (unumber) 3 in if((byte) main::i#1!=(number) 3) goto main::@1
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast 3
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 3
Successful SSA optimization PassNFinalizeNumberTypeConversions
Rewriting multiplication to use shift [1] (byte~) main::$1 ← (byte) main::i#2 * (const byte) SIZEOF_SIGNED_WORD
Successful SSA optimization Pass2MultiplyToShiftRewriting
Inlining constant with var siblings (const byte) main::i#0
Constant inlined main::i#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Eliminating unused constant (const byte) SIZEOF_SIGNED_WORD
Successful SSA optimization PassNEliminateUnusedVars
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 [13] 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] (byte) main::i#2 ← phi( main/(byte) 0 main::@1/(byte) main::i#1 )
[6] (byte~) main::$1 ← (byte) main::i#2 << (byte) 1
[7] *((const signed word[3]) world#0 + (byte~) main::$1) ← (signed word) $190
[8] (byte) main::i#1 ← ++ (byte) main::i#2
[9] if((byte) main::i#1!=(byte) 3) goto main::@1
to:main::@2
main::@2: scope:[main] from main::@1
[10] *((const signed word*) main::screen#0) ← *((const signed word[3]) world#0)
to:main::@return
main::@return: scope:[main] from main::@2
[11] return
to:@return
VARIABLE REGISTER WEIGHTS
(void()) main()
(byte~) main::$1 22.0
(byte) main::i
(byte) main::i#1 16.5
(byte) main::i#2 11.0
(signed word*) main::screen
(signed word[3]) world
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_BYTE:2 [ main::i#2 main::i#1 ]
Allocated zp ZP_BYTE:3 [ main::$1 ]
INITIAL ASM
//SEG0 File Comments
// Test fragment promotion of a constant (400) to signed word even if it also matches an unsigned word
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
//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
//SEG7 [4] phi from @1 to main [phi:@1->main]
main_from_b1:
jsr main
//SEG8 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
jmp bend
//SEG9 @end
bend:
//SEG10 main
main: {
.label screen = $400
.label _1 = 3
.label i = 2
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
b1_from_main:
//SEG12 [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
lda #0
sta i
jmp b1
//SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
b1_from_b1:
//SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy
jmp b1
//SEG15 main::@1
b1:
//SEG16 [6] (byte~) main::$1 ← (byte) main::i#2 << (byte) 1 -- vbuz1=vbuz2_rol_1
lda i
asl
sta _1
//SEG17 [7] *((const signed word[3]) world#0 + (byte~) main::$1) ← (signed word) $190 -- pwsc1_derefidx_vbuz1=vwsc2
ldy _1
lda #<$190
sta world,y
lda #>$190
sta world+1,y
//SEG18 [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1
inc i
//SEG19 [9] if((byte) main::i#1!=(byte) 3) goto main::@1 -- vbuz1_neq_vbuc1_then_la1
lda #3
cmp i
bne b1_from_b1
jmp b2
//SEG20 main::@2
b2:
//SEG21 [10] *((const signed word*) main::screen#0) ← *((const signed word[3]) world#0) -- _deref_pwsc1=_deref_pwsc2
lda world
sta screen
lda world+1
sta screen+1
jmp breturn
//SEG22 main::@return
breturn:
//SEG23 [11] return
rts
}
world: .fill 2*3, 0
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] (byte~) main::$1 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::$1 ] ( main:2 [ main::i#2 main::$1 ] ) always clobbers reg byte a
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ main::i#2 main::i#1 ]
Statement [7] *((const signed word[3]) world#0 + (byte~) main::$1) ← (signed word) $190 [ main::i#2 ] ( main:2 [ main::i#2 ] ) always clobbers reg byte a
Statement [10] *((const signed word*) main::screen#0) ← *((const signed word[3]) world#0) [ ] ( main:2 [ ] ) always clobbers reg byte a
Statement [6] (byte~) main::$1 ← (byte) main::i#2 << (byte) 1 [ main::i#2 main::$1 ] ( main:2 [ main::i#2 main::$1 ] ) always clobbers reg byte a
Statement [7] *((const signed word[3]) world#0 + (byte~) main::$1) ← (signed word) $190 [ main::i#2 ] ( main:2 [ main::i#2 ] ) always clobbers reg byte a
Statement [10] *((const signed word*) main::screen#0) ← *((const signed word[3]) world#0) [ ] ( main:2 [ ] ) always clobbers reg byte a
Potential registers zp ZP_BYTE:2 [ main::i#2 main::i#1 ] : zp ZP_BYTE:2 , reg byte x , reg byte y ,
Potential registers zp ZP_BYTE:3 [ main::$1 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [main] 27.5: zp ZP_BYTE:2 [ main::i#2 main::i#1 ] 22: zp ZP_BYTE:3 [ main::$1 ]
Uplift Scope []
Uplifting [main] best 412 combination reg byte x [ main::i#2 main::i#1 ] reg byte a [ main::$1 ]
Uplifting [] best 412 combination
ASSEMBLER BEFORE OPTIMIZATION
//SEG0 File Comments
// Test fragment promotion of a constant (400) to signed word even if it also matches an unsigned word
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
//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
//SEG7 [4] phi from @1 to main [phi:@1->main]
main_from_b1:
jsr main
//SEG8 [3] phi from @1 to @end [phi:@1->@end]
bend_from_b1:
jmp bend
//SEG9 @end
bend:
//SEG10 main
main: {
.label screen = $400
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
b1_from_main:
//SEG12 [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
ldx #0
jmp b1
//SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
b1_from_b1:
//SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy
jmp b1
//SEG15 main::@1
b1:
//SEG16 [6] (byte~) main::$1 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuxx_rol_1
txa
asl
//SEG17 [7] *((const signed word[3]) world#0 + (byte~) main::$1) ← (signed word) $190 -- pwsc1_derefidx_vbuaa=vwsc2
tay
lda #<$190
sta world,y
lda #>$190
sta world+1,y
//SEG18 [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
inx
//SEG19 [9] if((byte) main::i#1!=(byte) 3) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
cpx #3
bne b1_from_b1
jmp b2
//SEG20 main::@2
b2:
//SEG21 [10] *((const signed word*) main::screen#0) ← *((const signed word[3]) world#0) -- _deref_pwsc1=_deref_pwsc2
lda world
sta screen
lda world+1
sta screen+1
jmp breturn
//SEG22 main::@return
breturn:
//SEG23 [11] return
rts
}
world: .fill 2*3, 0
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp b2
Removing instruction jmp breturn
Succesful ASM optimization Pass5NextJumpElimination
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 b2:
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 reg byte a 22.0
(label) main::@1
(label) main::@2
(label) main::@return
(byte) main::i
(byte) main::i#1 reg byte x 16.5
(byte) main::i#2 reg byte x 11.0
(signed word*) main::screen
(const signed word*) main::screen#0 screen = (signed word*) 1024
(signed word[3]) world
(const signed word[3]) world#0 world = { fill( 3, 0) }
reg byte x [ main::i#2 main::i#1 ]
reg byte a [ main::$1 ]
FINAL ASSEMBLER
Score: 307
//SEG0 File Comments
// Test fragment promotion of a constant (400) to signed word even if it also matches an unsigned word
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG2 Global Constants & labels
//SEG3 @begin
//SEG4 [1] phi from @begin to @1 [phi:@begin->@1]
//SEG5 @1
//SEG6 [2] call main
//SEG7 [4] phi from @1 to main [phi:@1->main]
//SEG8 [3] phi from @1 to @end [phi:@1->@end]
//SEG9 @end
//SEG10 main
main: {
.label screen = $400
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
//SEG12 [5] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1
ldx #0
//SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
//SEG14 [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@1->main::@1#0] -- register_copy
//SEG15 main::@1
b1:
//SEG16 [6] (byte~) main::$1 ← (byte) main::i#2 << (byte) 1 -- vbuaa=vbuxx_rol_1
txa
asl
//SEG17 [7] *((const signed word[3]) world#0 + (byte~) main::$1) ← (signed word) $190 -- pwsc1_derefidx_vbuaa=vwsc2
tay
lda #<$190
sta world,y
lda #>$190
sta world+1,y
//SEG18 [8] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx
inx
//SEG19 [9] if((byte) main::i#1!=(byte) 3) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
cpx #3
bne b1
//SEG20 main::@2
//SEG21 [10] *((const signed word*) main::screen#0) ← *((const signed word[3]) world#0) -- _deref_pwsc1=_deref_pwsc2
lda world
sta screen
lda world+1
sta screen+1
//SEG22 main::@return
//SEG23 [11] return
rts
}
world: .fill 2*3, 0