1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-10-03 14:56:30 +00:00
kickc/src/test/ref/loophead-problem.log

540 lines
19 KiB
Plaintext
Raw Normal View History

Culled Empty Block (label) @1
Culled Empty Block (label) popup_selector::@4
Culled Empty Block (label) popup_selector::@3
Culled Empty Block (label) popup_selector::@5
Culled Empty Block (label) popup_selector::@6
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
(byte*) screen#0 ← ((byte*)) (number) $400
(byte) opcode#0 ← (byte) 'a'
to:@2
main: scope:[main] from @2
(byte) opcode#6 ← phi( @2/(byte) opcode#11 )
*((byte*) screen#0 + (number) $28) ← (byte) opcode#6
call popup_selector
to:main::@1
main::@1: scope:[main] from main
(byte) opcode#7 ← phi( main/(byte) opcode#4 )
(byte) opcode#1 ← (byte) opcode#7
*((byte*) screen#0 + (number) $29) ← (byte) opcode#1
to:main::@return
main::@return: scope:[main] from main::@1
(byte) opcode#8 ← phi( main::@1/(byte) opcode#1 )
(byte) opcode#2 ← (byte) opcode#8
return
to:@return
popup_selector: scope:[popup_selector] from main
(byte) opcode#13 ← phi( main/(byte) opcode#6 )
(byte) popup_selector::k#0 ← (number) 0
to:popup_selector::@1
popup_selector::@1: scope:[popup_selector] from popup_selector popup_selector::@2
(byte) opcode#12 ← phi( popup_selector/(byte) opcode#13 popup_selector::@2/(byte) opcode#3 )
(byte) popup_selector::k#2 ← phi( popup_selector/(byte) popup_selector::k#0 popup_selector::@2/(byte) popup_selector::k#1 )
(bool~) popup_selector::$0 ← (byte) popup_selector::k#2 <= (number) 2
if((bool~) popup_selector::$0) goto popup_selector::@2
to:popup_selector::@return
popup_selector::@2: scope:[popup_selector] from popup_selector::@1
(byte) popup_selector::k#3 ← phi( popup_selector::@1/(byte) popup_selector::k#2 )
(byte) opcode#3 ← (byte) 'b'
*((byte*) screen#0 + (byte) popup_selector::k#3) ← (byte) opcode#3
(byte) popup_selector::k#1 ← ++ (byte) popup_selector::k#3
to:popup_selector::@1
popup_selector::@return: scope:[popup_selector] from popup_selector::@1
(byte) opcode#9 ← phi( popup_selector::@1/(byte) opcode#12 )
(byte) opcode#4 ← (byte) opcode#9
return
to:@return
@2: scope:[] from @begin
(byte) opcode#11 ← phi( @begin/(byte) opcode#0 )
call main
to:@3
@3: scope:[] from @2
(byte) opcode#10 ← phi( @2/(byte) opcode#2 )
(byte) opcode#5 ← (byte) opcode#10
to:@end
@end: scope:[] from @3
SYMBOL TABLE SSA
(label) @2
(label) @3
(label) @begin
(label) @end
(void()) main()
(label) main::@1
(label) main::@return
(byte) opcode
(byte) opcode#0
(byte) opcode#1
(byte) opcode#10
(byte) opcode#11
(byte) opcode#12
(byte) opcode#13
(byte) opcode#2
(byte) opcode#3
(byte) opcode#4
(byte) opcode#5
(byte) opcode#6
(byte) opcode#7
(byte) opcode#8
(byte) opcode#9
(void()) popup_selector()
(bool~) popup_selector::$0
(label) popup_selector::@1
(label) popup_selector::@2
(label) popup_selector::@return
(byte) popup_selector::k
(byte) popup_selector::k#0
(byte) popup_selector::k#1
(byte) popup_selector::k#2
(byte) popup_selector::k#3
(byte*) screen
(byte*) screen#0
Adding number conversion cast (unumber) $28 in *((byte*) screen#0 + (number) $28) ← (byte) opcode#6
Adding number conversion cast (unumber) $29 in *((byte*) screen#0 + (number) $29) ← (byte) opcode#1
Adding number conversion cast (unumber) 0 in (byte) popup_selector::k#0 ← (number) 0
Adding number conversion cast (unumber) 2 in (bool~) popup_selector::$0 ← (byte) popup_selector::k#2 <= (number) 2
Successful SSA optimization PassNAddNumberTypeConversions
Inlining cast (byte*) screen#0 ← (byte*)(number) $400
Inlining cast (byte) popup_selector::k#0 ← (unumber)(number) 0
Successful SSA optimization Pass2InlineCast
Simplifying constant pointer cast (byte*) 1024
Simplifying constant integer cast $28
Simplifying constant integer cast $29
Simplifying constant integer cast 0
Simplifying constant integer cast 2
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) $28
Finalized unsigned number type (byte) $29
Finalized unsigned number type (byte) 0
Finalized unsigned number type (byte) 2
Successful SSA optimization PassNFinalizeNumberTypeConversions
Alias (byte) opcode#1 = (byte) opcode#7 (byte) opcode#8 (byte) opcode#2
Alias (byte) popup_selector::k#2 = (byte) popup_selector::k#3
Alias (byte) opcode#12 = (byte) opcode#9 (byte) opcode#4
Alias (byte) opcode#0 = (byte) opcode#11
Alias (byte) opcode#10 = (byte) opcode#5
Successful SSA optimization Pass2AliasElimination
Identical Phi Values (byte) opcode#6 (byte) opcode#0
Identical Phi Values (byte) opcode#1 (byte) opcode#12
Identical Phi Values (byte) opcode#13 (byte) opcode#6
Identical Phi Values (byte) opcode#10 (byte) opcode#1
Successful SSA optimization Pass2IdenticalPhiElimination
Simple Condition (bool~) popup_selector::$0 [15] if((byte) popup_selector::k#2<=(byte) 2) goto popup_selector::@2
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) screen#0 = (byte*) 1024
Constant (const byte) opcode#0 = 'a'
Constant (const byte) popup_selector::k#0 = 0
Constant (const byte) opcode#3 = 'b'
Successful SSA optimization Pass2ConstantIdentification
Rewriting conditional comparison [15] if((byte) popup_selector::k#2<=(byte) 2) goto popup_selector::@2
Adding number conversion cast (unumber) 2+1 in if((byte) popup_selector::k#2<(byte) 2+(number) 1) goto popup_selector::@2
Adding number conversion cast (unumber) 1 in if((byte) popup_selector::k#2<(unumber)(byte) 2+(number) 1) goto popup_selector::@2
Successful SSA optimization PassNAddNumberTypeConversions
Simplifying constant integer cast (byte) 2+(unumber)(number) 1
Simplifying constant integer cast 1
Successful SSA optimization PassNCastSimplification
Finalized unsigned number type (byte) 1
Successful SSA optimization PassNFinalizeNumberTypeConversions
Inlining constant with var siblings (const byte) popup_selector::k#0
Inlining constant with var siblings (const byte) opcode#0
Inlining constant with var siblings (const byte) opcode#3
Constant inlined opcode#3 = (byte) 'b'
Constant inlined opcode#0 = (byte) 'a'
Constant inlined popup_selector::k#0 = (byte) 0
Successful SSA optimization Pass2ConstantInlining
Consolidated array index constant in *(screen#0+$28)
Consolidated array index constant in *(screen#0+$29)
Successful SSA optimization Pass2ConstantAdditionElimination
Adding NOP phi() at start of @begin
Adding NOP phi() at start of @2
Adding NOP phi() at start of @3
Adding NOP phi() at start of @end
Adding NOP phi() at start of popup_selector
CALL GRAPH
Calls in [] to main:2
Calls in [main] to popup_selector:6
Created 2 initial phi equivalence classes
Coalesced [15] popup_selector::k#4 ← popup_selector::k#1
Coalesced down to 2 phi equivalence classes
Culled Empty Block (label) @3
Renumbering block @2 to @1
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 popup_selector
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+(byte) $28) ← (byte) 'a'
[5] call popup_selector
to:main::@1
main::@1: scope:[main] from main
[6] *((const byte*) screen#0+(byte) $29) ← (byte) opcode#12
to:main::@return
main::@return: scope:[main] from main::@1
[7] return
to:@return
popup_selector: scope:[popup_selector] from main
[8] phi()
to:popup_selector::@1
popup_selector::@1: scope:[popup_selector] from popup_selector popup_selector::@2
[9] (byte) opcode#12 ← phi( popup_selector/(byte) 'a' popup_selector::@2/(byte) 'b' )
[9] (byte) popup_selector::k#2 ← phi( popup_selector/(byte) 0 popup_selector::@2/(byte) popup_selector::k#1 )
[10] if((byte) popup_selector::k#2<(byte) 2+(byte) 1) goto popup_selector::@2
to:popup_selector::@return
popup_selector::@return: scope:[popup_selector] from popup_selector::@1
[11] return
to:@return
popup_selector::@2: scope:[popup_selector] from popup_selector::@1
[12] *((const byte*) screen#0 + (byte) popup_selector::k#2) ← (byte) 'b'
[13] (byte) popup_selector::k#1 ← ++ (byte) popup_selector::k#2
to:popup_selector::@1
VARIABLE REGISTER WEIGHTS
(void()) main()
(byte) opcode
(byte) opcode#12 0.5
(void()) popup_selector()
(byte) popup_selector::k
(byte) popup_selector::k#1 22.0
(byte) popup_selector::k#2 14.666666666666666
(byte*) screen
Initial phi equivalence classes
[ popup_selector::k#2 popup_selector::k#1 ]
[ opcode#12 ]
Complete equivalence classes
[ popup_selector::k#2 popup_selector::k#1 ]
[ opcode#12 ]
Allocated zp ZP_BYTE:2 [ popup_selector::k#2 popup_selector::k#1 ]
Allocated zp ZP_BYTE:3 [ opcode#12 ]
INITIAL ASM
Target platform is c64basic / 6502X
// File Comments
// Demonstrates a problem where constant loophead unrolling results in an error
// The result is a NullPointerException
// The cause is that the Unroller does not handle the variable opcode correctly.
// The Unroller gets the verwions for opcode wrong because it misses the fact that it is modified inside call to popup_selector()
// Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label screen = $400
.label opcode = 3
// @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
// Offending unroll variable
main: {
// [4] *((const byte*) screen#0+(byte) $28) ← (byte) 'a' -- _deref_pbuc1=vbuc2
lda #'a'
sta screen+$28
// [5] call popup_selector
// [8] phi from main to popup_selector [phi:main->popup_selector]
popup_selector_from_main:
jsr popup_selector
jmp b1
// main::@1
b1:
// [6] *((const byte*) screen#0+(byte) $29) ← (byte) opcode#12 -- _deref_pbuc1=vbuz1
lda.z opcode
sta screen+$29
jmp breturn
// main::@return
breturn:
// [7] return
rts
}
// popup_selector
popup_selector: {
.label k = 2
// [9] phi from popup_selector to popup_selector::@1 [phi:popup_selector->popup_selector::@1]
b1_from_popup_selector:
// [9] phi (byte) opcode#12 = (byte) 'a' [phi:popup_selector->popup_selector::@1#0] -- vbuz1=vbuc1
lda #'a'
sta.z opcode
// [9] phi (byte) popup_selector::k#2 = (byte) 0 [phi:popup_selector->popup_selector::@1#1] -- vbuz1=vbuc1
lda #0
sta.z k
jmp b1
// popup_selector::@1
b1:
// [10] if((byte) popup_selector::k#2<(byte) 2+(byte) 1) goto popup_selector::@2 -- vbuz1_lt_vbuc1_then_la1
lda.z k
cmp #2+1
bcc b2
jmp breturn
// popup_selector::@return
breturn:
// [11] return
rts
// popup_selector::@2
b2:
// [12] *((const byte*) screen#0 + (byte) popup_selector::k#2) ← (byte) 'b' -- pbuc1_derefidx_vbuz1=vbuc2
lda #'b'
ldy.z k
sta screen,y
// [13] (byte) popup_selector::k#1 ← ++ (byte) popup_selector::k#2 -- vbuz1=_inc_vbuz1
inc.z k
// [9] phi from popup_selector::@2 to popup_selector::@1 [phi:popup_selector::@2->popup_selector::@1]
b1_from_b2:
// [9] phi (byte) opcode#12 = (byte) 'b' [phi:popup_selector::@2->popup_selector::@1#0] -- vbuz1=vbuc1
lda #'b'
sta.z opcode
// [9] phi (byte) popup_selector::k#2 = (byte) popup_selector::k#1 [phi:popup_selector::@2->popup_selector::@1#1] -- register_copy
jmp b1
}
// File Data
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [4] *((const byte*) screen#0+(byte) $28) ← (byte) 'a' [ ] ( main:2 [ ] ) always clobbers reg byte a
Statement [12] *((const byte*) screen#0 + (byte) popup_selector::k#2) ← (byte) 'b' [ popup_selector::k#2 ] ( main:2::popup_selector:5 [ popup_selector::k#2 ] ) always clobbers reg byte a
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ popup_selector::k#2 popup_selector::k#1 ]
Statement [4] *((const byte*) screen#0+(byte) $28) ← (byte) 'a' [ ] ( main:2 [ ] ) always clobbers reg byte a
Statement [12] *((const byte*) screen#0 + (byte) popup_selector::k#2) ← (byte) 'b' [ popup_selector::k#2 ] ( main:2::popup_selector:5 [ popup_selector::k#2 ] ) always clobbers reg byte a
Potential registers zp ZP_BYTE:2 [ popup_selector::k#2 popup_selector::k#1 ] : zp ZP_BYTE:2 , reg byte x , reg byte y ,
Potential registers zp ZP_BYTE:3 [ opcode#12 ] : zp ZP_BYTE:3 , reg byte a , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [popup_selector] 36.67: zp ZP_BYTE:2 [ popup_selector::k#2 popup_selector::k#1 ]
Uplift Scope [] 0.5: zp ZP_BYTE:3 [ opcode#12 ]
Uplift Scope [main]
Uplifting [popup_selector] best 394 combination reg byte x [ popup_selector::k#2 popup_selector::k#1 ]
Uplifting [] best 331 combination reg byte a [ opcode#12 ]
Uplifting [main] best 331 combination
ASSEMBLER BEFORE OPTIMIZATION
// File Comments
// Demonstrates a problem where constant loophead unrolling results in an error
// The result is a NullPointerException
// The cause is that the Unroller does not handle the variable opcode correctly.
// The Unroller gets the verwions for opcode wrong because it misses the fact that it is modified inside call to popup_selector()
// Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
// Global Constants & labels
.label screen = $400
// @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
// Offending unroll variable
main: {
// [4] *((const byte*) screen#0+(byte) $28) ← (byte) 'a' -- _deref_pbuc1=vbuc2
lda #'a'
sta screen+$28
// [5] call popup_selector
// [8] phi from main to popup_selector [phi:main->popup_selector]
popup_selector_from_main:
jsr popup_selector
jmp b1
// main::@1
b1:
// [6] *((const byte*) screen#0+(byte) $29) ← (byte) opcode#12 -- _deref_pbuc1=vbuaa
sta screen+$29
jmp breturn
// main::@return
breturn:
// [7] return
rts
}
// popup_selector
popup_selector: {
// [9] phi from popup_selector to popup_selector::@1 [phi:popup_selector->popup_selector::@1]
b1_from_popup_selector:
// [9] phi (byte) opcode#12 = (byte) 'a' [phi:popup_selector->popup_selector::@1#0] -- vbuaa=vbuc1
lda #'a'
// [9] phi (byte) popup_selector::k#2 = (byte) 0 [phi:popup_selector->popup_selector::@1#1] -- vbuxx=vbuc1
ldx #0
jmp b1
// popup_selector::@1
b1:
// [10] if((byte) popup_selector::k#2<(byte) 2+(byte) 1) goto popup_selector::@2 -- vbuxx_lt_vbuc1_then_la1
cpx #2+1
bcc b2
jmp breturn
// popup_selector::@return
breturn:
// [11] return
rts
// popup_selector::@2
b2:
// [12] *((const byte*) screen#0 + (byte) popup_selector::k#2) ← (byte) 'b' -- pbuc1_derefidx_vbuxx=vbuc2
lda #'b'
sta screen,x
// [13] (byte) popup_selector::k#1 ← ++ (byte) popup_selector::k#2 -- vbuxx=_inc_vbuxx
inx
// [9] phi from popup_selector::@2 to popup_selector::@1 [phi:popup_selector::@2->popup_selector::@1]
b1_from_b2:
// [9] phi (byte) opcode#12 = (byte) 'b' [phi:popup_selector::@2->popup_selector::@1#0] -- vbuaa=vbuc1
lda #'b'
// [9] phi (byte) popup_selector::k#2 = (byte) popup_selector::k#1 [phi:popup_selector::@2->popup_selector::@1#1] -- register_copy
jmp b1
}
// File Data
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
Removing instruction jmp breturn
Removing instruction jmp b1
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 popup_selector_from_main:
Removing instruction b1:
Removing instruction breturn:
Removing instruction b1_from_popup_selector:
Removing instruction breturn:
Removing instruction b1_from_b2:
Succesful ASM optimization Pass5UnusedLabelElimination
Updating BasicUpstart to call main directly
Removing instruction jsr main
Succesful ASM optimization Pass5SkipBegin
Removing instruction lda #'b'
Succesful ASM optimization Pass5UnnecesaryLoadElimination
Removing instruction bbegin:
Succesful ASM optimization Pass5UnusedLabelElimination
FINAL SYMBOL TABLE
(label) @1
(label) @begin
(label) @end
(void()) main()
(label) main::@1
(label) main::@return
(byte) opcode
(byte) opcode#12 reg byte a 0.5
(void()) popup_selector()
(label) popup_selector::@1
(label) popup_selector::@2
(label) popup_selector::@return
(byte) popup_selector::k
(byte) popup_selector::k#1 reg byte x 22.0
(byte) popup_selector::k#2 reg byte x 14.666666666666666
(byte*) screen
(const byte*) screen#0 screen = (byte*) 1024
reg byte x [ popup_selector::k#2 popup_selector::k#1 ]
reg byte a [ opcode#12 ]
FINAL ASSEMBLER
Score: 233
// File Comments
// Demonstrates a problem where constant loophead unrolling results in an error
// The result is a NullPointerException
// The cause is that the Unroller does not handle the variable opcode correctly.
// The Unroller gets the verwions for opcode wrong because it misses the fact that it is modified inside call to popup_selector()
// Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
// Global Constants & labels
.label screen = $400
// @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
// Offending unroll variable
main: {
// screen[40] = opcode
// [4] *((const byte*) screen#0+(byte) $28) ← (byte) 'a' -- _deref_pbuc1=vbuc2
lda #'a'
sta screen+$28
// popup_selector()
// [5] call popup_selector
// [8] phi from main to popup_selector [phi:main->popup_selector]
jsr popup_selector
// main::@1
// screen[41] = opcode
// [6] *((const byte*) screen#0+(byte) $29) ← (byte) opcode#12 -- _deref_pbuc1=vbuaa
sta screen+$29
// main::@return
// }
// [7] return
rts
}
// popup_selector
popup_selector: {
// [9] phi from popup_selector to popup_selector::@1 [phi:popup_selector->popup_selector::@1]
// [9] phi (byte) opcode#12 = (byte) 'a' [phi:popup_selector->popup_selector::@1#0] -- vbuaa=vbuc1
lda #'a'
// [9] phi (byte) popup_selector::k#2 = (byte) 0 [phi:popup_selector->popup_selector::@1#1] -- vbuxx=vbuc1
ldx #0
// popup_selector::@1
b1:
// for (byte k = 0; k <= 2; k++)
// [10] if((byte) popup_selector::k#2<(byte) 2+(byte) 1) goto popup_selector::@2 -- vbuxx_lt_vbuc1_then_la1
cpx #2+1
bcc b2
// popup_selector::@return
// }
// [11] return
rts
// popup_selector::@2
b2:
// screen[k] = opcode
// [12] *((const byte*) screen#0 + (byte) popup_selector::k#2) ← (byte) 'b' -- pbuc1_derefidx_vbuxx=vbuc2
lda #'b'
sta screen,x
// for (byte k = 0; k <= 2; k++)
// [13] (byte) popup_selector::k#1 ← ++ (byte) popup_selector::k#2 -- vbuxx=_inc_vbuxx
inx
// [9] phi from popup_selector::@2 to popup_selector::@1 [phi:popup_selector::@2->popup_selector::@1]
// [9] phi (byte) opcode#12 = (byte) 'b' [phi:popup_selector::@2->popup_selector::@1#0] -- vbuaa=vbuc1
// [9] phi (byte) popup_selector::k#2 = (byte) popup_selector::k#1 [phi:popup_selector::@2->popup_selector::@1#1] -- register_copy
jmp b1
}
// File Data