1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-10 10:31:27 +00:00

Fixed optimization of constant addition in double array indexing. Closes #150

This commit is contained in:
jespergravgaard 2019-03-20 07:20:00 +01:00
parent 5791875d2d
commit 9a50e54928
15 changed files with 787 additions and 77 deletions

View File

@ -4,6 +4,7 @@ import dk.camelot64.kickc.model.ControlFlowBlock;
import dk.camelot64.kickc.model.Program;
import dk.camelot64.kickc.model.VariableReferenceInfos;
import dk.camelot64.kickc.model.iterator.ProgramValue;
import dk.camelot64.kickc.model.iterator.ProgramValueIterator;
import dk.camelot64.kickc.model.operators.Operator;
import dk.camelot64.kickc.model.operators.Operators;
import dk.camelot64.kickc.model.statements.Statement;
@ -38,48 +39,36 @@ public class Pass2ConstantAdditionElimination extends Pass2SsaOptimization {
*/
@Override
public boolean step() {
boolean optimized = false;
final boolean[] optimized = {false};
this.variableReferenceInfos = getProgram().getVariableReferenceInfos();
// Examine all assignments - performing constant consolidation
ProgramValueIterator.execute(getProgram(), (programValue, currentStmt, stmtIt, currentBlock) -> {
if(programValue.get() instanceof PointerDereferenceIndexed) {
optimized[0] |= optimizePointerDereferenceIndexed(programValue);
}
});
// Examine all assignments - performing constant consolidation for +/-
for(ControlFlowBlock block : getGraph().getAllBlocks()) {
for(Statement statement : block.getStatements()) {
if(statement instanceof StatementAssignment) {
StatementAssignment assignment = (StatementAssignment) statement;
if(assignment.getlValue() instanceof PointerDereferenceIndexed) {
optimized |= optimizePointerDereferenceIndexed(new ProgramValue.LValue(assignment));
}
if(assignment.getrValue1() instanceof PointerDereferenceIndexed) {
optimized |= optimizePointerDereferenceIndexed(new ProgramValue.RValue1(assignment));
}
if(assignment.getrValue2() instanceof PointerDereferenceIndexed) {
optimized |= optimizePointerDereferenceIndexed(new ProgramValue.RValue2(assignment));
}
Operator operator = assignment.getOperator();
if(operator != null) {
switch(operator.getOperator()) {
case "+":
optimized |= optimizePlus(assignment);
optimized[0] |= optimizePlus(assignment);
break;
case "*idx":
optimized |= optimizeArrayDeref(assignment);
optimized[0] |= optimizeArrayDeref(assignment);
break;
}
}
} else if(statement instanceof StatementConditionalJump) {
StatementConditionalJump jump = (StatementConditionalJump) statement;
if(jump.getrValue1() instanceof PointerDereferenceIndexed) {
optimized |= optimizePointerDereferenceIndexed(new ProgramValue.CondRValue1(jump));
}
if(jump.getrValue2() instanceof PointerDereferenceIndexed) {
optimized |= optimizePointerDereferenceIndexed(new ProgramValue.CondRValue2(jump));
}
}
}
}
return optimized;
return optimized[0];
}
private boolean optimizePointerDereferenceIndexed(ProgramValue value) {

View File

@ -454,7 +454,7 @@ public class Pass4CodeGeneration {
try {
generateStatementAsm(asm, block, statement, aluState, true);
} catch(AsmFragmentTemplateSynthesizer.UnknownFragmentException e) {
throw new CompileError("Unknown fragment for statement " + statement.toString(program, false), e);
throw new CompileError("Unknown fragment for statement " + statement.toString(program, false)+"\nMissing ASM fragment "+e.getFragmentSignature(), e);
}
}
}

View File

@ -32,15 +32,9 @@ public class TestPrograms {
public TestPrograms() {
}
@BeforeClass
public static void setUp() {
AsmFragmentTemplateSynthesizer.initialize("src/main/fragment/");
}
@AfterClass
public static void tearDown() {
CompileLog log = getLogSysout();
AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, false, false);
@Test
public void testDoubleIndexingArrays() throws IOException, URISyntaxException {
compileAndCompare("double-indexing-arrays");
}
@Test
@ -48,11 +42,6 @@ public class TestPrograms {
compileAndCompare("inline-kasm-clobber");
}
private static CompileLog getLogSysout() {
CompileLog log = new CompileLog();
log.setSysOut(true);
return log;
}
@Test
public void testInlineAsmClobberNone() throws IOException, URISyntaxException {
@ -1349,6 +1338,23 @@ public class TestPrograms {
assertError("condition-type-mismatch", "Type mismatch non-boolean condition");
}
@BeforeClass
public static void setUp() {
AsmFragmentTemplateSynthesizer.initialize("src/main/fragment/");
}
@AfterClass
public static void tearDown() {
CompileLog log = getLogSysout();
AsmFragmentTemplateUsages.logUsages(log, false, false, false, false, false, false);
}
private static CompileLog getLogSysout() {
CompileLog log = new CompileLog();
log.setSysOut(true);
return log;
}
private void assertError(String kcFile, String expectError) throws IOException, URISyntaxException {
assertError(kcFile, expectError, true);
}

View File

@ -0,0 +1,23 @@
// Tests that constant offset indexing into arrays is handled correctly
byte[1000] MAPDATA;
byte[256] COLORMAP1;
byte[256] COLORMAP2;
byte* SCREEN = $0400;
byte* COLS = $d800;
void main() {
for (byte x: 0..200) {
SCREEN[x] = MAPDATA[x];
COLS[x] = COLORMAP1[MAPDATA[x]];
SCREEN[200+x] = MAPDATA[200+x];
COLS[200+x] = COLORMAP1[MAPDATA[200+x]];
SCREEN[400+x] = MAPDATA[400+x];
COLS[400+x] = COLORMAP1[MAPDATA[400+x]];
SCREEN[600+x] = MAPDATA[600+x];
COLS[600+x] = COLORMAP2[MAPDATA[600+x]];
SCREEN[800+x] = MAPDATA[800+x];
COLS[800+x] = COLORMAP2[MAPDATA[800+x]];
}
}

View File

@ -8908,6 +8908,8 @@ Constant (const byte*) print_str_lines::str#2 = FORM_TEXT#0
Successful SSA optimization Pass2ConstantIdentification
Constant (const byte*) print_str_lines::str#1 = FORM_COLS#0
Successful SSA optimization Pass2ConstantIdentification
Consolidated array index constant in *(bitmap_plot_xhi#0+0)
Consolidated array index constant in *(bitmap_plot_xlo#0+0)
Consolidated array index constant in assignment *(gfx_init_vic_bitmap::lines_x#0+1 + gfx_init_vic_bitmap::$2)
Consolidated array index constant in assignment *(gfx_init_vic_bitmap::lines_y#0+1 + gfx_init_vic_bitmap::$3)
Successful SSA optimization Pass2ConstantAdditionElimination
@ -8922,7 +8924,7 @@ Removing PHI-reference to removed block (form_mode::@2) in block form_mode::@ret
if() condition always true - replacing block destination [720] if(true) goto form_mode::@3
Successful SSA optimization Pass2ConstantIfs
Successful SSA optimization Pass2ConstantStringConsolidation
Fixing inline constructor with bitmap_clear::$3 ← *(bitmap_plot_xhi#0 + 0) w= *(bitmap_plot_xlo#0 + 0)
Fixing inline constructor with bitmap_clear::$3 ← *(bitmap_plot_xhi#0+0) w= *(bitmap_plot_xlo#0+0)
Fixing inline constructor with bitmap_plot::$2 ← *(bitmap_plot_xhi#0 + bitmap_plot::x#4) w= *(bitmap_plot_xlo#0 + bitmap_plot::x#4)
Fixing inline constructor with bitmap_plot::$3 ← *(bitmap_plot_yhi#0 + bitmap_plot::y#4) w= *(bitmap_plot_ylo#0 + bitmap_plot::y#4)
Fixing inline constructor with form_field_ptr::$2 ← *(form_line_hi#0 + form_field_ptr::y#0) w= *(form_line_lo#0 + form_field_ptr::y#0)
@ -9125,9 +9127,6 @@ Redundant Phi (byte) form_fields_cnt#21 (const byte) form_fields_cnt#0
Successful SSA optimization Pass2RedundantPhiElimination
Constant (const byte) form_field_idx#7 = form_fields_cnt#0-1
Successful SSA optimization Pass2ConstantIdentification
Consolidated array index constant in *(bitmap_plot_xhi#0+0)
Consolidated array index constant in *(bitmap_plot_xlo#0+0)
Successful SSA optimization Pass2ConstantAdditionElimination
Culled Empty Block (label) gfx_mode::@16
Successful SSA optimization Pass2CullEmptyBlocks
Inlining constant with var siblings (const byte) dtvSetCpuBankSegment1::cpuBankIdx#2

View File

@ -7953,6 +7953,8 @@ Constant (const byte[]) MENU_TEXT#0 = "C64DTV Graphics Modes CCLHBME@
Successful SSA optimization Pass2ConstantIdentification
Constant (const byte*) print_str_lines::str#1 = MENU_TEXT#0
Successful SSA optimization Pass2ConstantIdentification
Consolidated array index constant in *(bitmap_plot_xhi#0+0)
Consolidated array index constant in *(bitmap_plot_xlo#0+0)
Consolidated array index constant in assignment *(mode_stdbitmap::lines_x#0+1 + mode_stdbitmap::$28)
Consolidated array index constant in assignment *(mode_stdbitmap::lines_y#0+1 + mode_stdbitmap::$29)
Successful SSA optimization Pass2ConstantAdditionElimination
@ -7962,7 +7964,7 @@ if() condition always true - replacing block destination [232] if(true) goto men
if() condition always true - replacing block destination [297] if(true) goto mode_ctrl::@2
Successful SSA optimization Pass2ConstantIfs
Successful SSA optimization Pass2ConstantStringConsolidation
Fixing inline constructor with bitmap_clear::$3 ← *(bitmap_plot_xhi#0 + 0) w= *(bitmap_plot_xlo#0 + 0)
Fixing inline constructor with bitmap_clear::$3 ← *(bitmap_plot_xhi#0+0) w= *(bitmap_plot_xlo#0+0)
Fixing inline constructor with bitmap_plot::$2 ← *(bitmap_plot_xhi#0 + bitmap_plot::x#4) w= *(bitmap_plot_xlo#0 + bitmap_plot::x#4)
Fixing inline constructor with bitmap_plot::$3 ← *(bitmap_plot_yhi#0 + bitmap_plot::y#4) w= *(bitmap_plot_ylo#0 + bitmap_plot::y#4)
Successful SSA optimization Pass2FixInlineConstructors
@ -8190,9 +8192,6 @@ Redundant Phi (byte) mode_8bpppixelcell::ch#7 (byte) mode_8bpppixelcell::ch#8
Redundant Phi (byte) dtv_control#234 (byte) dtv_control#244
Redundant Phi (byte) dtv_control#235 (const byte) dtv_control#51
Successful SSA optimization Pass2RedundantPhiElimination
Consolidated array index constant in *(bitmap_plot_xhi#0+0)
Consolidated array index constant in *(bitmap_plot_xlo#0+0)
Successful SSA optimization Pass2ConstantAdditionElimination
Culled Empty Block (label) main::@1
Successful SSA optimization Pass2CullEmptyBlocks
Self Phi Eliminated (byte) dtv_control#244

View File

@ -57,8 +57,8 @@ Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte*) screen#0 = ((byte*))$400
Constant (const byte) main::j#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Consolidated constant in assignment main::$2
Consolidated array index constant in assignment *(screen#0+$26 + main::$4)
Consolidated constant in assignment main::$2
Successful SSA optimization Pass2ConstantAdditionElimination
Inferred type updated to byte/signed word/word/dword/signed dword in [2] (byte*~) main::$1 ← (byte/signed word/word/dword/signed dword~) main::$0
Resolved ranged next value main::j#1 ← ++ main::j#2 to ++

View File

@ -0,0 +1,47 @@
// Tests that constant offset indexing into arrays is handled correctly
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
.label SCREEN = $400
.label COLS = $d800
main: {
ldx #0
b1:
lda MAPDATA,x
sta SCREEN,x
lda MAPDATA,x
tay
lda COLORMAP1,y
sta COLS,x
lda MAPDATA+$c8,x
sta SCREEN+$c8,x
lda MAPDATA+$c8,x
tay
lda COLORMAP1,y
sta COLS+$c8,x
lda MAPDATA+$190,x
sta SCREEN+$190,x
lda MAPDATA+$190,x
tay
lda COLORMAP1,y
sta COLS+$190,x
lda MAPDATA+$258,x
sta SCREEN+$258,x
lda MAPDATA+$258,x
tay
lda COLORMAP2,y
sta COLS+$258,x
lda MAPDATA+$320,x
sta SCREEN+$320,x
lda MAPDATA+$320,x
tay
lda COLORMAP2,y
sta COLS+$320,x
inx
cpx #$c9
bne b1
rts
}
MAPDATA: .fill $3e8, 0
COLORMAP1: .fill $100, 0
COLORMAP2: .fill $100, 0

View File

@ -0,0 +1,30 @@
@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::x#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@1/(byte) main::x#1 )
[6] *((const byte*) SCREEN#0 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0 + (byte) main::x#2)
[7] *((const byte*) COLS#0 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0 + (byte) main::x#2))
[8] *((const byte*) SCREEN#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2)
[9] *((const byte*) COLS#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2))
[10] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2)
[11] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2))
[12] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2)
[13] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP2#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2))
[14] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2)
[15] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP2#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2))
[16] (byte) main::x#1 ← ++ (byte) main::x#2
[17] if((byte) main::x#1!=(byte/word/signed word/dword/signed dword) $c9) goto main::@1
to:main::@return
main::@return: scope:[main] from main::@1
[18] return
to:@return

View File

@ -0,0 +1,597 @@
CONTROL FLOW GRAPH SSA
@begin: scope:[] from
(byte[$3e8]) MAPDATA#0 ← { fill( $3e8, 0) }
(byte[$100]) COLORMAP1#0 ← { fill( $100, 0) }
(byte[$100]) COLORMAP2#0 ← { fill( $100, 0) }
(byte*) SCREEN#0 ← ((byte*)) (word/signed word/dword/signed dword) $400
(byte*) COLS#0 ← ((byte*)) (word/dword/signed dword) $d800
to:@1
main: scope:[main] from @1
(byte*) COLS#2 ← phi( @1/(byte*) COLS#3 )
(byte*) SCREEN#2 ← phi( @1/(byte*) SCREEN#3 )
(byte) main::x#0 ← (byte/signed byte/word/signed word/dword/signed dword) 0
to:main::@1
main::@1: scope:[main] from main main::@1
(byte*) COLS#1 ← phi( main/(byte*) COLS#2 main::@1/(byte*) COLS#1 )
(byte*) SCREEN#1 ← phi( main/(byte*) SCREEN#2 main::@1/(byte*) SCREEN#1 )
(byte) main::x#2 ← phi( main/(byte) main::x#0 main::@1/(byte) main::x#1 )
*((byte*) SCREEN#1 + (byte) main::x#2) ← *((byte[$3e8]) MAPDATA#0 + (byte) main::x#2)
*((byte*) COLS#1 + (byte) main::x#2) ← *((byte[$100]) COLORMAP1#0 + *((byte[$3e8]) MAPDATA#0 + (byte) main::x#2))
(byte/word/signed word/dword/signed dword~) main::$0 ← (byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2
(byte/word/signed word/dword/signed dword~) main::$1 ← (byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2
*((byte*) SCREEN#1 + (byte/word/signed word/dword/signed dword~) main::$0) ← *((byte[$3e8]) MAPDATA#0 + (byte/word/signed word/dword/signed dword~) main::$1)
(byte/word/signed word/dword/signed dword~) main::$2 ← (byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2
(byte/word/signed word/dword/signed dword~) main::$3 ← (byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2
*((byte*) COLS#1 + (byte/word/signed word/dword/signed dword~) main::$2) ← *((byte[$100]) COLORMAP1#0 + *((byte[$3e8]) MAPDATA#0 + (byte/word/signed word/dword/signed dword~) main::$3))
(word/signed word/dword/signed dword~) main::$4 ← (word/signed word/dword/signed dword) $190 + (byte) main::x#2
(word/signed word/dword/signed dword~) main::$5 ← (word/signed word/dword/signed dword) $190 + (byte) main::x#2
*((byte*) SCREEN#1 + (word/signed word/dword/signed dword~) main::$4) ← *((byte[$3e8]) MAPDATA#0 + (word/signed word/dword/signed dword~) main::$5)
(word/signed word/dword/signed dword~) main::$6 ← (word/signed word/dword/signed dword) $190 + (byte) main::x#2
(word/signed word/dword/signed dword~) main::$7 ← (word/signed word/dword/signed dword) $190 + (byte) main::x#2
*((byte*) COLS#1 + (word/signed word/dword/signed dword~) main::$6) ← *((byte[$100]) COLORMAP1#0 + *((byte[$3e8]) MAPDATA#0 + (word/signed word/dword/signed dword~) main::$7))
(word/signed word/dword/signed dword~) main::$8 ← (word/signed word/dword/signed dword) $258 + (byte) main::x#2
(word/signed word/dword/signed dword~) main::$9 ← (word/signed word/dword/signed dword) $258 + (byte) main::x#2
*((byte*) SCREEN#1 + (word/signed word/dword/signed dword~) main::$8) ← *((byte[$3e8]) MAPDATA#0 + (word/signed word/dword/signed dword~) main::$9)
(word/signed word/dword/signed dword~) main::$10 ← (word/signed word/dword/signed dword) $258 + (byte) main::x#2
(word/signed word/dword/signed dword~) main::$11 ← (word/signed word/dword/signed dword) $258 + (byte) main::x#2
*((byte*) COLS#1 + (word/signed word/dword/signed dword~) main::$10) ← *((byte[$100]) COLORMAP2#0 + *((byte[$3e8]) MAPDATA#0 + (word/signed word/dword/signed dword~) main::$11))
(word/signed word/dword/signed dword~) main::$12 ← (word/signed word/dword/signed dword) $320 + (byte) main::x#2
(word/signed word/dword/signed dword~) main::$13 ← (word/signed word/dword/signed dword) $320 + (byte) main::x#2
*((byte*) SCREEN#1 + (word/signed word/dword/signed dword~) main::$12) ← *((byte[$3e8]) MAPDATA#0 + (word/signed word/dword/signed dword~) main::$13)
(word/signed word/dword/signed dword~) main::$14 ← (word/signed word/dword/signed dword) $320 + (byte) main::x#2
(word/signed word/dword/signed dword~) main::$15 ← (word/signed word/dword/signed dword) $320 + (byte) main::x#2
*((byte*) COLS#1 + (word/signed word/dword/signed dword~) main::$14) ← *((byte[$100]) COLORMAP2#0 + *((byte[$3e8]) MAPDATA#0 + (word/signed word/dword/signed dword~) main::$15))
(byte) main::x#1 ← (byte) main::x#2 + rangenext(0,$c8)
(bool~) main::$16 ← (byte) main::x#1 != rangelast(0,$c8)
if((bool~) main::$16) goto main::@1
to:main::@return
main::@return: scope:[main] from main::@1
return
to:@return
@1: scope:[] from @begin
(byte*) COLS#3 ← phi( @begin/(byte*) COLS#0 )
(byte*) SCREEN#3 ← phi( @begin/(byte*) SCREEN#0 )
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
(byte[$100]) COLORMAP1
(byte[$100]) COLORMAP1#0
(byte[$100]) COLORMAP2
(byte[$100]) COLORMAP2#0
(byte*) COLS
(byte*) COLS#0
(byte*) COLS#1
(byte*) COLS#2
(byte*) COLS#3
(byte[$3e8]) MAPDATA
(byte[$3e8]) MAPDATA#0
(byte*) SCREEN
(byte*) SCREEN#0
(byte*) SCREEN#1
(byte*) SCREEN#2
(byte*) SCREEN#3
(void()) main()
(byte/word/signed word/dword/signed dword~) main::$0
(byte/word/signed word/dword/signed dword~) main::$1
(word/signed word/dword/signed dword~) main::$10
(word/signed word/dword/signed dword~) main::$11
(word/signed word/dword/signed dword~) main::$12
(word/signed word/dword/signed dword~) main::$13
(word/signed word/dword/signed dword~) main::$14
(word/signed word/dword/signed dword~) main::$15
(bool~) main::$16
(byte/word/signed word/dword/signed dword~) main::$2
(byte/word/signed word/dword/signed dword~) main::$3
(word/signed word/dword/signed dword~) main::$4
(word/signed word/dword/signed dword~) main::$5
(word/signed word/dword/signed dword~) main::$6
(word/signed word/dword/signed dword~) main::$7
(word/signed word/dword/signed dword~) main::$8
(word/signed word/dword/signed dword~) main::$9
(label) main::@1
(label) main::@return
(byte) main::x
(byte) main::x#0
(byte) main::x#1
(byte) main::x#2
Culled Empty Block (label) @2
Successful SSA optimization Pass2CullEmptyBlocks
Alias (byte*) SCREEN#0 = (byte*) SCREEN#3
Alias (byte*) COLS#0 = (byte*) COLS#3
Successful SSA optimization Pass2AliasElimination
Self Phi Eliminated (byte*) SCREEN#1
Self Phi Eliminated (byte*) COLS#1
Successful SSA optimization Pass2SelfPhiElimination
Redundant Phi (byte*) SCREEN#2 (byte*) SCREEN#0
Redundant Phi (byte*) COLS#2 (byte*) COLS#0
Redundant Phi (byte*) SCREEN#1 (byte*) SCREEN#2
Redundant Phi (byte*) COLS#1 (byte*) COLS#2
Successful SSA optimization Pass2RedundantPhiElimination
Simple Condition (bool~) main::$16 [36] if((byte) main::x#1!=rangelast(0,$c8)) goto main::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Constant (const byte[$3e8]) MAPDATA#0 = { fill( $3e8, 0) }
Constant (const byte[$100]) COLORMAP1#0 = { fill( $100, 0) }
Constant (const byte[$100]) COLORMAP2#0 = { fill( $100, 0) }
Constant (const byte*) SCREEN#0 = ((byte*))$400
Constant (const byte*) COLS#0 = ((byte*))$d800
Constant (const byte) main::x#0 = 0
Successful SSA optimization Pass2ConstantIdentification
Consolidated array index constant in assignment *(MAPDATA#0+$c8 + main::$1)
Consolidated array index constant in assignment *(SCREEN#0+$c8 + main::$0)
Consolidated array index constant in assignment *(MAPDATA#0+$c8 + main::$3)
Consolidated array index constant in assignment *(COLS#0+$c8 + main::$2)
Consolidated array index constant in assignment *(MAPDATA#0+$190 + main::$5)
Consolidated array index constant in assignment *(SCREEN#0+$190 + main::$4)
Consolidated array index constant in assignment *(MAPDATA#0+$190 + main::$7)
Consolidated array index constant in assignment *(COLS#0+$190 + main::$6)
Consolidated array index constant in assignment *(MAPDATA#0+$258 + main::$9)
Consolidated array index constant in assignment *(SCREEN#0+$258 + main::$8)
Consolidated array index constant in assignment *(MAPDATA#0+$258 + main::$11)
Consolidated array index constant in assignment *(COLS#0+$258 + main::$10)
Consolidated array index constant in assignment *(MAPDATA#0+$320 + main::$13)
Consolidated array index constant in assignment *(SCREEN#0+$320 + main::$12)
Consolidated array index constant in assignment *(MAPDATA#0+$320 + main::$15)
Consolidated array index constant in assignment *(COLS#0+$320 + main::$14)
Successful SSA optimization Pass2ConstantAdditionElimination
Inferred type updated to byte in [3] (byte/word/signed word/dword/signed dword~) main::$0 ← (byte) main::x#2
Inferred type updated to byte in [4] (byte/word/signed word/dword/signed dword~) main::$1 ← (byte) main::x#2
Inferred type updated to byte in [6] (byte/word/signed word/dword/signed dword~) main::$2 ← (byte) main::x#2
Inferred type updated to byte in [7] (byte/word/signed word/dword/signed dword~) main::$3 ← (byte) main::x#2
Inferred type updated to byte in [9] (word/signed word/dword/signed dword~) main::$4 ← (byte) main::x#2
Inferred type updated to byte in [10] (word/signed word/dword/signed dword~) main::$5 ← (byte) main::x#2
Inferred type updated to byte in [12] (word/signed word/dword/signed dword~) main::$6 ← (byte) main::x#2
Inferred type updated to byte in [13] (word/signed word/dword/signed dword~) main::$7 ← (byte) main::x#2
Inferred type updated to byte in [15] (word/signed word/dword/signed dword~) main::$8 ← (byte) main::x#2
Inferred type updated to byte in [16] (word/signed word/dword/signed dword~) main::$9 ← (byte) main::x#2
Inferred type updated to byte in [18] (word/signed word/dword/signed dword~) main::$10 ← (byte) main::x#2
Inferred type updated to byte in [19] (word/signed word/dword/signed dword~) main::$11 ← (byte) main::x#2
Inferred type updated to byte in [21] (word/signed word/dword/signed dword~) main::$12 ← (byte) main::x#2
Inferred type updated to byte in [22] (word/signed word/dword/signed dword~) main::$13 ← (byte) main::x#2
Inferred type updated to byte in [24] (word/signed word/dword/signed dword~) main::$14 ← (byte) main::x#2
Inferred type updated to byte in [25] (word/signed word/dword/signed dword~) main::$15 ← (byte) main::x#2
Resolved ranged next value main::x#1 ← ++ main::x#2 to ++
Resolved ranged comparison value if(main::x#1!=rangelast(0,$c8)) goto main::@1 to (byte/word/signed word/dword/signed dword) $c9
Alias (byte) main::x#2 = (byte~) main::$0 (byte~) main::$1 (byte~) main::$2 (byte~) main::$3 (byte~) main::$4 (byte~) main::$5 (byte~) main::$6 (byte~) main::$7 (byte~) main::$8 (byte~) main::$9 (byte~) main::$10 (byte~) main::$11 (byte~) main::$12 (byte~) main::$13 (byte~) main::$14 (byte~) main::$15
Successful SSA optimization Pass2AliasElimination
Inlining constant with var siblings (const byte) main::x#0
Constant inlined main::x#0 = (byte/signed byte/word/signed word/dword/signed dword) 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 @end
Adding NOP phi() at start of main
CALL GRAPH
Calls in [] to main:2
Created 1 initial phi equivalence classes
Coalesced [19] main::x#3 ← main::x#1
Coalesced down to 1 phi equivalence classes
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::x#2 ← phi( main/(byte/signed byte/word/signed word/dword/signed dword) 0 main::@1/(byte) main::x#1 )
[6] *((const byte*) SCREEN#0 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0 + (byte) main::x#2)
[7] *((const byte*) COLS#0 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0 + (byte) main::x#2))
[8] *((const byte*) SCREEN#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2)
[9] *((const byte*) COLS#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2))
[10] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2)
[11] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2))
[12] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2)
[13] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP2#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2))
[14] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2)
[15] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP2#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2))
[16] (byte) main::x#1 ← ++ (byte) main::x#2
[17] if((byte) main::x#1!=(byte/word/signed word/dword/signed dword) $c9) goto main::@1
to:main::@return
main::@return: scope:[main] from main::@1
[18] return
to:@return
VARIABLE REGISTER WEIGHTS
(byte[$100]) COLORMAP1
(byte[$100]) COLORMAP2
(byte*) COLS
(byte[$3e8]) MAPDATA
(byte*) SCREEN
(void()) main()
(byte) main::x
(byte) main::x#1 16.5
(byte) main::x#2 22.0
Initial phi equivalence classes
[ main::x#2 main::x#1 ]
Complete equivalence classes
[ main::x#2 main::x#1 ]
Allocated zp ZP_BYTE:2 [ main::x#2 main::x#1 ]
INITIAL ASM
//SEG0 File Comments
// Tests that constant offset indexing into arrays is handled correctly
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
.label SCREEN = $400
.label COLS = $d800
//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 x = 2
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
b1_from_main:
//SEG12 [5] phi (byte) main::x#2 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1
lda #0
sta x
jmp b1
//SEG13 [5] phi from main::@1 to main::@1 [phi:main::@1->main::@1]
b1_from_b1:
//SEG14 [5] phi (byte) main::x#2 = (byte) main::x#1 [phi:main::@1->main::@1#0] -- register_copy
jmp b1
//SEG15 main::@1
b1:
//SEG16 [6] *((const byte*) SCREEN#0 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0 + (byte) main::x#2) -- pbuc1_derefidx_vbuz1=pbuc2_derefidx_vbuz1
ldy x
lda MAPDATA,y
sta SCREEN,y
//SEG17 [7] *((const byte*) COLS#0 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0 + (byte) main::x#2)) -- pbuc1_derefidx_vbuz1=pbuc2_derefidx_pbuc3_derefidx_vbuz1
ldx x
lda MAPDATA,x
tay
lda COLORMAP1,y
sta COLS,x
//SEG18 [8] *((const byte*) SCREEN#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) -- pbuc1_derefidx_vbuz1=pbuc2_derefidx_vbuz1
ldy x
lda MAPDATA+$c8,y
sta SCREEN+$c8,y
//SEG19 [9] *((const byte*) COLS#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2)) -- pbuc1_derefidx_vbuz1=pbuc2_derefidx_pbuc3_derefidx_vbuz1
ldx x
lda MAPDATA+$c8,x
tay
lda COLORMAP1,y
sta COLS+$c8,x
//SEG20 [10] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) -- pbuc1_derefidx_vbuz1=pbuc2_derefidx_vbuz1
ldy x
lda MAPDATA+$190,y
sta SCREEN+$190,y
//SEG21 [11] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2)) -- pbuc1_derefidx_vbuz1=pbuc2_derefidx_pbuc3_derefidx_vbuz1
ldx x
lda MAPDATA+$190,x
tay
lda COLORMAP1,y
sta COLS+$190,x
//SEG22 [12] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) -- pbuc1_derefidx_vbuz1=pbuc2_derefidx_vbuz1
ldy x
lda MAPDATA+$258,y
sta SCREEN+$258,y
//SEG23 [13] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP2#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2)) -- pbuc1_derefidx_vbuz1=pbuc2_derefidx_pbuc3_derefidx_vbuz1
ldx x
lda MAPDATA+$258,x
tay
lda COLORMAP2,y
sta COLS+$258,x
//SEG24 [14] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) -- pbuc1_derefidx_vbuz1=pbuc2_derefidx_vbuz1
ldy x
lda MAPDATA+$320,y
sta SCREEN+$320,y
//SEG25 [15] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP2#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2)) -- pbuc1_derefidx_vbuz1=pbuc2_derefidx_pbuc3_derefidx_vbuz1
ldx x
lda MAPDATA+$320,x
tay
lda COLORMAP2,y
sta COLS+$320,x
//SEG26 [16] (byte) main::x#1 ← ++ (byte) main::x#2 -- vbuz1=_inc_vbuz1
inc x
//SEG27 [17] if((byte) main::x#1!=(byte/word/signed word/dword/signed dword) $c9) goto main::@1 -- vbuz1_neq_vbuc1_then_la1
lda x
cmp #$c9
bne b1_from_b1
jmp breturn
//SEG28 main::@return
breturn:
//SEG29 [18] return
rts
}
MAPDATA: .fill $3e8, 0
COLORMAP1: .fill $100, 0
COLORMAP2: .fill $100, 0
REGISTER UPLIFT POTENTIAL REGISTERS
Statement [6] *((const byte*) SCREEN#0 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0 + (byte) main::x#2) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Removing always clobbered register reg byte a as potential for zp ZP_BYTE:2 [ main::x#2 main::x#1 ]
Statement [7] *((const byte*) COLS#0 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0 + (byte) main::x#2)) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [8] *((const byte*) SCREEN#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [9] *((const byte*) COLS#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2)) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [10] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [11] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2)) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [12] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [13] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP2#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2)) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [14] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [15] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP2#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2)) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [6] *((const byte*) SCREEN#0 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0 + (byte) main::x#2) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [7] *((const byte*) COLS#0 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0 + (byte) main::x#2)) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [8] *((const byte*) SCREEN#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [9] *((const byte*) COLS#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2)) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [10] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [11] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2)) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [12] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [13] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP2#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2)) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [14] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Statement [15] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP2#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2)) [ main::x#2 ] ( main:2 [ main::x#2 ] ) always clobbers reg byte a
Potential registers zp ZP_BYTE:2 [ main::x#2 main::x#1 ] : zp ZP_BYTE:2 , reg byte x , reg byte y ,
REGISTER UPLIFT SCOPES
Uplift Scope [main] 38.5: zp ZP_BYTE:2 [ main::x#2 main::x#1 ]
Uplift Scope []
Uplifting [main] best 1468 combination reg byte x [ main::x#2 main::x#1 ]
Uplifting [] best 1468 combination
ASSEMBLER BEFORE OPTIMIZATION
//SEG0 File Comments
// Tests that constant offset indexing into arrays is handled correctly
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(bbegin)
.pc = $80d "Program"
//SEG2 Global Constants & labels
.label SCREEN = $400
.label COLS = $d800
//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: {
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
b1_from_main:
//SEG12 [5] phi (byte) main::x#2 = (byte/signed byte/word/signed word/dword/signed dword) 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::x#2 = (byte) main::x#1 [phi:main::@1->main::@1#0] -- register_copy
jmp b1
//SEG15 main::@1
b1:
//SEG16 [6] *((const byte*) SCREEN#0 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0 + (byte) main::x#2) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx
lda MAPDATA,x
sta SCREEN,x
//SEG17 [7] *((const byte*) COLS#0 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0 + (byte) main::x#2)) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_pbuc3_derefidx_vbuxx
lda MAPDATA,x
tay
lda COLORMAP1,y
sta COLS,x
//SEG18 [8] *((const byte*) SCREEN#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx
lda MAPDATA+$c8,x
sta SCREEN+$c8,x
//SEG19 [9] *((const byte*) COLS#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2)) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_pbuc3_derefidx_vbuxx
lda MAPDATA+$c8,x
tay
lda COLORMAP1,y
sta COLS+$c8,x
//SEG20 [10] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx
lda MAPDATA+$190,x
sta SCREEN+$190,x
//SEG21 [11] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2)) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_pbuc3_derefidx_vbuxx
lda MAPDATA+$190,x
tay
lda COLORMAP1,y
sta COLS+$190,x
//SEG22 [12] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx
lda MAPDATA+$258,x
sta SCREEN+$258,x
//SEG23 [13] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP2#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2)) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_pbuc3_derefidx_vbuxx
lda MAPDATA+$258,x
tay
lda COLORMAP2,y
sta COLS+$258,x
//SEG24 [14] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx
lda MAPDATA+$320,x
sta SCREEN+$320,x
//SEG25 [15] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP2#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2)) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_pbuc3_derefidx_vbuxx
lda MAPDATA+$320,x
tay
lda COLORMAP2,y
sta COLS+$320,x
//SEG26 [16] (byte) main::x#1 ← ++ (byte) main::x#2 -- vbuxx=_inc_vbuxx
inx
//SEG27 [17] if((byte) main::x#1!=(byte/word/signed word/dword/signed dword) $c9) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
cpx #$c9
bne b1_from_b1
jmp breturn
//SEG28 main::@return
breturn:
//SEG29 [18] return
rts
}
MAPDATA: .fill $3e8, 0
COLORMAP1: .fill $100, 0
COLORMAP2: .fill $100, 0
ASSEMBLER OPTIMIZATIONS
Removing instruction jmp b1
Removing instruction jmp bend
Removing instruction jmp b1
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 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
(byte[$100]) COLORMAP1
(const byte[$100]) COLORMAP1#0 COLORMAP1 = { fill( $100, 0) }
(byte[$100]) COLORMAP2
(const byte[$100]) COLORMAP2#0 COLORMAP2 = { fill( $100, 0) }
(byte*) COLS
(const byte*) COLS#0 COLS = ((byte*))(word/dword/signed dword) $d800
(byte[$3e8]) MAPDATA
(const byte[$3e8]) MAPDATA#0 MAPDATA = { fill( $3e8, 0) }
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) $400
(void()) main()
(label) main::@1
(label) main::@return
(byte) main::x
(byte) main::x#1 reg byte x 16.5
(byte) main::x#2 reg byte x 22.0
reg byte x [ main::x#2 main::x#1 ]
FINAL ASSEMBLER
Score: 1366
//SEG0 File Comments
// Tests that constant offset indexing into arrays is handled correctly
//SEG1 Basic Upstart
.pc = $801 "Basic"
:BasicUpstart(main)
.pc = $80d "Program"
//SEG2 Global Constants & labels
.label SCREEN = $400
.label COLS = $d800
//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: {
//SEG11 [5] phi from main to main::@1 [phi:main->main::@1]
//SEG12 [5] phi (byte) main::x#2 = (byte/signed byte/word/signed word/dword/signed dword) 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::x#2 = (byte) main::x#1 [phi:main::@1->main::@1#0] -- register_copy
//SEG15 main::@1
b1:
//SEG16 [6] *((const byte*) SCREEN#0 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0 + (byte) main::x#2) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx
lda MAPDATA,x
sta SCREEN,x
//SEG17 [7] *((const byte*) COLS#0 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0 + (byte) main::x#2)) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_pbuc3_derefidx_vbuxx
lda MAPDATA,x
tay
lda COLORMAP1,y
sta COLS,x
//SEG18 [8] *((const byte*) SCREEN#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx
lda MAPDATA+$c8,x
sta SCREEN+$c8,x
//SEG19 [9] *((const byte*) COLS#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0+(byte/word/signed word/dword/signed dword) $c8 + (byte) main::x#2)) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_pbuc3_derefidx_vbuxx
lda MAPDATA+$c8,x
tay
lda COLORMAP1,y
sta COLS+$c8,x
//SEG20 [10] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx
lda MAPDATA+$190,x
sta SCREEN+$190,x
//SEG21 [11] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP1#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $190 + (byte) main::x#2)) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_pbuc3_derefidx_vbuxx
lda MAPDATA+$190,x
tay
lda COLORMAP1,y
sta COLS+$190,x
//SEG22 [12] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx
lda MAPDATA+$258,x
sta SCREEN+$258,x
//SEG23 [13] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP2#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $258 + (byte) main::x#2)) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_pbuc3_derefidx_vbuxx
lda MAPDATA+$258,x
tay
lda COLORMAP2,y
sta COLS+$258,x
//SEG24 [14] *((const byte*) SCREEN#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) ← *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_vbuxx
lda MAPDATA+$320,x
sta SCREEN+$320,x
//SEG25 [15] *((const byte*) COLS#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2) ← *((const byte[$100]) COLORMAP2#0 + *((const byte[$3e8]) MAPDATA#0+(word/signed word/dword/signed dword) $320 + (byte) main::x#2)) -- pbuc1_derefidx_vbuxx=pbuc2_derefidx_pbuc3_derefidx_vbuxx
lda MAPDATA+$320,x
tay
lda COLORMAP2,y
sta COLS+$320,x
//SEG26 [16] (byte) main::x#1 ← ++ (byte) main::x#2 -- vbuxx=_inc_vbuxx
inx
//SEG27 [17] if((byte) main::x#1!=(byte/word/signed word/dword/signed dword) $c9) goto main::@1 -- vbuxx_neq_vbuc1_then_la1
cpx #$c9
bne b1
//SEG28 main::@return
//SEG29 [18] return
rts
}
MAPDATA: .fill $3e8, 0
COLORMAP1: .fill $100, 0
COLORMAP2: .fill $100, 0

View File

@ -0,0 +1,21 @@
(label) @1
(label) @begin
(label) @end
(byte[$100]) COLORMAP1
(const byte[$100]) COLORMAP1#0 COLORMAP1 = { fill( $100, 0) }
(byte[$100]) COLORMAP2
(const byte[$100]) COLORMAP2#0 COLORMAP2 = { fill( $100, 0) }
(byte*) COLS
(const byte*) COLS#0 COLS = ((byte*))(word/dword/signed dword) $d800
(byte[$3e8]) MAPDATA
(const byte[$3e8]) MAPDATA#0 MAPDATA = { fill( $3e8, 0) }
(byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = ((byte*))(word/signed word/dword/signed dword) $400
(void()) main()
(label) main::@1
(label) main::@return
(byte) main::x
(byte) main::x#1 reg byte x 16.5
(byte) main::x#2 reg byte x 22.0
reg byte x [ main::x#2 main::x#1 ]

View File

@ -4215,36 +4215,36 @@ Constant (const byte*) print_str_at::at#2 = debug_print_init::$6+$22
Constant (const byte*) print_str_at::at#3 = debug_print_init::$10+$22
Constant (const byte) sprites_init::$2 = ((byte))sprites_init::$1
Successful SSA optimization Pass2ConstantIdentification
Consolidated array index constant in *(rotation_matrix#0+0)
Consolidated array index constant in *(rotation_matrix#0+1)
Consolidated array index constant in *(rotation_matrix#0+2)
Consolidated array index constant in *(rotation_matrix#0+3)
Consolidated array index constant in *(rotation_matrix#0+4)
Consolidated array index constant in *(rotation_matrix#0+5)
Consolidated array index constant in *(rotation_matrix#0+6)
Consolidated array index constant in *(rotation_matrix#0+7)
Consolidated array index constant in *(rotation_matrix#0+8)
Consolidated array index constant in *(rotation_matrix#0+0)
Consolidated array index constant in *(rotation_matrix#0+1)
Consolidated array index constant in *(rotation_matrix#0+2)
Consolidated array index constant in *(rotation_matrix#0+3)
Consolidated array index constant in *(rotation_matrix#0+4)
Consolidated array index constant in *(rotation_matrix#0+5)
Consolidated array index constant in *(rotation_matrix#0+6)
Consolidated array index constant in *(rotation_matrix#0+7)
Consolidated array index constant in *(rotation_matrix#0+8)
Consolidated constant in assignment print_sbyte_at::at#3
Consolidated constant in assignment print_sbyte_at::at#4
Consolidated constant in assignment print_sbyte_at::at#5
Consolidated array index constant in *(rotation_matrix#0+0)
Consolidated constant in assignment print_sbyte_at::at#6
Consolidated array index constant in *(rotation_matrix#0+1)
Consolidated constant in assignment print_sbyte_at::at#7
Consolidated array index constant in *(rotation_matrix#0+2)
Consolidated constant in assignment print_sbyte_at::at#8
Consolidated array index constant in *(rotation_matrix#0+3)
Consolidated constant in assignment print_sbyte_at::at#9
Consolidated array index constant in *(rotation_matrix#0+4)
Consolidated constant in assignment print_sbyte_at::at#10
Consolidated array index constant in *(rotation_matrix#0+5)
Consolidated constant in assignment print_sbyte_at::at#11
Consolidated array index constant in *(rotation_matrix#0+6)
Consolidated constant in assignment print_sbyte_at::at#12
Consolidated array index constant in *(rotation_matrix#0+7)
Consolidated constant in assignment print_sbyte_at::at#13
Consolidated array index constant in *(rotation_matrix#0+8)
Consolidated constant in assignment print_sbyte_at::at#14
Consolidated array index constant in *(rotation_matrix#0+0)
Consolidated array index constant in *(rotation_matrix#0+1)
Consolidated array index constant in *(rotation_matrix#0+2)
Consolidated array index constant in *(rotation_matrix#0+3)
Consolidated array index constant in *(rotation_matrix#0+4)
Consolidated array index constant in *(rotation_matrix#0+5)
Consolidated array index constant in *(rotation_matrix#0+6)
Consolidated array index constant in *(rotation_matrix#0+7)
Consolidated array index constant in *(rotation_matrix#0+8)
Successful SSA optimization Pass2ConstantAdditionElimination
if() condition always true - replacing block destination [44] if(true) goto anim::@2
Successful SSA optimization Pass2ConstantIfs

View File

@ -1734,12 +1734,14 @@ Constant (const word/dword) main::$9 = main::$5|main::$8
Successful SSA optimization Pass2ConstantIdentification
Constant (const byte) main::$10 = ((byte))main::$9
Successful SSA optimization Pass2ConstantIdentification
Consolidated array index constant in *(bitmap_plot_xhi#0+0)
Consolidated array index constant in *(bitmap_plot_xlo#0+0)
Consolidated array index constant in assignment *(lines_x#0+1 + lines::$0)
Consolidated array index constant in assignment *(lines_y#0+1 + lines::$1)
Successful SSA optimization Pass2ConstantAdditionElimination
if() condition always true - replacing block destination [172] if(true) goto main::@1
Successful SSA optimization Pass2ConstantIfs
Fixing inline constructor with bitmap_clear::$3 ← *(bitmap_plot_xhi#0 + 0) w= *(bitmap_plot_xlo#0 + 0)
Fixing inline constructor with bitmap_clear::$3 ← *(bitmap_plot_xhi#0+0) w= *(bitmap_plot_xlo#0+0)
Fixing inline constructor with bitmap_plot::$2 ← *(bitmap_plot_xhi#0 + bitmap_plot::x#4) w= *(bitmap_plot_xlo#0 + bitmap_plot::x#4)
Fixing inline constructor with bitmap_plot::$3 ← *(bitmap_plot_yhi#0 + bitmap_plot::y#4) w= *(bitmap_plot_ylo#0 + bitmap_plot::y#4)
Successful SSA optimization Pass2FixInlineConstructors
@ -1769,9 +1771,6 @@ Alias (word) bitmap_plot::plotter_x#0 = (word~) bitmap_plot::$2
Alias (word) bitmap_plot::plotter_y#0 = (word~) bitmap_plot::$3
Alias (byte) lines::l#2 = (byte~) lines::$0 (byte~) lines::$1
Successful SSA optimization Pass2AliasElimination
Consolidated array index constant in *(bitmap_plot_xhi#0+0)
Consolidated array index constant in *(bitmap_plot_xlo#0+0)
Successful SSA optimization Pass2ConstantAdditionElimination
Inlining constant with var siblings (const byte) bitmap_init::bits#0
Inlining constant with var siblings (const byte) bitmap_init::x#0
Inlining constant with var siblings (const byte) bitmap_init::bits#2

View File

@ -2335,10 +2335,13 @@ Constant (const byte) main::toD0181_$7#0 = main::toD0181_$6#0&$f
Successful SSA optimization Pass2ConstantIdentification
Constant (const byte) main::toD0181_return#0 = main::toD0181_$3#0|main::toD0181_$7#0
Successful SSA optimization Pass2ConstantIdentification
Consolidated array index constant in *(bitmap_plot_yhi#0+0)
Consolidated array index constant in *(bitmap_plot_ylo#0+0)
Successful SSA optimization Pass2ConstantAdditionElimination
if() condition always true - replacing block destination [44] if((const signed word) mul16s::b#0>=(byte/signed byte/word/signed word/dword/signed dword) 0) goto mul16s::@2
if() condition always true - replacing block destination [182] if(true) goto main::@2
Successful SSA optimization Pass2ConstantIfs
Fixing inline constructor with bitmap_clear::$3 ← *(bitmap_plot_yhi#0 + 0) w= *(bitmap_plot_ylo#0 + 0)
Fixing inline constructor with bitmap_clear::$3 ← *(bitmap_plot_yhi#0+0) w= *(bitmap_plot_ylo#0+0)
Fixing inline constructor with bitmap_plot::$3 ← *(bitmap_plot_yhi#0 + bitmap_plot::y#2) w= *(bitmap_plot_ylo#0 + bitmap_plot::y#2)
Fixing inline constructor with div32u16u::$4 ← div32u16u::quotient_hi#0 dw= div32u16u::quotient_lo#0
Successful SSA optimization Pass2FixInlineConstructors
@ -2385,9 +2388,6 @@ Successful SSA optimization Pass2CullEmptyBlocks
Alias (dword) div32u16u::return#0 = (dword~) div32u16u::$4
Alias (dword) mul16s::m#4 = (dword) mul16s::m#5
Successful SSA optimization Pass2AliasElimination
Consolidated array index constant in *(bitmap_plot_yhi#0+0)
Consolidated array index constant in *(bitmap_plot_ylo#0+0)
Successful SSA optimization Pass2ConstantAdditionElimination
Inlining constant with var siblings (const word) divr16u::quotient#0
Inlining constant with var siblings (const byte) divr16u::i#0
Inlining constant with var siblings (const word) divr16u::rem#3

View File

@ -2078,10 +2078,13 @@ Constant (const byte) main::toD0181_$7#0 = main::toD0181_$6#0&$f
Successful SSA optimization Pass2ConstantIdentification
Constant (const byte) main::toD0181_return#0 = main::toD0181_$3#0|main::toD0181_$7#0
Successful SSA optimization Pass2ConstantIdentification
Consolidated array index constant in *(bitmap_plot_yhi#0+0)
Consolidated array index constant in *(bitmap_plot_ylo#0+0)
Successful SSA optimization Pass2ConstantAdditionElimination
if() condition always false - eliminating [18] if((const bool) divr16s::$0) goto divr16s::@1
if() condition always true - replacing block destination [64] if(true) goto main::@3
Successful SSA optimization Pass2ConstantIfs
Fixing inline constructor with bitmap_clear::$3 ← *(bitmap_plot_yhi#0 + 0) w= *(bitmap_plot_ylo#0 + 0)
Fixing inline constructor with bitmap_clear::$3 ← *(bitmap_plot_yhi#0+0) w= *(bitmap_plot_ylo#0+0)
Fixing inline constructor with bitmap_plot::$3 ← *(bitmap_plot_yhi#0 + bitmap_plot::y#0) w= *(bitmap_plot_ylo#0 + bitmap_plot::y#0)
Successful SSA optimization Pass2FixInlineConstructors
Successful SSA optimization PassNEliminateUnusedVars
@ -2146,9 +2149,6 @@ Redundant Phi (byte) screen_fill::ch#2 (const byte) screen_fill::ch#0
Successful SSA optimization Pass2RedundantPhiElimination
Simple Condition (bool~) divr16s::$1 [135] if((signed word) divr16s::rem#0<(byte/signed byte/word/signed word/dword/signed dword) 0) goto divr16s::@1
Successful SSA optimization Pass2ConditionalJumpSimplification
Consolidated array index constant in *(bitmap_plot_yhi#0+0)
Consolidated array index constant in *(bitmap_plot_ylo#0+0)
Successful SSA optimization Pass2ConstantAdditionElimination
Culled Empty Block (label) main::@2
Successful SSA optimization Pass2CullEmptyBlocks
Inlining constant with var siblings (const word) divr16u::quotient#0