diff --git a/src/main/fragment/cache/fragment-cache-mos6502.asm b/src/main/fragment/cache/fragment-cache-mos6502.asm index 06affc4ac..c8f402d23 100644 --- a/src/main/fragment/cache/fragment-cache-mos6502.asm +++ b/src/main/fragment/cache/fragment-cache-mos6502.asm @@ -1,4 +1,4 @@ -//KICKC FRAGMENT CACHE 160b015f22 +//KICKC FRAGMENT CACHE 160b017651 //FRAGMENT vbuz1=vbuc1 lda #{c1} sta {z1} diff --git a/src/main/fragment/cache/fragment-cache-mos6502x.asm b/src/main/fragment/cache/fragment-cache-mos6502x.asm index 934470f36..8e2321752 100644 --- a/src/main/fragment/cache/fragment-cache-mos6502x.asm +++ b/src/main/fragment/cache/fragment-cache-mos6502x.asm @@ -1,4 +1,4 @@ -//KICKC FRAGMENT CACHE 160b015f22 +//KICKC FRAGMENT CACHE 160b017651 //FRAGMENT vbuz1=vbuc1 lda #{c1} sta {z1} @@ -6344,13 +6344,34 @@ tsx txa axs #-4 txs +//FRAGMENT pbuz1=_stackidxptr_vbuc1 +tsx +lda STACK_BASE+{c1},x +sta {z1} +lda STACK_BASE+{c1}+1,x +sta {z1}+1 +//FRAGMENT pbuc1_derefidx_vbuz1=_deref_pbuz2 +ldy #0 +lda ({z2}),y +ldy {z1} +sta {c1},y +//FRAGMENT _stackpushptr_=pbuc1 +lda #>{c1} +pha +lda #<{c1} +pha +//FRAGMENT _stackpushbyte_=vbuc1 +lda #{c1} +pha +//FRAGMENT _stackpullbyte_3 +tsx +txa +axs #-3 +txs //FRAGMENT vbuz1=vbuz2_minus_1 ldx {z2} dex stx {z1} -//FRAGMENT _stackpushbyte_=vbuc1 -lda #{c1} -pha //FRAGMENT vbuaa=vbuz1_minus_1 lda {z1} sec @@ -9046,6 +9067,21 @@ sta {z1} lda #>{c1} sbc {z1}+1 sta {z1}+1 +//FRAGMENT pbuc1_derefidx_vbuaa=_deref_pbuz1 +tax +ldy #0 +lda ({z1}),y +sta {c1},x +//FRAGMENT pbuc1_derefidx_vbuxx=_deref_pbuz1 +ldy #0 +lda ({z1}),y +sta {c1},x +//FRAGMENT pbuc1_derefidx_vbuyy=_deref_pbuz1 +tya +tax +ldy #0 +lda ({z1}),y +sta {c1},x //FRAGMENT pbsc1_derefidx_vbuz1=_deref_pbsc2 lda {c2} ldy {z1} @@ -11465,6 +11501,180 @@ sta {z1}+1 asl $ff rol {z1} rol {z1}+1 +//FRAGMENT vwuz1=pbuz2_bxor_vwuc1 +lda #<{c1} +eor {z2} +sta {z1} +lda #>{c1} +eor {z2}+1 +sta {z1}+1 +//FRAGMENT pbuz1_derefidx_vbuz2=pbuz1_derefidx_vbuz2_bor_pbuc1_derefidx_vbuz3 +ldy {z2} +lda ({z1}),y +ldy {z3} +ora {c1},y +ldy {z2} +sta ({z1}),y +//FRAGMENT vbuz1=vbuz1_bxor_pbuz2_derefidx_vbuz3 +lda {z1} +ldy {z3} +eor ({z2}),y +sta {z1} +//FRAGMENT vbuz1=_neg_vbuz1 +lda {z1} +eor #$ff +clc +adc #$01 +sta {z1} +//FRAGMENT pbuz1_derefidx_vbuz2=pbuz1_derefidx_vbuz2_bor_pbuc1_derefidx_vbuaa +ldy {z2} +tax +lda ({z1}),y +ora {c1},x +ldy {z2} +sta ({z1}),y +//FRAGMENT pbuz1_derefidx_vbuz2=pbuz1_derefidx_vbuz2_bor_pbuc1_derefidx_vbuxx +ldy {z2} +lda ({z1}),y +ora {c1},x +ldy {z2} +sta ({z1}),y +//FRAGMENT pbuz1_derefidx_vbuz2=pbuz1_derefidx_vbuz2_bor_pbuc1_derefidx_vbuyy +tya +ldy {z2} +tax +lda ({z1}),y +ora {c1},x +ldy {z2} +sta ({z1}),y +//FRAGMENT pbuz1_derefidx_vbuxx=pbuz1_derefidx_vbuxx_bor_pbuc1_derefidx_vbuz2 +txa +tay +lda ({z1}),y +ldy {z2} +stx $ff +ora {c1},y +ldy $ff +sta ({z1}),y +//FRAGMENT pbuz1_derefidx_vbuxx=pbuz1_derefidx_vbuxx_bor_pbuc1_derefidx_vbuaa +tay +txa +ldx {c1},y +tay +lda ({z1}),y +sty $ff + +stx $ff +ora $ff +ldy $ff +sta ({z1}),y +//FRAGMENT pbuz1_derefidx_vbuxx=pbuz1_derefidx_vbuxx_bor_pbuc1_derefidx_vbuxx +txa +tay +lda ({z1}),y +stx $ff +ora {c1},x +ldy $ff +sta ({z1}),y +//FRAGMENT pbuz1_derefidx_vbuxx=pbuz1_derefidx_vbuxx_bor_pbuc1_derefidx_vbuyy +txa +ldx {c1},y +tay +lda ({z1}),y +sty $ff + +stx $ff +ora $ff +ldy $ff +sta ({z1}),y +//FRAGMENT pbuz1_derefidx_vbuyy=pbuz1_derefidx_vbuyy_bor_pbuc1_derefidx_vbuz2 +lda ({z1}),y +sty $ff + +ldy {z2} +ora {c1},y +ldy $ff +sta ({z1}),y +//FRAGMENT pbuz1_derefidx_vbuyy=pbuz1_derefidx_vbuyy_bor_pbuc1_derefidx_vbuaa +tax +lda ({z1}),y +sty $ff + +ora {c1},x +ldy $ff +sta ({z1}),y +//FRAGMENT pbuz1_derefidx_vbuyy=pbuz1_derefidx_vbuyy_bor_pbuc1_derefidx_vbuxx +lda ({z1}),y +sty $ff + +ora {c1},x +ldy $ff +sta ({z1}),y +//FRAGMENT pbuz1_derefidx_vbuyy=pbuz1_derefidx_vbuyy_bor_pbuc1_derefidx_vbuyy +lda ({z1}),y +sty $ff + +ora {c1},y +ldy $ff +sta ({z1}),y +//FRAGMENT vbuz1=vbuz1_bxor_pbuz2_derefidx_vbuaa +tay +lda {z1} +eor ({z2}),y +sta {z1} +//FRAGMENT vbuz1=vbuz1_bxor_pbuz2_derefidx_vbuxx +txa +tay +lda {z1} +eor ({z2}),y +sta {z1} +//FRAGMENT vbuz1=vbuz1_bxor_pbuz2_derefidx_vbuyy +lda {z1} +eor ({z2}),y +sta {z1} +//FRAGMENT vbuaa=vbuaa_bxor_pbuz1_derefidx_vbuz2 +ldy {z2} +eor ({z1}),y +//FRAGMENT vbuaa=vbuaa_bxor_pbuz1_derefidx_vbuaa +tay +eor ({z1}),y +//FRAGMENT vbuaa=vbuaa_bxor_pbuz1_derefidx_vbuxx +stx $ff +ldy $ff +eor ({z1}),y +//FRAGMENT vbuaa=vbuaa_bxor_pbuz1_derefidx_vbuyy +eor ({z1}),y +//FRAGMENT vbuxx=vbuxx_bxor_pbuz1_derefidx_vbuz2 +ldy {z2} +txa +eor ({z1}),y +tax +//FRAGMENT vbuxx=vbuxx_bxor_pbuz1_derefidx_vbuaa +tay +txa +eor ({z1}),y +tax +//FRAGMENT vbuxx=vbuxx_bxor_pbuz1_derefidx_vbuxx +txa +tay +eor ({z1}),y +tax +//FRAGMENT vbuxx=vbuxx_bxor_pbuz1_derefidx_vbuyy +txa +eor ({z1}),y +tax +//FRAGMENT vbuyy=_neg_vbuyy +dey +tya +eor #$ff +tay +//FRAGMENT vwuz1=pbuz1_bxor_vwuc1 +lda #<{c1} +eor {z1} +sta {z1} +lda #>{c1} +eor {z1}+1 +sta {z1}+1 //FRAGMENT vbsz1=vbsz2_plus_vbsc1 lax {z2} axs #-[{c1}] @@ -12272,16 +12482,29 @@ ldy #{c2} tax lda ({z1}),y sta {c1},x -//FRAGMENT _deref_qssc1=pssc2 -lda #<{c2} -sta {c1} -lda #>{c2} -sta {c1}+1 //FRAGMENT pssz1=pssc1 lda #<{c1} sta {z1} lda #>{c1} sta {z1}+1 +//FRAGMENT pssz1=pssz1_plus_vbuc1 +lda #{c1} +clc +adc {z1} +sta {z1} +bcc !+ +inc {z1}+1 +!: +//FRAGMENT pbuc1_derefidx_vbuaa=pbuz1_derefidx_vbuc2 +ldy #{c2} +tax +lda ({z1}),y +sta {c1},x +//FRAGMENT _deref_qssc1=pssc2 +lda #<{c2} +sta {c1} +lda #>{c2} +sta {c1}+1 //FRAGMENT pssc1_neq_pssz1_then_la1 lda {z1}+1 cmp #>{c1} @@ -12929,12 +13152,6 @@ lda #{c1} sec sbc {z1} sta {z1} -//FRAGMENT vbuz1=_neg_vbuz1 -lda {z1} -eor #$ff -clc -adc #$01 -sta {z1} //FRAGMENT vbsz1=vbsz2_ror_vbuz3 lda {z2} ldy {z3} @@ -12986,11 +13203,6 @@ bne {la1} tya cmp #0 bne {la1} -//FRAGMENT vbuyy=_neg_vbuyy -dey -tya -eor #$ff -tay //FRAGMENT vbsaa=vbsz1_ror_vbuz2 lda {z1} ldy {z2} @@ -14523,14 +14735,6 @@ sta {z1} lda #0 adc {z2}+1 sta {z1}+1 -//FRAGMENT pssz1=pssz1_plus_vbuc1 -lda #{c1} -clc -adc {z1} -sta {z1} -bcc !+ -inc {z1}+1 -!: //FRAGMENT pssz1_lt_pssc1_then_la1 lda {z1}+1 cmp #>{c1} @@ -14602,11 +14806,6 @@ stx $fe ldx {c1}+1 stx $ff sta ($fe),y -//FRAGMENT pbuc1_derefidx_vbuaa=pbuz1_derefidx_vbuc2 -ldy #{c2} -tax -lda ({z1}),y -sta {c1},x //FRAGMENT pssz1_neq_pssc1_then_la1 lda {z1}+1 cmp #>{c1} @@ -14630,6 +14829,34 @@ sta {z1} iny lda ($fe),y sta {z1}+1 +//FRAGMENT pbuc1_derefidx_vbuz1=pbuc2_derefidx_(_deref_pbuz2) +ldy #0 +lda ({z2}),y +tay +lda {c2},y +ldy {z1} +sta {c1},y +//FRAGMENT pbuc1_derefidx_vbuxx=pbuc2_derefidx_(_deref_pbuz1) +ldy #0 +lda ({z1}),y +tay +lda {c2},y +sta {c1},x +//FRAGMENT pbuc1_derefidx_vbuaa=pbuc2_derefidx_(_deref_pbuz1) +tax +ldy #0 +lda ({z1}),y +tay +lda {c2},y +sta {c1},x +//FRAGMENT pbuc1_derefidx_vbuyy=pbuc2_derefidx_(_deref_pbuz1) +tya +tax +ldy #0 +lda ({z1}),y +tay +lda {c2},y +sta {c1},x //FRAGMENT _deref_pwuc1=vbuc2 lda #0 sta {c1}+1 @@ -17510,230 +17737,49 @@ sta {c1},x lda #{c2} ora {c1},y sta {c1},y -//FRAGMENT pbuz1=_stackidxptr_vbuc1 -tsx -lda STACK_BASE+{c1},x +//FRAGMENT vbuz1=_dec_vbuz2 +ldy {z2} +dey +sty {z1} +//FRAGMENT vbuz1=_dec_vbuaa +sec +sbc #1 sta {z1} -lda STACK_BASE+{c1}+1,x -sta {z1}+1 -//FRAGMENT pbuc1_derefidx_vbuz1=_deref_pbuz2 -ldy #0 -lda ({z2}),y +//FRAGMENT vbuz1=_dec_vbuxx +dex +stx {z1} +//FRAGMENT vbuz1=_dec_vbuyy +dey +sty {z1} +//FRAGMENT vbuaa=_dec_vbuz1 +lda {z1} +sec +sbc #1 +//FRAGMENT vbuaa=_dec_vbuxx +txa +sec +sbc #1 +//FRAGMENT vbuaa=_dec_vbuyy +tya +sec +sbc #1 +//FRAGMENT vbuxx=_dec_vbuz1 +ldx {z1} +dex +//FRAGMENT vbuxx=_dec_vbuaa +tax +dex +//FRAGMENT vbuxx=_dec_vbuyy +tya +tax +dex +//FRAGMENT vbuyy=_dec_vbuz1 ldy {z1} -sta {c1},y -//FRAGMENT _stackpushptr_=pbuc1 -lda #>{c1} -pha -lda #<{c1} -pha -//FRAGMENT _stackpullbyte_3 -tsx -txa -axs #-3 -txs -//FRAGMENT pbuc1_derefidx_vbuaa=_deref_pbuz1 -tax -ldy #0 -lda ({z1}),y -sta {c1},x -//FRAGMENT pbuc1_derefidx_vbuxx=_deref_pbuz1 -ldy #0 -lda ({z1}),y -sta {c1},x -//FRAGMENT pbuc1_derefidx_vbuyy=_deref_pbuz1 -tya -tax -ldy #0 -lda ({z1}),y -sta {c1},x -//FRAGMENT vwuz1=pbuz2_bxor_vwuc1 -lda #<{c1} -eor {z2} -sta {z1} -lda #>{c1} -eor {z2}+1 -sta {z1}+1 -//FRAGMENT pbuz1_derefidx_vbuz2=pbuz1_derefidx_vbuz2_bor_pbuc1_derefidx_vbuz3 -ldy {z2} -lda ({z1}),y -ldy {z3} -ora {c1},y -ldy {z2} -sta ({z1}),y -//FRAGMENT vbuz1=vbuz1_bxor_pbuz2_derefidx_vbuz3 -lda {z1} -ldy {z3} -eor ({z2}),y -sta {z1} -//FRAGMENT pbuz1_derefidx_vbuz2=pbuz1_derefidx_vbuz2_bor_pbuc1_derefidx_vbuaa -ldy {z2} -tax -lda ({z1}),y -ora {c1},x -ldy {z2} -sta ({z1}),y -//FRAGMENT pbuz1_derefidx_vbuz2=pbuz1_derefidx_vbuz2_bor_pbuc1_derefidx_vbuxx -ldy {z2} -lda ({z1}),y -ora {c1},x -ldy {z2} -sta ({z1}),y -//FRAGMENT pbuz1_derefidx_vbuz2=pbuz1_derefidx_vbuz2_bor_pbuc1_derefidx_vbuyy -tya -ldy {z2} -tax -lda ({z1}),y -ora {c1},x -ldy {z2} -sta ({z1}),y -//FRAGMENT pbuz1_derefidx_vbuxx=pbuz1_derefidx_vbuxx_bor_pbuc1_derefidx_vbuz2 +dey +//FRAGMENT vbuyy=_dec_vbuaa +tay +dey +//FRAGMENT vbuyy=_dec_vbuxx txa tay -lda ({z1}),y -ldy {z2} -stx $ff -ora {c1},y -ldy $ff -sta ({z1}),y -//FRAGMENT pbuz1_derefidx_vbuxx=pbuz1_derefidx_vbuxx_bor_pbuc1_derefidx_vbuaa -tay -txa -ldx {c1},y -tay -lda ({z1}),y -sty $ff - -stx $ff -ora $ff -ldy $ff -sta ({z1}),y -//FRAGMENT pbuz1_derefidx_vbuxx=pbuz1_derefidx_vbuxx_bor_pbuc1_derefidx_vbuxx -txa -tay -lda ({z1}),y -stx $ff -ora {c1},x -ldy $ff -sta ({z1}),y -//FRAGMENT pbuz1_derefidx_vbuxx=pbuz1_derefidx_vbuxx_bor_pbuc1_derefidx_vbuyy -txa -ldx {c1},y -tay -lda ({z1}),y -sty $ff - -stx $ff -ora $ff -ldy $ff -sta ({z1}),y -//FRAGMENT pbuz1_derefidx_vbuyy=pbuz1_derefidx_vbuyy_bor_pbuc1_derefidx_vbuz2 -lda ({z1}),y -sty $ff - -ldy {z2} -ora {c1},y -ldy $ff -sta ({z1}),y -//FRAGMENT pbuz1_derefidx_vbuyy=pbuz1_derefidx_vbuyy_bor_pbuc1_derefidx_vbuaa -tax -lda ({z1}),y -sty $ff - -ora {c1},x -ldy $ff -sta ({z1}),y -//FRAGMENT pbuz1_derefidx_vbuyy=pbuz1_derefidx_vbuyy_bor_pbuc1_derefidx_vbuxx -lda ({z1}),y -sty $ff - -ora {c1},x -ldy $ff -sta ({z1}),y -//FRAGMENT pbuz1_derefidx_vbuyy=pbuz1_derefidx_vbuyy_bor_pbuc1_derefidx_vbuyy -lda ({z1}),y -sty $ff - -ora {c1},y -ldy $ff -sta ({z1}),y -//FRAGMENT vbuz1=vbuz1_bxor_pbuz2_derefidx_vbuaa -tay -lda {z1} -eor ({z2}),y -sta {z1} -//FRAGMENT vbuz1=vbuz1_bxor_pbuz2_derefidx_vbuxx -txa -tay -lda {z1} -eor ({z2}),y -sta {z1} -//FRAGMENT vbuz1=vbuz1_bxor_pbuz2_derefidx_vbuyy -lda {z1} -eor ({z2}),y -sta {z1} -//FRAGMENT vbuaa=vbuaa_bxor_pbuz1_derefidx_vbuz2 -ldy {z2} -eor ({z1}),y -//FRAGMENT vbuaa=vbuaa_bxor_pbuz1_derefidx_vbuaa -tay -eor ({z1}),y -//FRAGMENT vbuaa=vbuaa_bxor_pbuz1_derefidx_vbuxx -stx $ff -ldy $ff -eor ({z1}),y -//FRAGMENT vbuaa=vbuaa_bxor_pbuz1_derefidx_vbuyy -eor ({z1}),y -//FRAGMENT vbuxx=vbuxx_bxor_pbuz1_derefidx_vbuz2 -ldy {z2} -txa -eor ({z1}),y -tax -//FRAGMENT vbuxx=vbuxx_bxor_pbuz1_derefidx_vbuaa -tay -txa -eor ({z1}),y -tax -//FRAGMENT vbuxx=vbuxx_bxor_pbuz1_derefidx_vbuxx -txa -tay -eor ({z1}),y -tax -//FRAGMENT vbuxx=vbuxx_bxor_pbuz1_derefidx_vbuyy -txa -eor ({z1}),y -tax -//FRAGMENT vwuz1=pbuz1_bxor_vwuc1 -lda #<{c1} -eor {z1} -sta {z1} -lda #>{c1} -eor {z1}+1 -sta {z1}+1 -//FRAGMENT pbuc1_derefidx_vbuz1=pbuc2_derefidx_(_deref_pbuz2) -ldy #0 -lda ({z2}),y -tay -lda {c2},y -ldy {z1} -sta {c1},y -//FRAGMENT pbuc1_derefidx_vbuxx=pbuc2_derefidx_(_deref_pbuz1) -ldy #0 -lda ({z1}),y -tay -lda {c2},y -sta {c1},x -//FRAGMENT pbuc1_derefidx_vbuaa=pbuc2_derefidx_(_deref_pbuz1) -tax -ldy #0 -lda ({z1}),y -tay -lda {c2},y -sta {c1},x -//FRAGMENT pbuc1_derefidx_vbuyy=pbuc2_derefidx_(_deref_pbuz1) -tya -tax -ldy #0 -lda ({z1}),y -tay -lda {c2},y -sta {c1},x +dey diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java index c7e2e3a19..9d7c7f6cf 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java @@ -460,6 +460,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor(); @@ -990,7 +991,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor 0 || (modifierHandler.getPostMods().size() > 0); + return (modifierHandler.getPreMods().size() > 0) || (modifierHandler.getPostMods().size() > 0); + } + + static boolean hasPostModifiers(Pass0GenerateStatementSequence parser, ParserRuleContext ctx, StatementSource statementSource) { + PrePostModifierHandler modifierHandler = new PrePostModifierHandler(parser); + modifierHandler.visit(ctx); + return modifierHandler.getPostMods().size() > 0; } diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index b66eca0f1..31d0b30fd 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -389,6 +389,16 @@ public class TestPrograms { compileAndCompare("examples/conio/nacht-screen.c"); } + @Test + public void testPostIncrementProblem4() throws IOException, URISyntaxException { + compileAndCompare("post-increment-problem-4.c"); + } + + @Test + public void testPostIncrementProblem3() throws IOException, URISyntaxException { + compileAndCompare("post-increment-problem-3.c"); + } + @Test public void testPostIncrementProblem2() throws IOException, URISyntaxException { compileAndCompare("post-increment-problem-2.c"); diff --git a/src/test/kc/post-increment-problem-3.c b/src/test/kc/post-increment-problem-3.c new file mode 100644 index 000000000..9e85e926f --- /dev/null +++ b/src/test/kc/post-increment-problem-3.c @@ -0,0 +1,14 @@ +// Illustrates a problem with post-incrementing inside the while loop condition +// https://gitlab.com/camelot/kickc/-/issues/486 + +const unsigned char mmap[] = { + 0x02, 0x5c, 0x1a, 0x03, 0x60, 0x1a, 0x07 +}; + +void main(void) +{ + unsigned char *ptr = mmap; + unsigned char n = *(ptr++); + while (n--) + *((unsigned char *)0x400) = n; +} diff --git a/src/test/kc/post-increment-problem-4.c b/src/test/kc/post-increment-problem-4.c new file mode 100644 index 000000000..a7a07376b --- /dev/null +++ b/src/test/kc/post-increment-problem-4.c @@ -0,0 +1,12 @@ +// Illustrates a problem with post-incrementing inside the while loop condition +// https://gitlab.com/camelot/kickc/-/issues/486 + +char MESSAGE[] = "hello world!"; +char * const SCREEN = 0x0400; + +void main(void) { + char * s = MESSAGE; + char c, i=0; + while(c=*s++) + SCREEN[i++] = c; +} diff --git a/src/test/ref/atoi-1.asm b/src/test/ref/atoi-1.asm index cdff96e79..3e80e8e38 100644 --- a/src/test/ref/atoi-1.asm +++ b/src/test/ref/atoi-1.asm @@ -276,10 +276,9 @@ printf_sint: { cputs: { .label s = 5 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/atoi-1.log b/src/test/ref/atoi-1.log index 2b2f786c2..bbe3fafe9 100644 --- a/src/test/ref/atoi-1.log +++ b/src/test/ref/atoi-1.log @@ -615,9 +615,10 @@ cputs: scope:[cputs] from main::@3 main::@6 printf_number_buffer::@5 cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#4 ← phi( cputs/(to_nomodify byte*) cputs::s#5 cputs::@3/(to_nomodify byte*) cputs::s#6 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#4) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#4 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#7 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -1266,7 +1267,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -2007,7 +2009,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 0 in *((byte*)&(struct printf_buffer_number) printf_buffer+(const byte) OFFSET_STRUCT_PRINTF_BUFFER_NUMBER_SIGN) ← (number) 0 Adding number conversion cast (snumber) 0 in (bool~) printf_sint::$0 ← (signed word) printf_sint::value#3 < (number) 0 Adding number conversion cast (unumber) 0 in (bool~) printf_sint::$5 ← (number) 0 != (byte) printf_sint::format_sign_always#2 @@ -2171,15 +2173,15 @@ Inversing boolean not [219] (bool~) gotoxy::$1 ← (byte) gotoxy::y#2 <= (byte) Inversing boolean not [223] (bool~) gotoxy::$3 ← (byte) gotoxy::x#2 < (byte) $28 from [222] (bool~) gotoxy::$2 ← (byte) gotoxy::x#2 >= (byte) $28 Inversing boolean not [249] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [248] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [260] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [259] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [324] (bool~) printf_sint::$3 ← (byte) 0 == (byte) printf_sint::format_sign_always#2 from [323] (bool~) printf_sint::$5 ← (byte) 0 != (byte) printf_sint::format_sign_always#2 -Inversing boolean not [348] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#1 from [347] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#1 -Inversing boolean not [352] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#1 from [351] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#1 -Inversing boolean not [354] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#1 from [353] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#1 -Inversing boolean not [367] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#1 from [366] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#1 -Inversing boolean not [374] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [373] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 -Inversing boolean not [382] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [381] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 -Inversing boolean not [399] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#1 from [398] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#1 -Inversing boolean not [411] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [410] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 +Inversing boolean not [325] (bool~) printf_sint::$3 ← (byte) 0 == (byte) printf_sint::format_sign_always#2 from [324] (bool~) printf_sint::$5 ← (byte) 0 != (byte) printf_sint::format_sign_always#2 +Inversing boolean not [349] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#1 from [348] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#1 +Inversing boolean not [353] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#1 from [352] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#1 +Inversing boolean not [355] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#1 from [354] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#1 +Inversing boolean not [368] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#1 from [367] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#1 +Inversing boolean not [375] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [374] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 +Inversing boolean not [383] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [382] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 +Inversing boolean not [400] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#1 from [399] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#1 +Inversing boolean not [412] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [411] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -2243,7 +2245,7 @@ Alias gotoxy::x#4 = gotoxy::x#5 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#4 = gotoxy::y#5 Alias cputc::c#3 = cputc::c#4 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#7 cputs::s#6 Alias printf_padding::pad#3 = printf_padding::pad#4 printf_padding::pad#6 Alias printf_padding::i#2 = printf_padding::i#4 printf_padding::i#3 @@ -2402,7 +2404,7 @@ Simple Condition (bool~) cputc::$0 [176] if((byte) cputc::c#3==(byte) ' Simple Condition (bool~) cputc::$2 [182] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [192] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [194] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [228] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [228] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) printf_padding::$0 [236] if((byte) printf_padding::i#2<(byte) printf_padding::length#4) goto printf_padding::@2 Simple Condition (bool~) printf_sint::$0 [244] if((signed word) printf_sint::value#3<(signed byte) 0) goto printf_sint::@1 Simple Condition (bool~) printf_sint::$3 [248] if((byte) 0==(byte) printf_sint::format_sign_always#2) goto printf_sint::@2 @@ -7163,11 +7165,10 @@ cputs: { // [68] phi (to_nomodify byte*) cputs::s#4 = (to_nomodify byte*) cputs::s#5 [phi:cputs/cputs::@2->cputs::@1#0] -- register_copy // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [69] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#4) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [70] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#4 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/circlechars.asm b/src/test/ref/circlechars.asm index dfdbcfdec..3cf343765 100644 --- a/src/test/ref/circlechars.asm +++ b/src/test/ref/circlechars.asm @@ -262,10 +262,9 @@ printf_uint: { cputs: { .label s = 7 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/circlechars.log b/src/test/ref/circlechars.log index d7ebe9754..a27a3bffb 100644 --- a/src/test/ref/circlechars.log +++ b/src/test/ref/circlechars.log @@ -428,9 +428,10 @@ cputs: scope:[cputs] from main::@11 printf_number_buffer::@5 cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#3 ← phi( cputs/(to_nomodify byte*) cputs::s#4 cputs::@3/(to_nomodify byte*) cputs::s#5 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#3) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#3 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#6 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -1225,7 +1226,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -2101,7 +2103,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 5 in (byte) utoa::max_digits#1 ← (number) 5 Adding number conversion cast (unumber) 4 in (byte) utoa::max_digits#2 ← (number) 4 Adding number conversion cast (unumber) 6 in (byte) utoa::max_digits#3 ← (number) 6 @@ -2321,15 +2323,15 @@ Inversing boolean not [140] (bool~) gotoxy::$1 ← (byte) gotoxy::y#3 <= (byte) Inversing boolean not [144] (bool~) gotoxy::$3 ← (byte) gotoxy::x#3 < (byte) $28 from [143] (bool~) gotoxy::$2 ← (byte) gotoxy::x#3 >= (byte) $28 Inversing boolean not [170] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [169] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [181] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [180] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [343] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#1 from [342] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#1 -Inversing boolean not [347] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#1 from [346] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#1 -Inversing boolean not [349] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#1 from [348] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#1 -Inversing boolean not [362] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#1 from [361] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#1 -Inversing boolean not [369] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [368] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 -Inversing boolean not [377] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [376] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 -Inversing boolean not [394] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#1 from [393] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#1 -Inversing boolean not [406] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [405] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 -Inversing boolean not [474] (bool~) main::$13 ← (signed word) main::dist_sq#0 >= (signed word)(number) 2*(number) 9*(number) 2*(number) 9 from [473] (bool~) main::$12 ← (signed word) main::dist_sq#0 < (signed word)(number) 2*(number) 9*(number) 2*(number) 9 +Inversing boolean not [344] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#1 from [343] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#1 +Inversing boolean not [348] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#1 from [347] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#1 +Inversing boolean not [350] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#1 from [349] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#1 +Inversing boolean not [363] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#1 from [362] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#1 +Inversing boolean not [370] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [369] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 +Inversing boolean not [378] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [377] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 +Inversing boolean not [395] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#1 from [394] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#1 +Inversing boolean not [407] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [406] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 +Inversing boolean not [475] (bool~) main::$13 ← (signed word) main::dist_sq#0 >= (signed word)(number) 2*(number) 9*(number) 2*(number) 9 from [474] (bool~) main::$12 ← (signed word) main::dist_sq#0 < (signed word)(number) 2*(number) 9*(number) 2*(number) 9 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -2375,7 +2377,7 @@ Alias gotoxy::x#5 = gotoxy::x#6 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#5 = gotoxy::y#6 Alias cputc::c#3 = cputc::c#4 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#6 cputs::s#5 Alias utoa::value#10 = utoa::value#8 utoa::value#12 utoa::value#13 utoa::value#9 utoa::value#14 utoa::value#15 utoa::value#11 Alias utoa::buffer#10 = utoa::buffer#17 utoa::buffer#21 utoa::buffer#16 utoa::buffer#18 utoa::buffer#13 utoa::buffer#19 utoa::buffer#20 utoa::buffer#6 @@ -2562,7 +2564,7 @@ Simple Condition (bool~) cputc::$0 [108] if((byte) cputc::c#3==(byte) ' Simple Condition (bool~) cputc::$2 [114] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [124] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [126] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [160] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [160] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) utoa::$0 [168] if((byte) utoa::radix#0==(const byte) DECIMAL) goto utoa::@1 Simple Condition (bool~) utoa::$1 [172] if((byte) utoa::radix#0==(const byte) HEXADECIMAL) goto utoa::@2 Simple Condition (bool~) utoa::$2 [176] if((byte) utoa::radix#0==(const byte) OCTAL) goto utoa::@3 @@ -7586,11 +7588,10 @@ cputs: { // [64] phi (to_nomodify byte*) cputs::s#3 = (to_nomodify byte*) cputs::s#4 [phi:cputs/cputs::@2->cputs::@1#0] -- register_copy // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [65] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#3) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [66] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#3 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/examples/conio/nacht-screen.asm b/src/test/ref/examples/conio/nacht-screen.asm index e349f89d7..c00b50b46 100644 --- a/src/test/ref/examples/conio/nacht-screen.asm +++ b/src/test/ref/examples/conio/nacht-screen.asm @@ -665,10 +665,9 @@ cvline: { cputs: { .label s = 9 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/examples/conio/nacht-screen.log b/src/test/ref/examples/conio/nacht-screen.log index 948ec4590..5d677520d 100644 --- a/src/test/ref/examples/conio/nacht-screen.log +++ b/src/test/ref/examples/conio/nacht-screen.log @@ -328,9 +328,10 @@ cputs: scope:[cputs] from cputsxy::@1 cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#2 ← phi( cputs/(to_nomodify byte*) cputs::s#3 cputs::@3/(to_nomodify byte*) cputs::s#4 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#2) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#2 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#5 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -1076,7 +1077,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -1424,7 +1426,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 0 in *((const nomodify byte*) kbhit::CIA1_PORT_A) ← (number) 0 Adding number conversion cast (unumber) $17 in *((const nomodify byte*) VIC_MEMORY) ← (number) $17 Adding number conversion cast (unumber) 0 in (bool~) main::$5 ← (number) 0 != (byte~) main::$3 @@ -1608,7 +1610,7 @@ Inversing boolean not [77] (bool~) gotoxy::$1 ← (byte) gotoxy::y#6 <= (byte) $ Inversing boolean not [81] (bool~) gotoxy::$3 ← (byte) gotoxy::x#6 < (byte) $28 from [80] (bool~) gotoxy::$2 ← (byte) gotoxy::x#6 >= (byte) $28 Inversing boolean not [111] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [110] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [122] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [121] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [269] (bool~) main::$4 ← (byte) 0 == (byte~) main::$3 from [268] (bool~) main::$5 ← (byte) 0 != (byte~) main::$3 +Inversing boolean not [270] (bool~) main::$4 ← (byte) 0 == (byte~) main::$3 from [269] (bool~) main::$5 ← (byte) 0 != (byte~) main::$3 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -1639,7 +1641,7 @@ Alias gotoxy::x#8 = gotoxy::x#9 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#8 = gotoxy::y#9 Alias cputc::c#8 = cputc::c#9 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#5 cputs::s#4 Alias cputcxy::c#2 = cputcxy::c#3 Alias cputsxy::s#1 = cputsxy::s#2 @@ -1716,7 +1718,7 @@ Simple Condition (bool~) cputc::$0 [78] if((byte) cputc::c#8==(byte) ' Simple Condition (bool~) cputc::$2 [84] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [94] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [96] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [130] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [130] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) chline::$0 [175] if((byte) chline::i#2<(byte) chline::length#4) goto chline::@2 Simple Condition (bool~) cvline::$0 [186] if((byte) cvline::i#2<(byte) cvline::length#0) goto cvline::@2 Simple Condition (bool~) main::$4 [211] if((byte) 0==(byte~) main::$3) goto main::@1 @@ -7986,11 +7988,10 @@ cputs: { // [187] phi (to_nomodify byte*) cputs::s#2 = (to_nomodify byte*) cputs::s#1 [phi:cputs/cputs::@2->cputs::@1#0] -- register_copy // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [188] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#2) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [189] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#2 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/examples/eightqueens/eightqueens-recursive.asm b/src/test/ref/examples/eightqueens/eightqueens-recursive.asm index de11bc9eb..306e8ef35 100644 --- a/src/test/ref/examples/eightqueens/eightqueens-recursive.asm +++ b/src/test/ref/examples/eightqueens/eightqueens-recursive.asm @@ -462,11 +462,10 @@ cputs: { .label c = $d .label s = $b __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y sta.z c - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/examples/eightqueens/eightqueens-recursive.log b/src/test/ref/examples/eightqueens/eightqueens-recursive.log index 36992df47..e4dcd8212 100644 --- a/src/test/ref/examples/eightqueens/eightqueens-recursive.log +++ b/src/test/ref/examples/eightqueens/eightqueens-recursive.log @@ -934,9 +934,10 @@ cputs: scope:[cputs] from main::@1 main::@11 main::@2 main::@7 main::@9 print:: cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#13 ← phi( cputs/(to_nomodify byte*) cputs::s#14 cputs::@3/(to_nomodify byte*) cputs::s#15 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#13) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#13 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#16 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -2161,7 +2162,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -3706,7 +3708,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 0 in (bool~) printf_ulong::$5 ← (number) 0 != (byte) printf_ulong::format_sign_always#2 Adding number conversion cast (unumber) printf_ulong::$2 in (byte) printf_ulong::format_upper_case#3 ← phi( printf_ulong::@1/(byte) printf_ulong::format_upper_case#4 printf_ulong::@2/(byte) printf_ulong::format_upper_case#5 ) (byte) printf_ulong::format_zero_padding#3 ← phi( printf_ulong::@1/(byte) printf_ulong::format_zero_padding#4 printf_ulong::@2/(byte) printf_ulong::format_zero_padding#5 ) @@ -4112,19 +4114,19 @@ Inversing boolean not [350] (bool~) gotoxy::$1 ← (byte) gotoxy::y#3 <= (byte) Inversing boolean not [354] (bool~) gotoxy::$3 ← (byte) gotoxy::x#3 < (byte) $28 from [353] (bool~) gotoxy::$2 ← (byte) gotoxy::x#3 >= (byte) $28 Inversing boolean not [380] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [379] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [391] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [390] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [520] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#3 from [519] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#3 -Inversing boolean not [524] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#3 from [523] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#3 -Inversing boolean not [526] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [525] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 -Inversing boolean not [539] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#3 from [538] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#3 -Inversing boolean not [546] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [545] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 -Inversing boolean not [554] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#4 from [553] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#4 -Inversing boolean not [571] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#3 from [570] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#3 -Inversing boolean not [583] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#5 from [582] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#5 -Inversing boolean not [601] (bool~) printf_string::$0 ← (byte) 0 == (byte) printf_string::format_min_length#1 from [600] (bool~) printf_string::$14 ← (byte) 0 != (byte) printf_string::format_min_length#1 -Inversing boolean not [605] (bool~) printf_string::$1 ← (byte) 0 == (byte) printf_string::format_justify_left#1 from [604] (bool~) printf_string::$15 ← (byte) 0 != (byte) printf_string::format_justify_left#1 -Inversing boolean not [620] (bool~) printf_string::$12 ← (signed byte) printf_string::padding#1 >= (signed byte) 0 from [619] (bool~) printf_string::$11 ← (signed byte) printf_string::padding#1 < (signed byte) 0 -Inversing boolean not [768] (bool~) queen::$2 ← (byte) 0 == (byte~) queen::$1 from [767] (bool~) queen::$7 ← (byte) 0 != (byte~) queen::$1 -Inversing boolean not [808] (bool~) legal::$6 ← (byte~) legal::$3 != (byte~) legal::$4 from [807] (bool~) legal::$5 ← (byte~) legal::$3 == (byte~) legal::$4 +Inversing boolean not [521] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#3 from [520] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#3 +Inversing boolean not [525] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#3 from [524] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#3 +Inversing boolean not [527] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [526] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 +Inversing boolean not [540] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#3 from [539] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#3 +Inversing boolean not [547] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [546] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 +Inversing boolean not [555] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#4 from [554] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#4 +Inversing boolean not [572] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#3 from [571] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#3 +Inversing boolean not [584] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#5 from [583] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#5 +Inversing boolean not [602] (bool~) printf_string::$0 ← (byte) 0 == (byte) printf_string::format_min_length#1 from [601] (bool~) printf_string::$14 ← (byte) 0 != (byte) printf_string::format_min_length#1 +Inversing boolean not [606] (bool~) printf_string::$1 ← (byte) 0 == (byte) printf_string::format_justify_left#1 from [605] (bool~) printf_string::$15 ← (byte) 0 != (byte) printf_string::format_justify_left#1 +Inversing boolean not [621] (bool~) printf_string::$12 ← (signed byte) printf_string::padding#1 >= (signed byte) 0 from [620] (bool~) printf_string::$11 ← (signed byte) printf_string::padding#1 < (signed byte) 0 +Inversing boolean not [769] (bool~) queen::$2 ← (byte) 0 == (byte~) queen::$1 from [768] (bool~) queen::$7 ← (byte) 0 != (byte~) queen::$1 +Inversing boolean not [809] (bool~) legal::$6 ← (byte~) legal::$3 != (byte~) legal::$4 from [808] (bool~) legal::$5 ← (byte~) legal::$3 == (byte~) legal::$4 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -4211,7 +4213,7 @@ Alias gotoxy::x#5 = gotoxy::x#6 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#5 = gotoxy::y#6 Alias cputc::c#3 = cputc::c#4 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#16 cputs::s#15 Alias printf_padding::pad#5 = printf_padding::pad#6 printf_padding::pad#8 Alias printf_padding::i#2 = printf_padding::i#4 printf_padding::i#3 @@ -4507,7 +4509,7 @@ Simple Condition (bool~) cputc::$0 [280] if((byte) cputc::c#3==(byte) ' Simple Condition (bool~) cputc::$2 [286] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [296] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [298] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [332] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [332] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) printf_padding::$0 [340] if((byte) printf_padding::i#2<(byte) printf_padding::length#6) goto printf_padding::@2 Simple Condition (bool~) printf_ulong::$5 [347] if((byte) 0!=(byte) printf_ulong::format_sign_always#2) goto printf_ulong::@1 Simple Condition (bool~) printf_uint::$5 [368] if((byte) 0!=(byte) printf_uint::format_sign_always#0) goto printf_uint::@1 @@ -15483,12 +15485,11 @@ cputs: { // [133] phi (to_nomodify byte*) cputs::s#13 = (to_nomodify byte*) cputs::s#14 [phi:cputs/cputs::@2->cputs::@1#0] -- register_copy // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [134] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#13) -- vbuz1=_deref_pbuz2 ldy #0 lda (s),y sta.z c - // while(c=*s++) // [135] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#13 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/examples/eightqueens/eightqueens.asm b/src/test/ref/examples/eightqueens/eightqueens.asm index 7184a78d2..074c186bf 100644 --- a/src/test/ref/examples/eightqueens/eightqueens.asm +++ b/src/test/ref/examples/eightqueens/eightqueens.asm @@ -160,10 +160,9 @@ clrscr: { cputs: { .label s = $13 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/examples/eightqueens/eightqueens.log b/src/test/ref/examples/eightqueens/eightqueens.log index 67ab41b3b..d914d0158 100644 --- a/src/test/ref/examples/eightqueens/eightqueens.log +++ b/src/test/ref/examples/eightqueens/eightqueens.log @@ -926,9 +926,10 @@ cputs: scope:[cputs] from main::@1 main::@2 main::@5 main::@7 print::@11 print: cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#11 ← phi( cputs/(to_nomodify byte*) cputs::s#12 cputs::@3/(to_nomodify byte*) cputs::s#13 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#11) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#11 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#14 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -2043,7 +2044,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -3461,7 +3463,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 0 in (bool~) printf_ulong::$5 ← (number) 0 != (byte) printf_ulong::format_sign_always#2 Adding number conversion cast (unumber) printf_ulong::$2 in (byte) printf_ulong::format_upper_case#3 ← phi( printf_ulong::@1/(byte) printf_ulong::format_upper_case#4 printf_ulong::@2/(byte) printf_ulong::format_upper_case#5 ) (byte) printf_ulong::format_zero_padding#3 ← phi( printf_ulong::@1/(byte) printf_ulong::format_zero_padding#4 printf_ulong::@2/(byte) printf_ulong::format_zero_padding#5 ) @@ -3779,16 +3781,16 @@ Inversing boolean not [350] (bool~) gotoxy::$1 ← (byte) gotoxy::y#3 <= (byte) Inversing boolean not [354] (bool~) gotoxy::$3 ← (byte) gotoxy::x#3 < (byte) $28 from [353] (bool~) gotoxy::$2 ← (byte) gotoxy::x#3 >= (byte) $28 Inversing boolean not [380] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [379] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [391] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [390] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [520] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#3 from [519] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#3 -Inversing boolean not [524] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#3 from [523] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#3 -Inversing boolean not [526] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [525] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 -Inversing boolean not [539] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#3 from [538] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#3 -Inversing boolean not [546] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [545] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 -Inversing boolean not [554] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#4 from [553] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#4 -Inversing boolean not [571] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#3 from [570] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#3 -Inversing boolean not [583] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#5 from [582] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#5 -Inversing boolean not [658] (bool~) queens::$3 ← (byte) 0 == (byte~) queens::$2 from [657] (bool~) queens::$8 ← (byte) 0 != (byte~) queens::$2 -Inversing boolean not [717] (bool~) legal::$6 ← (byte~) legal::$3 != (byte~) legal::$4 from [716] (bool~) legal::$5 ← (byte~) legal::$3 == (byte~) legal::$4 +Inversing boolean not [521] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#3 from [520] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#3 +Inversing boolean not [525] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#3 from [524] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#3 +Inversing boolean not [527] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [526] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 +Inversing boolean not [540] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#3 from [539] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#3 +Inversing boolean not [547] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [546] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 +Inversing boolean not [555] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#4 from [554] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#4 +Inversing boolean not [572] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#3 from [571] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#3 +Inversing boolean not [584] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#5 from [583] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#5 +Inversing boolean not [659] (bool~) queens::$3 ← (byte) 0 == (byte~) queens::$2 from [658] (bool~) queens::$8 ← (byte) 0 != (byte~) queens::$2 +Inversing boolean not [718] (bool~) legal::$6 ← (byte~) legal::$3 != (byte~) legal::$4 from [717] (bool~) legal::$5 ← (byte~) legal::$3 == (byte~) legal::$4 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -3874,7 +3876,7 @@ Alias gotoxy::x#5 = gotoxy::x#6 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#5 = gotoxy::y#6 Alias cputc::c#3 = cputc::c#4 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#14 cputs::s#13 Alias printf_padding::pad#3 = printf_padding::pad#4 printf_padding::pad#6 Alias printf_padding::i#2 = printf_padding::i#4 printf_padding::i#3 @@ -4153,7 +4155,7 @@ Simple Condition (bool~) cputc::$0 [280] if((byte) cputc::c#3==(byte) ' Simple Condition (bool~) cputc::$2 [286] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [296] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [298] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [332] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [332] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) printf_padding::$0 [340] if((byte) printf_padding::i#2<(byte) printf_padding::length#4) goto printf_padding::@2 Simple Condition (bool~) printf_ulong::$5 [347] if((byte) 0!=(byte) printf_ulong::format_sign_always#2) goto printf_ulong::@1 Simple Condition (bool~) printf_uint::$5 [368] if((byte) 0!=(byte) printf_uint::format_sign_always#0) goto printf_uint::@1 @@ -13320,11 +13322,10 @@ cputs: { // [42] phi (to_nomodify byte*) cputs::s#11 = (to_nomodify byte*) cputs::s#12 [phi:cputs/cputs::@2->cputs::@1#0] -- register_copy // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [43] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#11) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [44] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#11 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/examples/helloworld/helloworld.asm b/src/test/ref/examples/helloworld/helloworld.asm index 7c133e959..73513a526 100644 --- a/src/test/ref/examples/helloworld/helloworld.asm +++ b/src/test/ref/examples/helloworld/helloworld.asm @@ -52,10 +52,9 @@ cputs: { lda #>main.s sta.z s+1 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/examples/helloworld/helloworld.log b/src/test/ref/examples/helloworld/helloworld.log index a70f53629..89b2aefae 100644 --- a/src/test/ref/examples/helloworld/helloworld.log +++ b/src/test/ref/examples/helloworld/helloworld.log @@ -237,9 +237,10 @@ cputs: scope:[cputs] from main cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#2 ← phi( cputs/(to_nomodify byte*) cputs::s#3 cputs::@3/(to_nomodify byte*) cputs::s#4 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#2) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#2 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#5 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -409,7 +410,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -600,7 +602,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Successful SSA optimization PassNAddNumberTypeConversions Inlining cast (byte*) memcpy::src#0 ← (byte*)(void*) memcpy::source#2 Inlining cast (byte*) memcpy::dst#0 ← (byte*)(void*) memcpy::destination#2 @@ -692,7 +694,7 @@ Alias gotoxy::x#4 = gotoxy::x#5 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#4 = gotoxy::y#5 Alias cputc::c#1 = cputc::c#2 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#5 cputs::s#4 Successful SSA optimization Pass2AliasElimination Alias candidate removed (volatile)conio_line_text = gotoxy::$5 @@ -724,7 +726,7 @@ Simple Condition (bool~) cputc::$0 [45] if((byte) cputc::c#0==(byte) ' Simple Condition (bool~) cputc::$2 [51] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [61] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [63] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [97] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [97] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Successful SSA optimization Pass2ConditionalJumpSimplification Constant right-side identified [66] (word) memcpy::num#0 ← (unumber)(number) $19*(number) $28-(number) $28 Constant right-side identified [71] (word) memcpy::num#1 ← (unumber)(number) $19*(number) $28-(number) $28 @@ -2525,11 +2527,10 @@ cputs: { sta.z s+1 // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [13] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#2) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [14] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#2 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/examples/nes-conio/nes-conio.asm b/src/test/ref/examples/nes-conio/nes-conio.asm index 0750de479..f028118c3 100644 --- a/src/test/ref/examples/nes-conio/nes-conio.asm +++ b/src/test/ref/examples/nes-conio/nes-conio.asm @@ -714,10 +714,9 @@ cputs: { lda #>num_buffer sta.z s+1 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/examples/nes-conio/nes-conio.log b/src/test/ref/examples/nes-conio/nes-conio.log index 3d120ad44..a59011f0e 100644 --- a/src/test/ref/examples/nes-conio/nes-conio.log +++ b/src/test/ref/examples/nes-conio/nes-conio.log @@ -466,9 +466,10 @@ cputs: scope:[cputs] from cputsxy::@1 cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#2 ← phi( cputs/(to_nomodify byte*) cputs::s#3 cputs::@3/(to_nomodify byte*) cputs::s#4 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#2) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#2 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#5 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -748,8 +749,9 @@ main::initNES1_@1: scope:[main] from main::initNES1_@1 main::initNES1_@6 *((const nomodify byte*) MEMORY+(number) $600 + (byte) main::initNES1_i#2) ← (number) 0 *((const nomodify byte*) MEMORY+(number) $700 + (byte) main::initNES1_i#2) ← (number) 0 (byte) main::initNES1_i#1 ← ++ (byte) main::initNES1_i#2 - (bool~) main::initNES1_$5 ← (number) 0 != (byte) main::initNES1_i#1 - if((bool~) main::initNES1_$5) goto main::initNES1_@1 + (byte~) main::initNES1_$5 ← (byte) main::initNES1_i#1 + (bool~) main::initNES1_$6 ← (number) 0 != (byte~) main::initNES1_$5 + if((bool~) main::initNES1_$6) goto main::initNES1_@1 to:main::initNES1_waitForVBlank2 main::initNES1_waitForVBlank2: scope:[main] from main::initNES1_@1 to:main::initNES1_waitForVBlank2_@1 @@ -1186,7 +1188,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -1341,7 +1344,8 @@ SYMBOL TABLE SSA (byte) main::i#6 (byte) main::i#7 (label) main::initNES1 -(bool~) main::initNES1_$5 +(byte~) main::initNES1_$5 +(bool~) main::initNES1_$6 (label) main::initNES1_@1 (label) main::initNES1_@6 (label) main::initNES1_@7 @@ -1906,7 +1910,7 @@ Adding number conversion cast (unumber) $20 in (nomodify void*) ppuDataFill::ppu Adding number conversion cast (unumber) $1e*$20 in (nomodify void*) ppuDataFill::ppuData#1 ← (void*)(const nomodify byte*) CONIO_SCREEN_TEXT+(number) $1e*(number) $20-(unumber)(number) $20 Adding number conversion cast (unumber) $20 in (word) ppuDataFill::size#1 ← (number) $20 Adding number conversion cast (unumber) $20 in (byte*) conio_line_text ← (byte*) conio_line_text - (number) $20 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 3 in (byte) uctoa::max_digits#1 ← (number) 3 Adding number conversion cast (unumber) 2 in (byte) uctoa::max_digits#2 ← (number) 2 Adding number conversion cast (unumber) 3 in (byte) uctoa::max_digits#3 ← (number) 3 @@ -1939,7 +1943,7 @@ Adding number conversion cast (unumber) 0 in *((const nomodify byte*) MEMORY+(nu Adding number conversion cast (unumber) $600 in *((const nomodify byte*) MEMORY+(number) $600 + (byte) main::initNES1_i#2) ← ((unumber)) (number) 0 Adding number conversion cast (unumber) 0 in *((const nomodify byte*) MEMORY+(number) $700 + (byte) main::initNES1_i#2) ← (number) 0 Adding number conversion cast (unumber) $700 in *((const nomodify byte*) MEMORY+(number) $700 + (byte) main::initNES1_i#2) ← ((unumber)) (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) main::initNES1_$5 ← (number) 0 != (byte) main::initNES1_i#1 +Adding number conversion cast (unumber) 0 in (bool~) main::initNES1_$6 ← (number) 0 != (byte~) main::initNES1_$5 Adding number conversion cast (unumber) $80 in (number~) main::initNES1_waitForVBlank2_$0 ← *((byte*~) main::initNES1_waitForVBlank2_$2) & (number) $80 Adding number conversion cast (unumber) main::initNES1_waitForVBlank2_$0 in (number~) main::initNES1_waitForVBlank2_$0 ← *((byte*~) main::initNES1_waitForVBlank2_$2) & (unumber)(number) $80 Adding number conversion cast (unumber) 0 in (bool~) main::initNES1_waitForVBlank2_$4 ← (number) 0 != (unumber~) main::initNES1_waitForVBlank2_$0 @@ -2236,14 +2240,14 @@ Inversing boolean not [134] (bool~) gotoxy::$1 ← (byte) gotoxy::y#4 <= (byte) Inversing boolean not [138] (bool~) gotoxy::$3 ← (byte) gotoxy::x#4 < (byte) $20 from [137] (bool~) gotoxy::$2 ← (byte) gotoxy::x#4 >= (byte) $20 Inversing boolean not [164] (bool~) cputc::$4 ← (byte) conio_cursor_x != (byte) $20 from [163] (bool~) cputc::$3 ← (byte) conio_cursor_x == (byte) $20 Inversing boolean not [174] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $1e from [173] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $1e -Inversing boolean not [332] (bool~) main::initNES1_waitForVBlank1_$1 ← (byte) 0 == (byte~) main::initNES1_waitForVBlank1_$0 from [331] (bool~) main::initNES1_waitForVBlank1_$4 ← (byte) 0 != (byte~) main::initNES1_waitForVBlank1_$0 -Inversing boolean not [351] (bool~) main::initNES1_waitForVBlank2_$1 ← (byte) 0 == (byte~) main::initNES1_waitForVBlank2_$0 from [350] (bool~) main::initNES1_waitForVBlank2_$4 ← (byte) 0 != (byte~) main::initNES1_waitForVBlank2_$0 -Inversing boolean not [466] (bool~) vblank::$2 ← (byte) 0 == (byte~) vblank::$1 from [465] (bool~) vblank::$17 ← (byte) 0 != (byte~) vblank::$1 -Inversing boolean not [471] (bool~) vblank::$4 ← (byte) 0 == (byte~) vblank::$3 from [470] (bool~) vblank::$18 ← (byte) 0 != (byte~) vblank::$3 -Inversing boolean not [476] (bool~) vblank::$10 ← (volatile byte) y_scroll != (byte) $f0 from [475] (bool~) vblank::$9 ← (volatile byte) y_scroll == (byte) $f0 -Inversing boolean not [483] (bool~) vblank::$6 ← (byte) 0 == (byte~) vblank::$5 from [482] (bool~) vblank::$19 ← (byte) 0 != (byte~) vblank::$5 -Inversing boolean not [488] (bool~) vblank::$12 ← (volatile byte) y_scroll != (byte) $ff from [487] (bool~) vblank::$11 ← (volatile byte) y_scroll == (byte) $ff -Inversing boolean not [495] (bool~) vblank::$8 ← (byte) 0 == (byte~) vblank::$7 from [494] (bool~) vblank::$20 ← (byte) 0 != (byte~) vblank::$7 +Inversing boolean not [333] (bool~) main::initNES1_waitForVBlank1_$1 ← (byte) 0 == (byte~) main::initNES1_waitForVBlank1_$0 from [332] (bool~) main::initNES1_waitForVBlank1_$4 ← (byte) 0 != (byte~) main::initNES1_waitForVBlank1_$0 +Inversing boolean not [353] (bool~) main::initNES1_waitForVBlank2_$1 ← (byte) 0 == (byte~) main::initNES1_waitForVBlank2_$0 from [352] (bool~) main::initNES1_waitForVBlank2_$4 ← (byte) 0 != (byte~) main::initNES1_waitForVBlank2_$0 +Inversing boolean not [468] (bool~) vblank::$2 ← (byte) 0 == (byte~) vblank::$1 from [467] (bool~) vblank::$17 ← (byte) 0 != (byte~) vblank::$1 +Inversing boolean not [473] (bool~) vblank::$4 ← (byte) 0 == (byte~) vblank::$3 from [472] (bool~) vblank::$18 ← (byte) 0 != (byte~) vblank::$3 +Inversing boolean not [478] (bool~) vblank::$10 ← (volatile byte) y_scroll != (byte) $f0 from [477] (bool~) vblank::$9 ← (volatile byte) y_scroll == (byte) $f0 +Inversing boolean not [485] (bool~) vblank::$6 ← (byte) 0 == (byte~) vblank::$5 from [484] (bool~) vblank::$19 ← (byte) 0 != (byte~) vblank::$5 +Inversing boolean not [490] (bool~) vblank::$12 ← (volatile byte) y_scroll != (byte) $ff from [489] (bool~) vblank::$11 ← (volatile byte) y_scroll == (byte) $ff +Inversing boolean not [497] (bool~) vblank::$8 ← (byte) 0 == (byte~) vblank::$7 from [496] (bool~) vblank::$20 ← (byte) 0 != (byte~) vblank::$7 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias readJoy1::joy#2 = readJoy1::joy#4 readJoy1::joy#3 readJoy1::return#0 readJoy1::return#3 readJoy1::return#1 @@ -2278,7 +2282,7 @@ Alias cputc::c#2 = cputc::c#3 Alias cscroll::line2#2 = cscroll::line2#4 cscroll::line2#5 cscroll::line2#3 Alias cscroll::line1#2 = cscroll::line1#4 cscroll::line1#5 cscroll::line1#3 Alias cscroll::y#2 = cscroll::y#5 cscroll::y#4 cscroll::y#3 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#5 cputs::s#4 Alias cputcxy::c#4 = cputcxy::c#5 Alias cputsxy::s#1 = cputsxy::s#2 @@ -2298,6 +2302,7 @@ Alias uctoa_append::digit#2 = uctoa_append::digit#4 uctoa_append::digit#3 Alias uctoa_append::value#2 = uctoa_append::value#3 uctoa_append::value#4 uctoa_append::return#1 uctoa_append::return#4 uctoa_append::return#2 Alias uctoa_append::sub#1 = uctoa_append::sub#2 Alias uctoa_append::buffer#1 = uctoa_append::buffer#4 uctoa_append::buffer#2 +Alias main::initNES1_i#1 = main::initNES1_$5 Alias ppuDataTransfer::size#1 = main::$1 Alias main::screensizex1_return#0 = main::screensizex1_return#2 main::screensizex1_return#1 main::screensizex1_return#3 main::$7 Alias main::x#10 = main::x#6 main::x#8 main::x#2 main::x#3 main::x#9 main::x#7 main::x#4 main::x#5 @@ -2362,7 +2367,7 @@ Simple Condition (bool~) cputc::$4 [126] if((byte) conio_cursor_x!=(byte) $20) g Simple Condition (bool~) cscroll::$1 [135] if((byte) conio_cursor_y!=(byte) $1e) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [137] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 Simple Condition (bool~) cscroll::$3 [146] if((byte) cscroll::y#2<(byte)(number) $1e-(number) 1) goto cscroll::@5 -Simple Condition (bool~) cputs::$1 [171] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [171] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) uctoa::$0 [193] if((byte) uctoa::radix#0==(const byte) DECIMAL) goto uctoa::@1 Simple Condition (bool~) uctoa::$1 [197] if((byte) uctoa::radix#0==(const byte) HEXADECIMAL) goto uctoa::@2 Simple Condition (bool~) uctoa::$2 [201] if((byte) uctoa::radix#0==(const byte) OCTAL) goto uctoa::@3 @@ -2370,7 +2375,7 @@ Simple Condition (bool~) uctoa::$3 [205] if((byte) uctoa::radix#0==(const byte) Simple Condition (bool~) uctoa::$5 [222] if((byte) uctoa::digit#2<(byte~) uctoa::$4) goto uctoa::@11 Simple Condition (bool~) uctoa_append::$0 [245] if((byte) uctoa_append::value#2>=(byte) uctoa_append::sub#0) goto uctoa_append::@2 Simple Condition (bool~) main::initNES1_waitForVBlank1_$1 [266] if((byte) 0==(byte~) main::initNES1_waitForVBlank1_$0) goto main::initNES1_waitForVBlank1_@1 -Simple Condition (bool~) main::initNES1_$5 [279] if((byte) 0!=(byte) main::initNES1_i#1) goto main::initNES1_@1 +Simple Condition (bool~) main::initNES1_$6 [279] if((byte) 0!=(byte) main::initNES1_i#1) goto main::initNES1_@1 Simple Condition (bool~) main::initNES1_waitForVBlank2_$1 [284] if((byte) 0==(byte~) main::initNES1_waitForVBlank2_$0) goto main::initNES1_waitForVBlank2_@1 Simple Condition (bool~) main::$9 [304] if((byte) main::x#10<(byte~) main::$8) goto main::@1 Simple Condition (bool~) main::$16 [320] if((byte) main::y#10<(byte~) main::$15) goto main::@3 @@ -9536,11 +9541,10 @@ cputs: { sta.z s+1 // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [187] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#2) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [188] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#2 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/examples/nes-demo/nes-demo.log b/src/test/ref/examples/nes-demo/nes-demo.log index e54b07b33..58f6b9f96 100644 --- a/src/test/ref/examples/nes-demo/nes-demo.log +++ b/src/test/ref/examples/nes-demo/nes-demo.log @@ -410,8 +410,9 @@ main::initNES1_@1: scope:[main] from main::initNES1_@1 main::initNES1_@6 *((const nomodify byte*) MEMORY+(number) $600 + (byte) main::initNES1_i#2) ← (number) 0 *((const nomodify byte*) MEMORY+(number) $700 + (byte) main::initNES1_i#2) ← (number) 0 (byte) main::initNES1_i#1 ← ++ (byte) main::initNES1_i#2 - (bool~) main::initNES1_$5 ← (number) 0 != (byte) main::initNES1_i#1 - if((bool~) main::initNES1_$5) goto main::initNES1_@1 + (byte~) main::initNES1_$5 ← (byte) main::initNES1_i#1 + (bool~) main::initNES1_$6 ← (number) 0 != (byte~) main::initNES1_$5 + if((bool~) main::initNES1_$6) goto main::initNES1_@1 to:main::initNES1_waitForVBlank2 main::initNES1_waitForVBlank2: scope:[main] from main::initNES1_@1 to:main::initNES1_waitForVBlank2_@1 @@ -711,7 +712,8 @@ SYMBOL TABLE SSA (byte*~) main::enableVideoOutput1_$2 (byte*~) main::enableVideoOutput1_$3 (label) main::initNES1 -(bool~) main::initNES1_$5 +(byte~) main::initNES1_$5 +(bool~) main::initNES1_$6 (label) main::initNES1_@1 (label) main::initNES1_@6 (label) main::initNES1_@7 @@ -1102,7 +1104,7 @@ Adding number conversion cast (unumber) 0 in *((const nomodify byte*) MEMORY+(nu Adding number conversion cast (unumber) $600 in *((const nomodify byte*) MEMORY+(number) $600 + (byte) main::initNES1_i#2) ← ((unumber)) (number) 0 Adding number conversion cast (unumber) 0 in *((const nomodify byte*) MEMORY+(number) $700 + (byte) main::initNES1_i#2) ← (number) 0 Adding number conversion cast (unumber) $700 in *((const nomodify byte*) MEMORY+(number) $700 + (byte) main::initNES1_i#2) ← ((unumber)) (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) main::initNES1_$5 ← (number) 0 != (byte) main::initNES1_i#1 +Adding number conversion cast (unumber) 0 in (bool~) main::initNES1_$6 ← (number) 0 != (byte~) main::initNES1_$5 Adding number conversion cast (unumber) $80 in (number~) main::initNES1_waitForVBlank2_$0 ← *((byte*~) main::initNES1_waitForVBlank2_$2) & (number) $80 Adding number conversion cast (unumber) main::initNES1_waitForVBlank2_$0 in (number~) main::initNES1_waitForVBlank2_$0 ← *((byte*~) main::initNES1_waitForVBlank2_$2) & (unumber)(number) $80 Adding number conversion cast (unumber) 0 in (bool~) main::initNES1_waitForVBlank2_$4 ← (number) 0 != (unumber~) main::initNES1_waitForVBlank2_$0 @@ -1349,11 +1351,11 @@ Inferred type updated to byte in (unumber~) vblank::$53 ← (byte) 1 * (const by Inferred type updated to byte in (unumber~) vblank::$55 ← (byte) 2 * (const byte) SIZEOF_STRUCT_SPRITEDATA Inferred type updated to byte in (unumber~) vblank::$57 ← (byte) 3 * (const byte) SIZEOF_STRUCT_SPRITEDATA Inversing boolean not [159] (bool~) main::initNES1_waitForVBlank1_$1 ← (byte) 0 == (byte~) main::initNES1_waitForVBlank1_$0 from [158] (bool~) main::initNES1_waitForVBlank1_$4 ← (byte) 0 != (byte~) main::initNES1_waitForVBlank1_$0 -Inversing boolean not [178] (bool~) main::initNES1_waitForVBlank2_$1 ← (byte) 0 == (byte~) main::initNES1_waitForVBlank2_$0 from [177] (bool~) main::initNES1_waitForVBlank2_$4 ← (byte) 0 != (byte~) main::initNES1_waitForVBlank2_$0 -Inversing boolean not [230] (bool~) vblank::$2 ← (byte) 0 == (byte~) vblank::$1 from [229] (bool~) vblank::$62 ← (byte) 0 != (byte~) vblank::$1 -Inversing boolean not [235] (bool~) vblank::$4 ← (byte) 0 == (byte~) vblank::$3 from [234] (bool~) vblank::$63 ← (byte) 0 != (byte~) vblank::$3 -Inversing boolean not [249] (bool~) vblank::$6 ← (byte) 0 == (byte~) vblank::$5 from [248] (bool~) vblank::$64 ← (byte) 0 != (byte~) vblank::$5 -Inversing boolean not [263] (bool~) vblank::$8 ← (byte) 0 == (byte~) vblank::$7 from [262] (bool~) vblank::$65 ← (byte) 0 != (byte~) vblank::$7 +Inversing boolean not [179] (bool~) main::initNES1_waitForVBlank2_$1 ← (byte) 0 == (byte~) main::initNES1_waitForVBlank2_$0 from [178] (bool~) main::initNES1_waitForVBlank2_$4 ← (byte) 0 != (byte~) main::initNES1_waitForVBlank2_$0 +Inversing boolean not [231] (bool~) vblank::$2 ← (byte) 0 == (byte~) vblank::$1 from [230] (bool~) vblank::$62 ← (byte) 0 != (byte~) vblank::$1 +Inversing boolean not [236] (bool~) vblank::$4 ← (byte) 0 == (byte~) vblank::$3 from [235] (bool~) vblank::$63 ← (byte) 0 != (byte~) vblank::$3 +Inversing boolean not [250] (bool~) vblank::$6 ← (byte) 0 == (byte~) vblank::$5 from [249] (bool~) vblank::$64 ← (byte) 0 != (byte~) vblank::$5 +Inversing boolean not [264] (bool~) vblank::$8 ← (byte) 0 == (byte~) vblank::$7 from [263] (bool~) vblank::$65 ← (byte) 0 != (byte~) vblank::$7 Successful SSA optimization Pass2UnaryNotSimplification Alias readJoy1::joy#2 = readJoy1::joy#4 readJoy1::joy#3 readJoy1::return#0 readJoy1::return#3 readJoy1::return#1 Alias readJoy1::i#2 = readJoy1::i#3 @@ -1383,6 +1385,7 @@ Alias memcpy::src#2 = memcpy::src#3 Alias memcpy::dst#2 = memcpy::dst#3 Alias memcpy::src_end#1 = memcpy::src_end#2 Alias memcpy::destination#2 = memcpy::destination#4 memcpy::destination#3 memcpy::return#0 memcpy::return#3 memcpy::return#1 +Alias main::initNES1_i#1 = main::initNES1_$5 Alias ppuDataTransfer::size#0 = main::$1 Alias main::x#2 = main::x#3 main::x#4 Alias memcpy::num#0 = main::$6 @@ -1411,7 +1414,7 @@ Simple Condition (bool~) ppuDataFill::$1 [30] if((word) ppuDataFill::i#2<(word) Simple Condition (bool~) ppuDataTransfer::$1 [49] if((word) ppuDataTransfer::i#2<(word) ppuDataTransfer::size#0) goto ppuDataTransfer::@2 Simple Condition (bool~) memcpy::$1 [101] if((byte*) memcpy::src#2!=(byte*) memcpy::src_end#0) goto memcpy::@2 Simple Condition (bool~) main::initNES1_waitForVBlank1_$1 [122] if((byte) 0==(byte~) main::initNES1_waitForVBlank1_$0) goto main::initNES1_waitForVBlank1_@1 -Simple Condition (bool~) main::initNES1_$5 [135] if((byte) 0!=(byte) main::initNES1_i#1) goto main::initNES1_@1 +Simple Condition (bool~) main::initNES1_$6 [135] if((byte) 0!=(byte) main::initNES1_i#1) goto main::initNES1_@1 Simple Condition (bool~) main::initNES1_waitForVBlank2_$1 [140] if((byte) 0==(byte~) main::initNES1_waitForVBlank2_$0) goto main::initNES1_waitForVBlank2_@1 Simple Condition (bool~) main::$9 [157] if((byte) main::x#2<(byte) $20) goto main::@2 Simple Condition (bool~) main::$12 [178] if((number) 0!=(number) 1) goto main::@4 diff --git a/src/test/ref/examples/nes-dxycp/nes-dxycp.log b/src/test/ref/examples/nes-dxycp/nes-dxycp.log index 865f23345..f1a6a19b5 100644 --- a/src/test/ref/examples/nes-dxycp/nes-dxycp.log +++ b/src/test/ref/examples/nes-dxycp/nes-dxycp.log @@ -238,8 +238,9 @@ main::initNES1_@1: scope:[main] from main::initNES1_@1 main::initNES1_@6 *((const nomodify byte*) MEMORY+(number) $600 + (byte) main::initNES1_i#2) ← (number) 0 *((const nomodify byte*) MEMORY+(number) $700 + (byte) main::initNES1_i#2) ← (number) 0 (byte) main::initNES1_i#1 ← ++ (byte) main::initNES1_i#2 - (bool~) main::initNES1_$5 ← (number) 0 != (byte) main::initNES1_i#1 - if((bool~) main::initNES1_$5) goto main::initNES1_@1 + (byte~) main::initNES1_$5 ← (byte) main::initNES1_i#1 + (bool~) main::initNES1_$6 ← (number) 0 != (byte~) main::initNES1_$5 + if((bool~) main::initNES1_$6) goto main::initNES1_@1 to:main::initNES1_waitForVBlank2 main::initNES1_waitForVBlank2: scope:[main] from main::initNES1_@1 to:main::initNES1_waitForVBlank2_@1 @@ -574,7 +575,8 @@ SYMBOL TABLE SSA (byte*~) main::enableVideoOutput1_$2 (byte*~) main::enableVideoOutput1_$3 (label) main::initNES1 -(bool~) main::initNES1_$5 +(byte~) main::initNES1_$5 +(bool~) main::initNES1_$6 (label) main::initNES1_@1 (label) main::initNES1_@6 (label) main::initNES1_@7 @@ -898,7 +900,7 @@ Adding number conversion cast (unumber) 0 in *((const nomodify byte*) MEMORY+(nu Adding number conversion cast (unumber) $600 in *((const nomodify byte*) MEMORY+(number) $600 + (byte) main::initNES1_i#2) ← ((unumber)) (number) 0 Adding number conversion cast (unumber) 0 in *((const nomodify byte*) MEMORY+(number) $700 + (byte) main::initNES1_i#2) ← (number) 0 Adding number conversion cast (unumber) $700 in *((const nomodify byte*) MEMORY+(number) $700 + (byte) main::initNES1_i#2) ← ((unumber)) (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) main::initNES1_$5 ← (number) 0 != (byte) main::initNES1_i#1 +Adding number conversion cast (unumber) 0 in (bool~) main::initNES1_$6 ← (number) 0 != (byte~) main::initNES1_$5 Adding number conversion cast (unumber) $80 in (number~) main::initNES1_waitForVBlank2_$0 ← *((byte*~) main::initNES1_waitForVBlank2_$2) & (number) $80 Adding number conversion cast (unumber) main::initNES1_waitForVBlank2_$0 in (number~) main::initNES1_waitForVBlank2_$0 ← *((byte*~) main::initNES1_waitForVBlank2_$2) & (unumber)(number) $80 Adding number conversion cast (unumber) 0 in (bool~) main::initNES1_waitForVBlank2_$4 ← (number) 0 != (unumber~) main::initNES1_waitForVBlank2_$0 @@ -1124,8 +1126,8 @@ Inferred type updated to byte in (unumber~) vblank::$22 ← (byte) vblank::x_idx Inferred type updated to byte in (unumber~) vblank::$23 ← (byte~) vblank::$22 Inferred type updated to byte for (unumber~) vblank::$26 Inversing boolean not [92] (bool~) main::initNES1_waitForVBlank1_$1 ← (byte) 0 == (byte~) main::initNES1_waitForVBlank1_$0 from [91] (bool~) main::initNES1_waitForVBlank1_$4 ← (byte) 0 != (byte~) main::initNES1_waitForVBlank1_$0 -Inversing boolean not [111] (bool~) main::initNES1_waitForVBlank2_$1 ← (byte) 0 == (byte~) main::initNES1_waitForVBlank2_$0 from [110] (bool~) main::initNES1_waitForVBlank2_$4 ← (byte) 0 != (byte~) main::initNES1_waitForVBlank2_$0 -Inversing boolean not [168] (bool~) vblank::$2 ← (byte) 0 == (byte) vblank::joy#0 from [167] (bool~) vblank::$33 ← (byte) 0 != (byte) vblank::joy#0 +Inversing boolean not [112] (bool~) main::initNES1_waitForVBlank2_$1 ← (byte) 0 == (byte~) main::initNES1_waitForVBlank2_$0 from [111] (bool~) main::initNES1_waitForVBlank2_$4 ← (byte) 0 != (byte~) main::initNES1_waitForVBlank2_$0 +Inversing boolean not [169] (bool~) vblank::$2 ← (byte) 0 == (byte) vblank::joy#0 from [168] (bool~) vblank::$33 ← (byte) 0 != (byte) vblank::joy#0 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)x_sin_idx = vblank::$7 Alias candidate removed (volatile)x_sin_idx_2 = vblank::$12 @@ -1145,6 +1147,7 @@ Alias ppuDataTransfer::cpuSrc#2 = ppuDataTransfer::cpuSrc#4 ppuDataTransfer::cpu Alias ppuDataTransfer::i#2 = ppuDataTransfer::i#5 ppuDataTransfer::i#4 ppuDataTransfer::i#3 Alias ppuDataTransfer::size#1 = ppuDataTransfer::size#7 ppuDataTransfer::size#5 ppuDataTransfer::size#3 Alias ppuDataTransfer::ppuDataPut1_val#0 = ppuDataTransfer::ppuDataPut1_val#1 +Alias main::initNES1_i#1 = main::initNES1_$5 Alias ppuDataTransfer::size#0 = main::$1 Alias main::s#2 = main::s#3 Alias vblank::ppuSpriteBufferDmaTransfer1_spriteBuffer#0 = vblank::ppuSpriteBufferDmaTransfer1_spriteBuffer#1 @@ -1188,13 +1191,13 @@ Identical Phi Values (nomodify void*) ppuDataTransfer::cpuData#1 (nomodify void* Identical Phi Values (word) ppuDataTransfer::size#2 (word) ppuDataTransfer::size#0 Identical Phi Values (word) ppuDataTransfer::size#1 (word) ppuDataTransfer::size#2 Successful SSA optimization Pass2IdenticalPhiElimination -Identified duplicate assignment right side [202] (byte~) vblank::$28 ← (byte) vblank::s#2 * (const byte) SIZEOF_STRUCT_SPRITEDATA +Identified duplicate assignment right side [203] (byte~) vblank::$28 ← (byte) vblank::s#2 * (const byte) SIZEOF_STRUCT_SPRITEDATA Successful SSA optimization Pass2DuplicateRValueIdentification Simple Condition (bool~) readJoy1::$0 [10] if((byte) readJoy1::i#2<(byte) 8) goto readJoy1::@2 Simple Condition (bool~) ppuDataFill::$1 [30] if((word) ppuDataFill::i#2<(word) ppuDataFill::size#3) goto ppuDataFill::@2 Simple Condition (bool~) ppuDataTransfer::$1 [49] if((word) ppuDataTransfer::i#2<(word) ppuDataTransfer::size#0) goto ppuDataTransfer::@2 Simple Condition (bool~) main::initNES1_waitForVBlank1_$1 [73] if((byte) 0==(byte~) main::initNES1_waitForVBlank1_$0) goto main::initNES1_waitForVBlank1_@1 -Simple Condition (bool~) main::initNES1_$5 [86] if((byte) 0!=(byte) main::initNES1_i#1) goto main::initNES1_@1 +Simple Condition (bool~) main::initNES1_$6 [86] if((byte) 0!=(byte) main::initNES1_i#1) goto main::initNES1_@1 Simple Condition (bool~) main::initNES1_waitForVBlank2_$1 [91] if((byte) 0==(byte~) main::initNES1_waitForVBlank2_$0) goto main::initNES1_waitForVBlank2_@1 Simple Condition (bool~) main::$6 [108] if((byte) main::s#2<(byte) $40) goto main::@2 Simple Condition (bool~) main::$8 [122] if((number) 0!=(number) 1) goto main::@3 diff --git a/src/test/ref/post-increment-problem-3.asm b/src/test/ref/post-increment-problem-3.asm new file mode 100644 index 000000000..8068c59e3 --- /dev/null +++ b/src/test/ref/post-increment-problem-3.asm @@ -0,0 +1,23 @@ +// Illustrates a problem with post-incrementing inside the while loop condition +// https://gitlab.com/camelot/kickc/-/issues/486 +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" +main: { + // n = *(ptr++) + lda mmap + __b1: + // while (n--) + tax + dex + cmp #0 + bne __b2 + // } + rts + __b2: + // *((unsigned char *)0x400) = n + stx $400 + txa + jmp __b1 +} + mmap: .byte 2, $5c, $1a, 3, $60, $1a, 7 diff --git a/src/test/ref/post-increment-problem-3.cfg b/src/test/ref/post-increment-problem-3.cfg new file mode 100644 index 000000000..65fab62cf --- /dev/null +++ b/src/test/ref/post-increment-problem-3.cfg @@ -0,0 +1,17 @@ + +(void()) main() +main: scope:[main] from + [0] (byte) main::n#0 ← *((const to_nomodify byte*) mmap) + to:main::@1 +main::@1: scope:[main] from main main::@2 + [1] (byte) main::n#2 ← phi( main/(byte) main::n#0 main::@2/(byte) main::n#5 ) + [2] (byte) main::n#1 ← -- (byte) main::n#2 + [3] if((byte) 0!=(byte) main::n#2) goto main::@2 + to:main::@return +main::@return: scope:[main] from main::@1 + [4] return + to:@return +main::@2: scope:[main] from main::@1 + [5] *((byte*) 1024) ← (byte) main::n#1 + [6] (byte) main::n#5 ← (byte) main::n#1 + to:main::@1 diff --git a/src/test/ref/post-increment-problem-3.log b/src/test/ref/post-increment-problem-3.log new file mode 100644 index 000000000..7a468fead --- /dev/null +++ b/src/test/ref/post-increment-problem-3.log @@ -0,0 +1,296 @@ + +CONTROL FLOW GRAPH SSA + +(void()) main() +main: scope:[main] from __start + (byte*) main::ptr#0 ← (const to_nomodify byte*) mmap + (byte) main::n#0 ← *((byte*) main::ptr#0) + (byte*) main::ptr#1 ← ++ (byte*) main::ptr#0 + to:main::@1 +main::@1: scope:[main] from main main::@2 + (byte) main::n#2 ← phi( main/(byte) main::n#0 main::@2/(byte) main::n#3 ) + (byte~) main::$0 ← (byte) main::n#2 + (byte) main::n#1 ← -- (byte) main::n#2 + (bool~) main::$1 ← (number) 0 != (byte~) main::$0 + if((bool~) main::$1) goto main::@2 + to:main::@return +main::@2: scope:[main] from main::@1 + (byte) main::n#3 ← phi( main::@1/(byte) main::n#1 ) + *((byte*)(number) $400) ← (byte) main::n#3 + to:main::@1 +main::@return: scope:[main] from main::@1 + return + to:@return + +(void()) __start() +__start: scope:[__start] from + call main + to:__start::@1 +__start::@1: scope:[__start] from __start + to:__start::@return +__start::@return: scope:[__start] from __start::@1 + return + to:@return + +SYMBOL TABLE SSA +(void()) __start() +(label) __start::@1 +(label) __start::@return +(void()) main() +(byte~) main::$0 +(bool~) main::$1 +(label) main::@1 +(label) main::@2 +(label) main::@return +(byte) main::n +(byte) main::n#0 +(byte) main::n#1 +(byte) main::n#2 +(byte) main::n#3 +(byte*) main::ptr +(byte*) main::ptr#0 +(byte*) main::ptr#1 +(const to_nomodify byte*) mmap[] = { (byte) 2, (byte) $5c, (byte) $1a, (byte) 3, (byte) $60, (byte) $1a, (byte) 7 } + +Adding number conversion cast (unumber) 0 in (bool~) main::$1 ← (number) 0 != (byte~) main::$0 +Successful SSA optimization PassNAddNumberTypeConversions +Simplifying constant integer cast 0 +Simplifying constant pointer cast (byte*) 1024 +Successful SSA optimization PassNCastSimplification +Finalized unsigned number type (byte) 0 +Successful SSA optimization PassNFinalizeNumberTypeConversions +Alias main::n#2 = main::$0 +Alias main::n#1 = main::n#3 +Successful SSA optimization Pass2AliasElimination +Simple Condition (bool~) main::$1 [6] if((byte) 0!=(byte) main::n#2) goto main::@2 +Successful SSA optimization Pass2ConditionalJumpSimplification +Constant (const byte*) main::ptr#0 = mmap +Successful SSA optimization Pass2ConstantIdentification +Eliminating unused variable (byte*) main::ptr#1 and assignment [1] (byte*) main::ptr#1 ← ++ (const byte*) main::ptr#0 +Successful SSA optimization PassNEliminateUnusedVars +Removing unused procedure __start +Removing unused procedure block __start +Removing unused procedure block __start::@1 +Removing unused procedure block __start::@return +Successful SSA optimization PassNEliminateEmptyStart +Constant inlined main::ptr#0 = (const to_nomodify byte*) mmap +Successful SSA optimization Pass2ConstantInlining +CALL GRAPH + +Created 1 initial phi equivalence classes +Coalesced [1] main::n#4 ← main::n#0 +Not coalescing [7] main::n#5 ← main::n#1 +Coalesced down to 2 phi equivalence classes + +FINAL CONTROL FLOW GRAPH + +(void()) main() +main: scope:[main] from + [0] (byte) main::n#0 ← *((const to_nomodify byte*) mmap) + to:main::@1 +main::@1: scope:[main] from main main::@2 + [1] (byte) main::n#2 ← phi( main/(byte) main::n#0 main::@2/(byte) main::n#5 ) + [2] (byte) main::n#1 ← -- (byte) main::n#2 + [3] if((byte) 0!=(byte) main::n#2) goto main::@2 + to:main::@return +main::@return: scope:[main] from main::@1 + [4] return + to:@return +main::@2: scope:[main] from main::@1 + [5] *((byte*) 1024) ← (byte) main::n#1 + [6] (byte) main::n#5 ← (byte) main::n#1 + to:main::@1 + + +VARIABLE REGISTER WEIGHTS +(void()) main() +(byte) main::n +(byte) main::n#0 4.0 +(byte) main::n#1 11.0 +(byte) main::n#2 17.5 +(byte) main::n#5 22.0 +(byte*) main::ptr + +Initial phi equivalence classes +[ main::n#2 main::n#0 main::n#5 ] +Added variable main::n#1 to live range equivalence class [ main::n#1 ] +Complete equivalence classes +[ main::n#2 main::n#0 main::n#5 ] +[ main::n#1 ] +Allocated zp[1]:2 [ main::n#2 main::n#0 main::n#5 ] +Allocated zp[1]:3 [ main::n#1 ] + +INITIAL ASM +Target platform is c64basic / MOS6502X + // File Comments +// Illustrates a problem with post-incrementing inside the while loop condition +// https://gitlab.com/camelot/kickc/-/issues/486 + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + // main +main: { + .label n = 2 + .label n_1 = 3 + // [0] (byte) main::n#0 ← *((const to_nomodify byte*) mmap) -- vbuz1=_deref_pbuc1 + lda mmap + sta.z n + // [1] phi from main main::@2 to main::@1 [phi:main/main::@2->main::@1] + __b1_from_main: + __b1_from___b2: + // [1] phi (byte) main::n#2 = (byte) main::n#0 [phi:main/main::@2->main::@1#0] -- register_copy + jmp __b1 + // main::@1 + __b1: + // [2] (byte) main::n#1 ← -- (byte) main::n#2 -- vbuz1=_dec_vbuz2 + ldy.z n + dey + sty.z n_1 + // [3] if((byte) 0!=(byte) main::n#2) goto main::@2 -- vbuc1_neq_vbuz1_then_la1 + lda #0 + cmp.z n + bne __b2 + jmp __breturn + // main::@return + __breturn: + // [4] return + rts + // main::@2 + __b2: + // [5] *((byte*) 1024) ← (byte) main::n#1 -- _deref_pbuc1=vbuz1 + lda.z n_1 + sta $400 + // [6] (byte) main::n#5 ← (byte) main::n#1 -- vbuz1=vbuz2 + lda.z n_1 + sta.z n + jmp __b1_from___b2 +} + // File Data + mmap: .byte 2, $5c, $1a, 3, $60, $1a, 7 + +REGISTER UPLIFT POTENTIAL REGISTERS +Potential registers zp[1]:2 [ main::n#2 main::n#0 main::n#5 ] : zp[1]:2 , reg byte a , reg byte x , reg byte y , +Potential registers zp[1]:3 [ main::n#1 ] : zp[1]:3 , reg byte a , reg byte x , reg byte y , + +REGISTER UPLIFT SCOPES +Uplift Scope [main] 43.5: zp[1]:2 [ main::n#2 main::n#0 main::n#5 ] 11: zp[1]:3 [ main::n#1 ] +Uplift Scope [] + +Uplifting [main] best 245 combination reg byte a [ main::n#2 main::n#0 main::n#5 ] reg byte x [ main::n#1 ] +Uplifting [] best 245 combination + +ASSEMBLER BEFORE OPTIMIZATION + // File Comments +// Illustrates a problem with post-incrementing inside the while loop condition +// https://gitlab.com/camelot/kickc/-/issues/486 + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + // main +main: { + // [0] (byte) main::n#0 ← *((const to_nomodify byte*) mmap) -- vbuaa=_deref_pbuc1 + lda mmap + // [1] phi from main main::@2 to main::@1 [phi:main/main::@2->main::@1] + __b1_from_main: + __b1_from___b2: + // [1] phi (byte) main::n#2 = (byte) main::n#0 [phi:main/main::@2->main::@1#0] -- register_copy + jmp __b1 + // main::@1 + __b1: + // [2] (byte) main::n#1 ← -- (byte) main::n#2 -- vbuxx=_dec_vbuaa + tax + dex + // [3] if((byte) 0!=(byte) main::n#2) goto main::@2 -- vbuc1_neq_vbuaa_then_la1 + cmp #0 + bne __b2 + jmp __breturn + // main::@return + __breturn: + // [4] return + rts + // main::@2 + __b2: + // [5] *((byte*) 1024) ← (byte) main::n#1 -- _deref_pbuc1=vbuxx + stx $400 + // [6] (byte) main::n#5 ← (byte) main::n#1 -- vbuaa=vbuxx + txa + jmp __b1_from___b2 +} + // File Data + mmap: .byte 2, $5c, $1a, 3, $60, $1a, 7 + +ASSEMBLER OPTIMIZATIONS +Removing instruction jmp __b1 +Removing instruction jmp __breturn +Succesful ASM optimization Pass5NextJumpElimination +Replacing label __b1_from___b2 with __b1 +Removing instruction __b1_from_main: +Removing instruction __b1_from___b2: +Succesful ASM optimization Pass5RedundantLabelElimination +Removing instruction __breturn: +Succesful ASM optimization Pass5UnusedLabelElimination + +FINAL SYMBOL TABLE +(void()) main() +(label) main::@1 +(label) main::@2 +(label) main::@return +(byte) main::n +(byte) main::n#0 reg byte a 4.0 +(byte) main::n#1 reg byte x 11.0 +(byte) main::n#2 reg byte a 17.5 +(byte) main::n#5 reg byte a 22.0 +(byte*) main::ptr +(const to_nomodify byte*) mmap[] = { (byte) 2, (byte) $5c, (byte) $1a, (byte) 3, (byte) $60, (byte) $1a, (byte) 7 } + +reg byte a [ main::n#2 main::n#0 main::n#5 ] +reg byte x [ main::n#1 ] + + +FINAL ASSEMBLER +Score: 185 + + // File Comments +// Illustrates a problem with post-incrementing inside the while loop condition +// https://gitlab.com/camelot/kickc/-/issues/486 + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + // main +main: { + // n = *(ptr++) + // [0] (byte) main::n#0 ← *((const to_nomodify byte*) mmap) -- vbuaa=_deref_pbuc1 + lda mmap + // [1] phi from main main::@2 to main::@1 [phi:main/main::@2->main::@1] + // [1] phi (byte) main::n#2 = (byte) main::n#0 [phi:main/main::@2->main::@1#0] -- register_copy + // main::@1 + __b1: + // while (n--) + // [2] (byte) main::n#1 ← -- (byte) main::n#2 -- vbuxx=_dec_vbuaa + tax + dex + // [3] if((byte) 0!=(byte) main::n#2) goto main::@2 -- vbuc1_neq_vbuaa_then_la1 + cmp #0 + bne __b2 + // main::@return + // } + // [4] return + rts + // main::@2 + __b2: + // *((unsigned char *)0x400) = n + // [5] *((byte*) 1024) ← (byte) main::n#1 -- _deref_pbuc1=vbuxx + stx $400 + // [6] (byte) main::n#5 ← (byte) main::n#1 -- vbuaa=vbuxx + txa + jmp __b1 +} + // File Data + mmap: .byte 2, $5c, $1a, 3, $60, $1a, 7 + diff --git a/src/test/ref/post-increment-problem-3.sym b/src/test/ref/post-increment-problem-3.sym new file mode 100644 index 000000000..85ebb08f0 --- /dev/null +++ b/src/test/ref/post-increment-problem-3.sym @@ -0,0 +1,14 @@ +(void()) main() +(label) main::@1 +(label) main::@2 +(label) main::@return +(byte) main::n +(byte) main::n#0 reg byte a 4.0 +(byte) main::n#1 reg byte x 11.0 +(byte) main::n#2 reg byte a 17.5 +(byte) main::n#5 reg byte a 22.0 +(byte*) main::ptr +(const to_nomodify byte*) mmap[] = { (byte) 2, (byte) $5c, (byte) $1a, (byte) 3, (byte) $60, (byte) $1a, (byte) 7 } + +reg byte a [ main::n#2 main::n#0 main::n#5 ] +reg byte x [ main::n#1 ] diff --git a/src/test/ref/post-increment-problem-4.asm b/src/test/ref/post-increment-problem-4.asm new file mode 100644 index 000000000..74d36c71f --- /dev/null +++ b/src/test/ref/post-increment-problem-4.asm @@ -0,0 +1,34 @@ +// Illustrates a problem with post-incrementing inside the while loop condition +// https://gitlab.com/camelot/kickc/-/issues/486 +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + .label SCREEN = $400 +main: { + .label s = 2 + ldx #0 + lda #MESSAGE + sta.z s+1 + __b1: + // while(c=*s++) + ldy #0 + lda (s),y + inc.z s + bne !+ + inc.z s+1 + !: + cmp #0 + bne __b2 + // } + rts + __b2: + // SCREEN[i++] = c + sta SCREEN,x + // SCREEN[i++] = c; + inx + jmp __b1 +} + MESSAGE: .text "hello world!" + .byte 0 diff --git a/src/test/ref/post-increment-problem-4.cfg b/src/test/ref/post-increment-problem-4.cfg new file mode 100644 index 000000000..01ef00675 --- /dev/null +++ b/src/test/ref/post-increment-problem-4.cfg @@ -0,0 +1,19 @@ + +(void()) main() +main: scope:[main] from + [0] phi() + to:main::@1 +main::@1: scope:[main] from main main::@2 + [1] (byte) main::i#2 ← phi( main/(byte) 0 main::@2/(byte) main::i#1 ) + [1] (byte*) main::s#2 ← phi( main/(const byte*) MESSAGE main::@2/(byte*) main::s#1 ) + [2] (byte) main::c#1 ← *((byte*) main::s#2) + [3] (byte*) main::s#1 ← ++ (byte*) main::s#2 + [4] if((byte) 0!=(byte) main::c#1) goto main::@2 + to:main::@return +main::@return: scope:[main] from main::@1 + [5] return + to:@return +main::@2: scope:[main] from main::@1 + [6] *((const nomodify byte*) SCREEN + (byte) main::i#2) ← (byte) main::c#1 + [7] (byte) main::i#1 ← ++ (byte) main::i#2 + to:main::@1 diff --git a/src/test/ref/post-increment-problem-4.log b/src/test/ref/post-increment-problem-4.log new file mode 100644 index 000000000..2b290a8d1 --- /dev/null +++ b/src/test/ref/post-increment-problem-4.log @@ -0,0 +1,375 @@ + +CONTROL FLOW GRAPH SSA + +(void()) main() +main: scope:[main] from __start + (byte*) main::s#0 ← (const byte*) MESSAGE + (byte) main::c#0 ← (byte) 0 + (byte) main::i#0 ← (byte) 0 + to:main::@1 +main::@1: scope:[main] from main main::@2 + (byte) main::i#3 ← phi( main/(byte) main::i#0 main::@2/(byte) main::i#1 ) + (byte*) main::s#2 ← phi( main/(byte*) main::s#0 main::@2/(byte*) main::s#3 ) + (byte) main::c#1 ← *((byte*) main::s#2) + (byte~) main::$0 ← (byte) main::c#1 + (byte*) main::s#1 ← ++ (byte*) main::s#2 + (bool~) main::$1 ← (number) 0 != (byte~) main::$0 + if((bool~) main::$1) goto main::@2 + to:main::@return +main::@2: scope:[main] from main::@1 + (byte*) main::s#3 ← phi( main::@1/(byte*) main::s#1 ) + (byte) main::i#2 ← phi( main::@1/(byte) main::i#3 ) + (byte) main::c#2 ← phi( main::@1/(byte) main::c#1 ) + *((const nomodify byte*) SCREEN + (byte) main::i#2) ← (byte) main::c#2 + (byte) main::i#1 ← ++ (byte) main::i#2 + to:main::@1 +main::@return: scope:[main] from main::@1 + return + to:@return + +(void()) __start() +__start: scope:[__start] from + call main + to:__start::@1 +__start::@1: scope:[__start] from __start + to:__start::@return +__start::@return: scope:[__start] from __start::@1 + return + to:@return + +SYMBOL TABLE SSA +(const byte*) MESSAGE[] = (byte*) "hello world!" +(const nomodify byte*) SCREEN = (byte*)(number) $400 +(void()) __start() +(label) __start::@1 +(label) __start::@return +(void()) main() +(byte~) main::$0 +(bool~) main::$1 +(label) main::@1 +(label) main::@2 +(label) main::@return +(byte) main::c +(byte) main::c#0 +(byte) main::c#1 +(byte) main::c#2 +(byte) main::i +(byte) main::i#0 +(byte) main::i#1 +(byte) main::i#2 +(byte) main::i#3 +(byte*) main::s +(byte*) main::s#0 +(byte*) main::s#1 +(byte*) main::s#2 +(byte*) main::s#3 + +Adding number conversion cast (unumber) 0 in (bool~) main::$1 ← (number) 0 != (byte~) main::$0 +Successful SSA optimization PassNAddNumberTypeConversions +Simplifying constant pointer cast (byte*) 1024 +Simplifying constant integer cast 0 +Successful SSA optimization PassNCastSimplification +Finalized unsigned number type (byte) 0 +Successful SSA optimization PassNFinalizeNumberTypeConversions +Alias main::c#1 = main::$0 main::c#2 +Alias main::i#2 = main::i#3 +Alias main::s#1 = main::s#3 +Successful SSA optimization Pass2AliasElimination +Simple Condition (bool~) main::$1 [7] if((byte) 0!=(byte) main::c#1) goto main::@2 +Successful SSA optimization Pass2ConditionalJumpSimplification +Constant (const byte*) main::s#0 = MESSAGE +Constant (const byte) main::c#0 = 0 +Constant (const byte) main::i#0 = 0 +Successful SSA optimization Pass2ConstantIdentification +Eliminating unused constant (const byte) main::c#0 +Successful SSA optimization PassNEliminateUnusedVars +Removing unused procedure __start +Removing unused procedure block __start +Removing unused procedure block __start::@1 +Removing unused procedure block __start::@return +Successful SSA optimization PassNEliminateEmptyStart +Inlining constant with var siblings (const byte*) main::s#0 +Inlining constant with var siblings (const byte) main::i#0 +Constant inlined main::i#0 = (byte) 0 +Constant inlined main::s#0 = (const byte*) MESSAGE +Successful SSA optimization Pass2ConstantInlining +Adding NOP phi() at start of main +CALL GRAPH + +Created 2 initial phi equivalence classes +Coalesced [8] main::s#4 ← main::s#1 +Coalesced [9] main::i#4 ← main::i#1 +Coalesced down to 2 phi equivalence classes +Adding NOP phi() at start of main + +FINAL CONTROL FLOW GRAPH + +(void()) main() +main: scope:[main] from + [0] phi() + to:main::@1 +main::@1: scope:[main] from main main::@2 + [1] (byte) main::i#2 ← phi( main/(byte) 0 main::@2/(byte) main::i#1 ) + [1] (byte*) main::s#2 ← phi( main/(const byte*) MESSAGE main::@2/(byte*) main::s#1 ) + [2] (byte) main::c#1 ← *((byte*) main::s#2) + [3] (byte*) main::s#1 ← ++ (byte*) main::s#2 + [4] if((byte) 0!=(byte) main::c#1) goto main::@2 + to:main::@return +main::@return: scope:[main] from main::@1 + [5] return + to:@return +main::@2: scope:[main] from main::@1 + [6] *((const nomodify byte*) SCREEN + (byte) main::i#2) ← (byte) main::c#1 + [7] (byte) main::i#1 ← ++ (byte) main::i#2 + to:main::@1 + + +VARIABLE REGISTER WEIGHTS +(void()) main() +(byte) main::c +(byte) main::c#1 11.0 +(byte) main::i +(byte) main::i#1 22.0 +(byte) main::i#2 6.6000000000000005 +(byte*) main::s +(byte*) main::s#1 5.5 +(byte*) main::s#2 16.5 + +Initial phi equivalence classes +[ main::s#2 main::s#1 ] +[ main::i#2 main::i#1 ] +Added variable main::c#1 to live range equivalence class [ main::c#1 ] +Complete equivalence classes +[ main::s#2 main::s#1 ] +[ main::i#2 main::i#1 ] +[ main::c#1 ] +Allocated zp[2]:2 [ main::s#2 main::s#1 ] +Allocated zp[1]:4 [ main::i#2 main::i#1 ] +Allocated zp[1]:5 [ main::c#1 ] + +INITIAL ASM +Target platform is c64basic / MOS6502X + // File Comments +// Illustrates a problem with post-incrementing inside the while loop condition +// https://gitlab.com/camelot/kickc/-/issues/486 + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + .label SCREEN = $400 + // main +main: { + .label c = 5 + .label s = 2 + .label i = 4 + // [1] phi from main to main::@1 [phi:main->main::@1] + __b1_from_main: + // [1] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuz1=vbuc1 + lda #0 + sta.z i + // [1] phi (byte*) main::s#2 = (const byte*) MESSAGE [phi:main->main::@1#1] -- pbuz1=pbuc1 + lda #MESSAGE + sta.z s+1 + jmp __b1 + // main::@1 + __b1: + // [2] (byte) main::c#1 ← *((byte*) main::s#2) -- vbuz1=_deref_pbuz2 + ldy #0 + lda (s),y + sta.z c + // [3] (byte*) main::s#1 ← ++ (byte*) main::s#2 -- pbuz1=_inc_pbuz1 + inc.z s + bne !+ + inc.z s+1 + !: + // [4] if((byte) 0!=(byte) main::c#1) goto main::@2 -- vbuc1_neq_vbuz1_then_la1 + lda #0 + cmp.z c + bne __b2 + jmp __breturn + // main::@return + __breturn: + // [5] return + rts + // main::@2 + __b2: + // [6] *((const nomodify byte*) SCREEN + (byte) main::i#2) ← (byte) main::c#1 -- pbuc1_derefidx_vbuz1=vbuz2 + lda.z c + ldy.z i + sta SCREEN,y + // [7] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuz1=_inc_vbuz1 + inc.z i + // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1] + __b1_from___b2: + // [1] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#0] -- register_copy + // [1] phi (byte*) main::s#2 = (byte*) main::s#1 [phi:main::@2->main::@1#1] -- register_copy + jmp __b1 +} + // File Data + MESSAGE: .text "hello world!" + .byte 0 + +REGISTER UPLIFT POTENTIAL REGISTERS +Statement [2] (byte) main::c#1 ← *((byte*) main::s#2) [ main::s#2 main::i#2 main::c#1 ] ( [ main::s#2 main::i#2 main::c#1 ] { } ) always clobbers reg byte a reg byte y +Removing always clobbered register reg byte a as potential for zp[1]:4 [ main::i#2 main::i#1 ] +Removing always clobbered register reg byte y as potential for zp[1]:4 [ main::i#2 main::i#1 ] +Statement [2] (byte) main::c#1 ← *((byte*) main::s#2) [ main::s#2 main::i#2 main::c#1 ] ( [ main::s#2 main::i#2 main::c#1 ] { } ) always clobbers reg byte a reg byte y +Potential registers zp[2]:2 [ main::s#2 main::s#1 ] : zp[2]:2 , +Potential registers zp[1]:4 [ main::i#2 main::i#1 ] : zp[1]:4 , reg byte x , +Potential registers zp[1]:5 [ main::c#1 ] : zp[1]:5 , reg byte a , reg byte x , reg byte y , + +REGISTER UPLIFT SCOPES +Uplift Scope [main] 28.6: zp[1]:4 [ main::i#2 main::i#1 ] 22: zp[2]:2 [ main::s#2 main::s#1 ] 11: zp[1]:5 [ main::c#1 ] +Uplift Scope [] + +Uplifting [main] best 531 combination reg byte x [ main::i#2 main::i#1 ] zp[2]:2 [ main::s#2 main::s#1 ] reg byte a [ main::c#1 ] +Uplifting [] best 531 combination + +ASSEMBLER BEFORE OPTIMIZATION + // File Comments +// Illustrates a problem with post-incrementing inside the while loop condition +// https://gitlab.com/camelot/kickc/-/issues/486 + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + .label SCREEN = $400 + // main +main: { + .label s = 2 + // [1] phi from main to main::@1 [phi:main->main::@1] + __b1_from_main: + // [1] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 + ldx #0 + // [1] phi (byte*) main::s#2 = (const byte*) MESSAGE [phi:main->main::@1#1] -- pbuz1=pbuc1 + lda #MESSAGE + sta.z s+1 + jmp __b1 + // main::@1 + __b1: + // [2] (byte) main::c#1 ← *((byte*) main::s#2) -- vbuaa=_deref_pbuz1 + ldy #0 + lda (s),y + // [3] (byte*) main::s#1 ← ++ (byte*) main::s#2 -- pbuz1=_inc_pbuz1 + inc.z s + bne !+ + inc.z s+1 + !: + // [4] if((byte) 0!=(byte) main::c#1) goto main::@2 -- vbuc1_neq_vbuaa_then_la1 + cmp #0 + bne __b2 + jmp __breturn + // main::@return + __breturn: + // [5] return + rts + // main::@2 + __b2: + // [6] *((const nomodify byte*) SCREEN + (byte) main::i#2) ← (byte) main::c#1 -- pbuc1_derefidx_vbuxx=vbuaa + sta SCREEN,x + // [7] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx + inx + // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1] + __b1_from___b2: + // [1] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#0] -- register_copy + // [1] phi (byte*) main::s#2 = (byte*) main::s#1 [phi:main::@2->main::@1#1] -- register_copy + jmp __b1 +} + // File Data + MESSAGE: .text "hello world!" + .byte 0 + +ASSEMBLER OPTIMIZATIONS +Removing instruction jmp __b1 +Removing instruction jmp __breturn +Succesful ASM optimization Pass5NextJumpElimination +Removing instruction __b1_from_main: +Removing instruction __breturn: +Removing instruction __b1_from___b2: +Succesful ASM optimization Pass5UnusedLabelElimination + +FINAL SYMBOL TABLE +(const byte*) MESSAGE[] = (byte*) "hello world!" +(const nomodify byte*) SCREEN = (byte*) 1024 +(void()) main() +(label) main::@1 +(label) main::@2 +(label) main::@return +(byte) main::c +(byte) main::c#1 reg byte a 11.0 +(byte) main::i +(byte) main::i#1 reg byte x 22.0 +(byte) main::i#2 reg byte x 6.6000000000000005 +(byte*) main::s +(byte*) main::s#1 s zp[2]:2 5.5 +(byte*) main::s#2 s zp[2]:2 16.5 + +zp[2]:2 [ main::s#2 main::s#1 ] +reg byte x [ main::i#2 main::i#1 ] +reg byte a [ main::c#1 ] + + +FINAL ASSEMBLER +Score: 471 + + // File Comments +// Illustrates a problem with post-incrementing inside the while loop condition +// https://gitlab.com/camelot/kickc/-/issues/486 + // Upstart +.pc = $801 "Basic" +:BasicUpstart(main) +.pc = $80d "Program" + // Global Constants & labels + .label SCREEN = $400 + // main +main: { + .label s = 2 + // [1] phi from main to main::@1 [phi:main->main::@1] + // [1] phi (byte) main::i#2 = (byte) 0 [phi:main->main::@1#0] -- vbuxx=vbuc1 + ldx #0 + // [1] phi (byte*) main::s#2 = (const byte*) MESSAGE [phi:main->main::@1#1] -- pbuz1=pbuc1 + lda #MESSAGE + sta.z s+1 + // main::@1 + __b1: + // while(c=*s++) + // [2] (byte) main::c#1 ← *((byte*) main::s#2) -- vbuaa=_deref_pbuz1 + ldy #0 + lda (s),y + // [3] (byte*) main::s#1 ← ++ (byte*) main::s#2 -- pbuz1=_inc_pbuz1 + inc.z s + bne !+ + inc.z s+1 + !: + // [4] if((byte) 0!=(byte) main::c#1) goto main::@2 -- vbuc1_neq_vbuaa_then_la1 + cmp #0 + bne __b2 + // main::@return + // } + // [5] return + rts + // main::@2 + __b2: + // SCREEN[i++] = c + // [6] *((const nomodify byte*) SCREEN + (byte) main::i#2) ← (byte) main::c#1 -- pbuc1_derefidx_vbuxx=vbuaa + sta SCREEN,x + // SCREEN[i++] = c; + // [7] (byte) main::i#1 ← ++ (byte) main::i#2 -- vbuxx=_inc_vbuxx + inx + // [1] phi from main::@2 to main::@1 [phi:main::@2->main::@1] + // [1] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#0] -- register_copy + // [1] phi (byte*) main::s#2 = (byte*) main::s#1 [phi:main::@2->main::@1#1] -- register_copy + jmp __b1 +} + // File Data + MESSAGE: .text "hello world!" + .byte 0 + diff --git a/src/test/ref/post-increment-problem-4.sym b/src/test/ref/post-increment-problem-4.sym new file mode 100644 index 000000000..dbc5fe207 --- /dev/null +++ b/src/test/ref/post-increment-problem-4.sym @@ -0,0 +1,18 @@ +(const byte*) MESSAGE[] = (byte*) "hello world!" +(const nomodify byte*) SCREEN = (byte*) 1024 +(void()) main() +(label) main::@1 +(label) main::@2 +(label) main::@return +(byte) main::c +(byte) main::c#1 reg byte a 11.0 +(byte) main::i +(byte) main::i#1 reg byte x 22.0 +(byte) main::i#2 reg byte x 6.6000000000000005 +(byte*) main::s +(byte*) main::s#1 s zp[2]:2 5.5 +(byte*) main::s#2 s zp[2]:2 16.5 + +zp[2]:2 [ main::s#2 main::s#1 ] +reg byte x [ main::i#2 main::i#1 ] +reg byte a [ main::c#1 ] diff --git a/src/test/ref/printf-1.asm b/src/test/ref/printf-1.asm index 894bd6d76..e5cb796df 100644 --- a/src/test/ref/printf-1.asm +++ b/src/test/ref/printf-1.asm @@ -303,10 +303,9 @@ printf_padding: { cputs: { .label s = 3 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/printf-1.log b/src/test/ref/printf-1.log index 4a6d2a279..2ca931369 100644 --- a/src/test/ref/printf-1.log +++ b/src/test/ref/printf-1.log @@ -321,9 +321,10 @@ cputs: scope:[cputs] from printf_string::@2 cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#2 ← phi( cputs/(to_nomodify byte*) cputs::s#3 cputs::@3/(to_nomodify byte*) cputs::s#4 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#2) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#2 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#5 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -681,7 +682,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -1011,7 +1013,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 0 in (bool~) printf_string::$14 ← (number) 0 != (byte) printf_string::format_min_length#4 Adding number conversion cast (unumber) 0 in (bool~) printf_string::$15 ← (number) 0 != (byte) printf_string::format_justify_left#4 Adding number conversion cast (snumber) 0 in (bool~) printf_string::$11 ← (signed byte) printf_string::padding#1 < (number) 0 @@ -1143,9 +1145,9 @@ Inversing boolean not [77] (bool~) gotoxy::$1 ← (byte) gotoxy::y#2 <= (byte) $ Inversing boolean not [81] (bool~) gotoxy::$3 ← (byte) gotoxy::x#2 < (byte) $28 from [80] (bool~) gotoxy::$2 ← (byte) gotoxy::x#2 >= (byte) $28 Inversing boolean not [107] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [106] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [118] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [117] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [175] (bool~) printf_string::$0 ← (byte) 0 == (byte) printf_string::format_min_length#4 from [174] (bool~) printf_string::$14 ← (byte) 0 != (byte) printf_string::format_min_length#4 -Inversing boolean not [179] (bool~) printf_string::$1 ← (byte) 0 == (byte) printf_string::format_justify_left#4 from [178] (bool~) printf_string::$15 ← (byte) 0 != (byte) printf_string::format_justify_left#4 -Inversing boolean not [194] (bool~) printf_string::$12 ← (signed byte) printf_string::padding#1 >= (signed byte) 0 from [193] (bool~) printf_string::$11 ← (signed byte) printf_string::padding#1 < (signed byte) 0 +Inversing boolean not [176] (bool~) printf_string::$0 ← (byte) 0 == (byte) printf_string::format_min_length#4 from [175] (bool~) printf_string::$14 ← (byte) 0 != (byte) printf_string::format_min_length#4 +Inversing boolean not [180] (bool~) printf_string::$1 ← (byte) 0 == (byte) printf_string::format_justify_left#4 from [179] (bool~) printf_string::$15 ← (byte) 0 != (byte) printf_string::format_justify_left#4 +Inversing boolean not [195] (bool~) printf_string::$12 ← (signed byte) printf_string::padding#1 >= (signed byte) 0 from [194] (bool~) printf_string::$11 ← (signed byte) printf_string::padding#1 < (signed byte) 0 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -1176,7 +1178,7 @@ Alias gotoxy::x#4 = gotoxy::x#5 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#4 = gotoxy::y#5 Alias cputc::c#2 = cputc::c#3 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#5 cputs::s#4 Alias printf_padding::pad#2 = printf_padding::pad#3 printf_padding::pad#5 Alias printf_padding::i#2 = printf_padding::i#4 printf_padding::i#3 @@ -1232,7 +1234,7 @@ Simple Condition (bool~) cputc::$0 [74] if((byte) cputc::c#2==(byte) ' Simple Condition (bool~) cputc::$2 [80] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [90] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [92] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [126] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [126] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) printf_padding::$0 [134] if((byte) printf_padding::i#2<(byte) printf_padding::length#3) goto printf_padding::@2 Simple Condition (bool~) printf_string::$0 [142] if((byte) 0==(byte) printf_string::format_min_length#4) goto printf_string::@1 Simple Condition (bool~) printf_string::$12 [156] if((signed byte) printf_string::padding#1>=(signed byte) 0) goto printf_string::@1 @@ -4923,11 +4925,10 @@ cputs: { // [82] phi (to_nomodify byte*) cputs::s#2 = (to_nomodify byte*) cputs::s#1 [phi:cputs/cputs::@2->cputs::@1#0] -- register_copy // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [83] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#2) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [84] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#2 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/printf-12.asm b/src/test/ref/printf-12.asm index 309a6d3ae..258f7f58e 100644 --- a/src/test/ref/printf-12.asm +++ b/src/test/ref/printf-12.asm @@ -291,10 +291,9 @@ clrscr: { cputs: { .label s = 8 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/printf-12.log b/src/test/ref/printf-12.log index 655465097..027d907df 100644 --- a/src/test/ref/printf-12.log +++ b/src/test/ref/printf-12.log @@ -928,9 +928,10 @@ cputs: scope:[cputs] from main::@1 main::@10 main::@12 main::@13 main::@15 main cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#20 ← phi( cputs/(to_nomodify byte*) cputs::s#21 cputs::@3/(to_nomodify byte*) cputs::s#22 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#20) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#20 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#23 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -2023,7 +2024,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -3512,7 +3514,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 0 in *((byte*)&(struct printf_buffer_number) printf_buffer+(const byte) OFFSET_STRUCT_PRINTF_BUFFER_NUMBER_SIGN) ← (number) 0 Adding number conversion cast (snumber) 0 in (bool~) printf_slong::$0 ← (signed dword) printf_slong::value#2 < (number) 0 Adding number conversion cast (unumber) 0 in (bool~) printf_slong::$5 ← (number) 0 != (byte) printf_slong::format_sign_always#1 @@ -3808,17 +3810,17 @@ Inversing boolean not [350] (bool~) gotoxy::$1 ← (byte) gotoxy::y#2 <= (byte) Inversing boolean not [354] (bool~) gotoxy::$3 ← (byte) gotoxy::x#2 < (byte) $28 from [353] (bool~) gotoxy::$2 ← (byte) gotoxy::x#2 >= (byte) $28 Inversing boolean not [380] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [379] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [391] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [390] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [455] (bool~) printf_slong::$3 ← (byte) 0 == (byte) printf_slong::format_sign_always#1 from [454] (bool~) printf_slong::$5 ← (byte) 0 != (byte) printf_slong::format_sign_always#1 -Inversing boolean not [510] (bool~) printf_sint::$3 ← (byte) 0 == (byte) printf_sint::format_sign_always#1 from [509] (bool~) printf_sint::$5 ← (byte) 0 != (byte) printf_sint::format_sign_always#1 -Inversing boolean not [565] (bool~) printf_schar::$3 ← (byte) 0 == (byte) printf_schar::format_sign_always#1 from [564] (bool~) printf_schar::$5 ← (byte) 0 != (byte) printf_schar::format_sign_always#1 -Inversing boolean not [613] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#6 from [612] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#6 -Inversing boolean not [617] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#6 from [616] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#6 -Inversing boolean not [619] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#6 from [618] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#6 -Inversing boolean not [632] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#6 from [631] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#6 -Inversing boolean not [639] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [638] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 -Inversing boolean not [647] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#7 from [646] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#7 -Inversing boolean not [664] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#6 from [663] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#6 -Inversing boolean not [676] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#8 from [675] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#8 +Inversing boolean not [456] (bool~) printf_slong::$3 ← (byte) 0 == (byte) printf_slong::format_sign_always#1 from [455] (bool~) printf_slong::$5 ← (byte) 0 != (byte) printf_slong::format_sign_always#1 +Inversing boolean not [511] (bool~) printf_sint::$3 ← (byte) 0 == (byte) printf_sint::format_sign_always#1 from [510] (bool~) printf_sint::$5 ← (byte) 0 != (byte) printf_sint::format_sign_always#1 +Inversing boolean not [566] (bool~) printf_schar::$3 ← (byte) 0 == (byte) printf_schar::format_sign_always#1 from [565] (bool~) printf_schar::$5 ← (byte) 0 != (byte) printf_schar::format_sign_always#1 +Inversing boolean not [614] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#6 from [613] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#6 +Inversing boolean not [618] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#6 from [617] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#6 +Inversing boolean not [620] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#6 from [619] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#6 +Inversing boolean not [633] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#6 from [632] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#6 +Inversing boolean not [640] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [639] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 +Inversing boolean not [648] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#7 from [647] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#7 +Inversing boolean not [665] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#6 from [664] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#6 +Inversing boolean not [677] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#8 from [676] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#8 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -3904,7 +3906,7 @@ Alias gotoxy::x#4 = gotoxy::x#5 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#4 = gotoxy::y#5 Alias cputc::c#5 = cputc::c#6 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#23 cputs::s#22 Alias printf_padding::pad#3 = printf_padding::pad#4 printf_padding::pad#6 Alias printf_padding::i#2 = printf_padding::i#4 printf_padding::i#3 @@ -4217,7 +4219,7 @@ Simple Condition (bool~) cputc::$0 [280] if((byte) cputc::c#5==(byte) ' Simple Condition (bool~) cputc::$2 [286] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [296] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [298] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [332] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [332] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) printf_padding::$0 [340] if((byte) printf_padding::i#2<(byte) printf_padding::length#4) goto printf_padding::@2 Simple Condition (bool~) printf_slong::$0 [348] if((signed dword) printf_slong::value#1<(signed byte) 0) goto printf_slong::@1 Simple Condition (bool~) printf_slong::$3 [352] if((byte) 0==(byte) printf_slong::format_sign_always#0) goto printf_slong::@2 @@ -13730,11 +13732,10 @@ cputs: { // [82] phi (to_nomodify byte*) cputs::s#20 = (to_nomodify byte*) cputs::s#21 [phi:cputs/cputs::@2->cputs::@1#0] -- register_copy // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [83] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#20) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [84] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#20 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/printf-13.asm b/src/test/ref/printf-13.asm index d2429bde3..9bf54f9e5 100644 --- a/src/test/ref/printf-13.asm +++ b/src/test/ref/printf-13.asm @@ -816,10 +816,9 @@ cputc: { cputs: { .label s = 2 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/printf-13.log b/src/test/ref/printf-13.log index 69180ee6b..19ad06536 100644 --- a/src/test/ref/printf-13.log +++ b/src/test/ref/printf-13.log @@ -599,9 +599,10 @@ cputs: scope:[cputs] from main::@10 main::@12 main::@14 main::@16 main::@18 mai cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#48 ← phi( cputs/(to_nomodify byte*) cputs::s#49 cputs::@3/(to_nomodify byte*) cputs::s#50 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#48) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#48 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#51 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -1863,7 +1864,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -3117,7 +3119,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 0 in *((byte*)&(struct printf_buffer_number) printf_buffer+(const byte) OFFSET_STRUCT_PRINTF_BUFFER_NUMBER_SIGN) ← (number) 0 Adding number conversion cast (snumber) 0 in (bool~) printf_sint::$0 ← (signed word) printf_sint::value#17 < (number) 0 Adding number conversion cast (unumber) 0 in (bool~) printf_sint::$5 ← (number) 0 != (byte) printf_sint::format_sign_always#16 @@ -3419,18 +3421,18 @@ Inversing boolean not [189] (bool~) gotoxy::$1 ← (byte) gotoxy::y#2 <= (byte) Inversing boolean not [193] (bool~) gotoxy::$3 ← (byte) gotoxy::x#2 < (byte) $28 from [192] (bool~) gotoxy::$2 ← (byte) gotoxy::x#2 >= (byte) $28 Inversing boolean not [219] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [218] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [230] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [229] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [294] (bool~) printf_sint::$3 ← (byte) 0 == (byte) printf_sint::format_sign_always#16 from [293] (bool~) printf_sint::$5 ← (byte) 0 != (byte) printf_sint::format_sign_always#16 -Inversing boolean not [342] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#2 from [341] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#2 -Inversing boolean not [346] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#2 from [345] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#2 -Inversing boolean not [348] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#2 from [347] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#2 -Inversing boolean not [361] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [360] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 -Inversing boolean not [368] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [367] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 -Inversing boolean not [376] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#3 from [375] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#3 -Inversing boolean not [393] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#2 from [392] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#2 -Inversing boolean not [405] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#4 from [404] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#4 -Inversing boolean not [423] (bool~) printf_string::$0 ← (byte) 0 == (byte) printf_string::format_min_length#8 from [422] (bool~) printf_string::$14 ← (byte) 0 != (byte) printf_string::format_min_length#8 -Inversing boolean not [427] (bool~) printf_string::$1 ← (byte) 0 == (byte) printf_string::format_justify_left#8 from [426] (bool~) printf_string::$15 ← (byte) 0 != (byte) printf_string::format_justify_left#8 -Inversing boolean not [442] (bool~) printf_string::$12 ← (signed byte) printf_string::padding#1 >= (signed byte) 0 from [441] (bool~) printf_string::$11 ← (signed byte) printf_string::padding#1 < (signed byte) 0 +Inversing boolean not [295] (bool~) printf_sint::$3 ← (byte) 0 == (byte) printf_sint::format_sign_always#16 from [294] (bool~) printf_sint::$5 ← (byte) 0 != (byte) printf_sint::format_sign_always#16 +Inversing boolean not [343] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#2 from [342] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#2 +Inversing boolean not [347] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#2 from [346] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#2 +Inversing boolean not [349] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#2 from [348] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#2 +Inversing boolean not [362] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [361] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 +Inversing boolean not [369] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [368] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 +Inversing boolean not [377] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#3 from [376] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#3 +Inversing boolean not [394] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#2 from [393] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#2 +Inversing boolean not [406] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#4 from [405] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#4 +Inversing boolean not [424] (bool~) printf_string::$0 ← (byte) 0 == (byte) printf_string::format_min_length#8 from [423] (bool~) printf_string::$14 ← (byte) 0 != (byte) printf_string::format_min_length#8 +Inversing boolean not [428] (bool~) printf_string::$1 ← (byte) 0 == (byte) printf_string::format_justify_left#8 from [427] (bool~) printf_string::$15 ← (byte) 0 != (byte) printf_string::format_justify_left#8 +Inversing boolean not [443] (bool~) printf_string::$12 ← (signed byte) printf_string::padding#1 >= (signed byte) 0 from [442] (bool~) printf_string::$11 ← (signed byte) printf_string::padding#1 < (signed byte) 0 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -3484,7 +3486,7 @@ Alias gotoxy::x#4 = gotoxy::x#5 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#4 = gotoxy::y#5 Alias cputc::c#12 = cputc::c#13 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#51 cputs::s#50 Alias printf_padding::pad#5 = printf_padding::pad#6 printf_padding::pad#8 Alias printf_padding::i#2 = printf_padding::i#4 printf_padding::i#3 @@ -3658,7 +3660,7 @@ Simple Condition (bool~) cputc::$0 [156] if((byte) cputc::c#12==(byte) ' Simple Condition (bool~) cputc::$2 [162] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [172] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [174] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [208] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [208] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) printf_padding::$0 [216] if((byte) printf_padding::i#2<(byte) printf_padding::length#6) goto printf_padding::@2 Simple Condition (bool~) printf_sint::$0 [224] if((signed word) printf_sint::value#17<(signed byte) 0) goto printf_sint::@1 Simple Condition (bool~) printf_sint::$3 [228] if((byte) 0==(byte) printf_sint::format_sign_always#16) goto printf_sint::@2 @@ -15849,11 +15851,10 @@ cputs: { // [219] phi (to_nomodify byte*) cputs::s#48 = (to_nomodify byte*) cputs::s#49 [phi:cputs/cputs::@2->cputs::@1#0] -- register_copy // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [220] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#48) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [221] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#48 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/printf-14.asm b/src/test/ref/printf-14.asm index 0ea78cf7d..56f0b2fdc 100644 --- a/src/test/ref/printf-14.asm +++ b/src/test/ref/printf-14.asm @@ -288,10 +288,9 @@ cputs: { lda #>printf_number_buffer.buffer_digits sta.z s+1 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/printf-14.log b/src/test/ref/printf-14.log index 551e82e86..cd28cca34 100644 --- a/src/test/ref/printf-14.log +++ b/src/test/ref/printf-14.log @@ -555,9 +555,10 @@ cputs: scope:[cputs] from printf_number_buffer::@5 cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#2 ← phi( cputs/(to_nomodify byte*) cputs::s#3 cputs::@3/(to_nomodify byte*) cputs::s#4 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#2) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#2 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#5 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -1105,7 +1106,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -1806,7 +1808,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 0 in (bool~) printf_uchar::$5 ← (number) 0 != (byte) printf_uchar::format_sign_always#1 Adding number conversion cast (unumber) printf_uchar::$2 in (byte) printf_uchar::format_upper_case#2 ← phi( printf_uchar::@1/(byte) printf_uchar::format_upper_case#3 printf_uchar::@2/(byte) printf_uchar::format_upper_case#4 ) (byte) printf_uchar::format_zero_padding#2 ← phi( printf_uchar::@1/(byte) printf_uchar::format_zero_padding#3 printf_uchar::@2/(byte) printf_uchar::format_zero_padding#4 ) @@ -1974,14 +1976,14 @@ Inversing boolean not [188] (bool~) gotoxy::$1 ← (byte) gotoxy::y#2 <= (byte) Inversing boolean not [192] (bool~) gotoxy::$3 ← (byte) gotoxy::x#2 < (byte) $28 from [191] (bool~) gotoxy::$2 ← (byte) gotoxy::x#2 >= (byte) $28 Inversing boolean not [218] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [217] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [229] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [228] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [310] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#1 from [309] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#1 -Inversing boolean not [314] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#1 from [313] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#1 -Inversing boolean not [316] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#1 from [315] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#1 -Inversing boolean not [329] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#1 from [328] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#1 -Inversing boolean not [336] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [335] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 -Inversing boolean not [344] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [343] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 -Inversing boolean not [361] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#1 from [360] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#1 -Inversing boolean not [373] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [372] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 +Inversing boolean not [311] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#1 from [310] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#1 +Inversing boolean not [315] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#1 from [314] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#1 +Inversing boolean not [317] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#1 from [316] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#1 +Inversing boolean not [330] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#1 from [329] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#1 +Inversing boolean not [337] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [336] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 +Inversing boolean not [345] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [344] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 +Inversing boolean not [362] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#1 from [361] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#1 +Inversing boolean not [374] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [373] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -2035,7 +2037,7 @@ Alias gotoxy::x#4 = gotoxy::x#5 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#4 = gotoxy::y#5 Alias cputc::c#3 = cputc::c#4 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#5 cputs::s#4 Alias printf_padding::pad#3 = printf_padding::pad#4 printf_padding::pad#6 Alias printf_padding::i#2 = printf_padding::i#4 printf_padding::i#3 @@ -2194,7 +2196,7 @@ Simple Condition (bool~) cputc::$0 [154] if((byte) cputc::c#3==(byte) ' Simple Condition (bool~) cputc::$2 [160] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [170] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [172] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [206] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [206] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) printf_padding::$0 [214] if((byte) printf_padding::i#2<(byte) printf_padding::length#4) goto printf_padding::@2 Simple Condition (bool~) printf_uchar::$5 [221] if((byte) 0!=(byte) printf_uchar::format_sign_always#0) goto printf_uchar::@1 Simple Condition (bool~) printf_number_buffer::$0 [243] if((byte) 0==(byte) printf_number_buffer::format_min_length#0) goto printf_number_buffer::@1 @@ -6032,11 +6034,10 @@ cputs: { sta.z s+1 // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [81] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#2) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [82] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#2 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/printf-15.asm b/src/test/ref/printf-15.asm index a401afe91..9434db8ae 100644 --- a/src/test/ref/printf-15.asm +++ b/src/test/ref/printf-15.asm @@ -133,10 +133,9 @@ clrscr: { cputs: { .label s = 2 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/printf-15.log b/src/test/ref/printf-15.log index bbeb69e7b..115cbcad8 100644 --- a/src/test/ref/printf-15.log +++ b/src/test/ref/printf-15.log @@ -292,9 +292,10 @@ cputs: scope:[cputs] from main::@1 main::@2 cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#3 ← phi( cputs/(to_nomodify byte*) cputs::s#4 cputs::@3/(to_nomodify byte*) cputs::s#5 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#3) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#3 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#6 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -510,7 +511,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -712,7 +714,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Successful SSA optimization PassNAddNumberTypeConversions Inlining cast (byte*) memcpy::src#0 ← (byte*)(void*) memcpy::source#2 Inlining cast (byte*) memcpy::dst#0 ← (byte*)(void*) memcpy::destination#2 @@ -825,7 +827,7 @@ Alias gotoxy::x#4 = gotoxy::x#5 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#4 = gotoxy::y#5 Alias cputc::c#1 = cputc::c#2 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#6 cputs::s#5 Successful SSA optimization Pass2AliasElimination Alias candidate removed (volatile)conio_line_text = gotoxy::$5 @@ -861,7 +863,7 @@ Simple Condition (bool~) cputc::$0 [66] if((byte) cputc::c#0==(byte) ' Simple Condition (bool~) cputc::$2 [72] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [82] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [84] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [118] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [118] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Successful SSA optimization Pass2ConditionalJumpSimplification Constant right-side identified [87] (word) memcpy::num#0 ← (unumber)(number) $19*(number) $28-(number) $28 Constant right-side identified [92] (word) memcpy::num#1 ← (unumber)(number) $19*(number) $28-(number) $28 @@ -3219,11 +3221,10 @@ cputs: { // [32] phi (to_nomodify byte*) cputs::s#3 = (to_nomodify byte*) cputs::s#4 [phi:cputs/cputs::@2->cputs::@1#0] -- register_copy // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [33] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#3) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [34] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#3 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/printf-16.asm b/src/test/ref/printf-16.asm index bd496490e..94b478a8f 100644 --- a/src/test/ref/printf-16.asm +++ b/src/test/ref/printf-16.asm @@ -373,10 +373,9 @@ cputc: { cputs: { .label s = 2 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/printf-16.log b/src/test/ref/printf-16.log index 6b0020b69..4ecafdf7f 100644 --- a/src/test/ref/printf-16.log +++ b/src/test/ref/printf-16.log @@ -569,9 +569,10 @@ cputs: scope:[cputs] from main::@10 main::@12 main::@14 main::@16 main::@18 mai cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#22 ← phi( cputs/(to_nomodify byte*) cputs::s#23 cputs::@3/(to_nomodify byte*) cputs::s#24 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#22) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#22 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#25 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -1354,7 +1355,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -2213,7 +2215,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 0 in *((byte*)&(struct printf_buffer_number) printf_buffer+(const byte) OFFSET_STRUCT_PRINTF_BUFFER_NUMBER_SIGN) ← (number) 0 Adding number conversion cast (snumber) 0 in (bool~) printf_sint::$0 ← (signed word) printf_sint::value#11 < (number) 0 Adding number conversion cast (unumber) 0 in (bool~) printf_sint::$5 ← (number) 0 != (byte) printf_sint::format_sign_always#10 @@ -2404,15 +2406,15 @@ Inversing boolean not [189] (bool~) gotoxy::$1 ← (byte) gotoxy::y#2 <= (byte) Inversing boolean not [193] (bool~) gotoxy::$3 ← (byte) gotoxy::x#2 < (byte) $28 from [192] (bool~) gotoxy::$2 ← (byte) gotoxy::x#2 >= (byte) $28 Inversing boolean not [219] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [218] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [230] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [229] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [294] (bool~) printf_sint::$3 ← (byte) 0 == (byte) printf_sint::format_sign_always#10 from [293] (bool~) printf_sint::$5 ← (byte) 0 != (byte) printf_sint::format_sign_always#10 -Inversing boolean not [318] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#1 from [317] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#1 -Inversing boolean not [322] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#1 from [321] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#1 -Inversing boolean not [324] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#1 from [323] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#1 -Inversing boolean not [337] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#1 from [336] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#1 -Inversing boolean not [344] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [343] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 -Inversing boolean not [352] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [351] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 -Inversing boolean not [369] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#1 from [368] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#1 -Inversing boolean not [381] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [380] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 +Inversing boolean not [295] (bool~) printf_sint::$3 ← (byte) 0 == (byte) printf_sint::format_sign_always#10 from [294] (bool~) printf_sint::$5 ← (byte) 0 != (byte) printf_sint::format_sign_always#10 +Inversing boolean not [319] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#1 from [318] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#1 +Inversing boolean not [323] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#1 from [322] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#1 +Inversing boolean not [325] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#1 from [324] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#1 +Inversing boolean not [338] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#1 from [337] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#1 +Inversing boolean not [345] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [344] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 +Inversing boolean not [353] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [352] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 +Inversing boolean not [370] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#1 from [369] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#1 +Inversing boolean not [382] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [381] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -2466,7 +2468,7 @@ Alias gotoxy::x#4 = gotoxy::x#5 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#4 = gotoxy::y#5 Alias cputc::c#13 = cputc::c#14 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#25 cputs::s#24 Alias printf_padding::pad#3 = printf_padding::pad#4 printf_padding::pad#6 Alias printf_padding::i#2 = printf_padding::i#4 printf_padding::i#3 @@ -2617,7 +2619,7 @@ Simple Condition (bool~) cputc::$0 [156] if((byte) cputc::c#13==(byte) ' Simple Condition (bool~) cputc::$2 [162] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [172] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [174] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [208] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [208] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) printf_padding::$0 [216] if((byte) printf_padding::i#2<(byte) printf_padding::length#4) goto printf_padding::@2 Simple Condition (bool~) printf_sint::$0 [224] if((signed word) printf_sint::value#11<(signed byte) 0) goto printf_sint::@1 Simple Condition (bool~) printf_sint::$3 [228] if((byte) 0==(byte) printf_sint::format_sign_always#10) goto printf_sint::@2 @@ -8700,11 +8702,10 @@ cputs: { // [119] phi (to_nomodify byte*) cputs::s#22 = (to_nomodify byte*) cputs::s#23 [phi:cputs/cputs::@2->cputs::@1#0] -- register_copy // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [120] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#22) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [121] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#22 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/printf-2.asm b/src/test/ref/printf-2.asm index 6dad0aa85..3455f8432 100644 --- a/src/test/ref/printf-2.asm +++ b/src/test/ref/printf-2.asm @@ -785,10 +785,9 @@ cputs: { lda #>printf_buffer+OFFSET_STRUCT_PRINTF_BUFFER_NUMBER_DIGITS sta.z s+1 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/printf-2.log b/src/test/ref/printf-2.log index 92f960649..e045fec3b 100644 --- a/src/test/ref/printf-2.log +++ b/src/test/ref/printf-2.log @@ -735,9 +735,10 @@ cputs: scope:[cputs] from printf_number_buffer::@5 cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#2 ← phi( cputs/(to_nomodify byte*) cputs::s#3 cputs::@3/(to_nomodify byte*) cputs::s#4 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#2) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#2 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#5 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -1403,7 +1404,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -2355,7 +2357,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 0 in (bool~) printf_uint::$5 ← (number) 0 != (byte) printf_uint::format_sign_always#1 Adding number conversion cast (unumber) printf_uint::$2 in (byte) printf_uint::format_upper_case#2 ← phi( printf_uint::@1/(byte) printf_uint::format_upper_case#3 printf_uint::@2/(byte) printf_uint::format_upper_case#4 ) (byte) printf_uint::format_zero_padding#2 ← phi( printf_uint::@1/(byte) printf_uint::format_zero_padding#3 printf_uint::@2/(byte) printf_uint::format_zero_padding#4 ) @@ -2629,15 +2631,15 @@ Inversing boolean not [269] (bool~) gotoxy::$1 ← (byte) gotoxy::y#2 <= (byte) Inversing boolean not [273] (bool~) gotoxy::$3 ← (byte) gotoxy::x#2 < (byte) $28 from [272] (bool~) gotoxy::$2 ← (byte) gotoxy::x#2 >= (byte) $28 Inversing boolean not [299] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [298] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [310] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [309] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [398] (bool~) printf_schar::$3 ← (byte) 0 == (byte) printf_schar::format_sign_always#2 from [397] (bool~) printf_schar::$5 ← (byte) 0 != (byte) printf_schar::format_sign_always#2 -Inversing boolean not [422] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#2 from [421] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#2 -Inversing boolean not [426] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#2 from [425] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#2 -Inversing boolean not [428] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#2 from [427] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#2 -Inversing boolean not [441] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [440] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 -Inversing boolean not [448] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [447] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 -Inversing boolean not [456] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#3 from [455] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#3 -Inversing boolean not [473] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#2 from [472] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#2 -Inversing boolean not [485] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#4 from [484] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#4 +Inversing boolean not [399] (bool~) printf_schar::$3 ← (byte) 0 == (byte) printf_schar::format_sign_always#2 from [398] (bool~) printf_schar::$5 ← (byte) 0 != (byte) printf_schar::format_sign_always#2 +Inversing boolean not [423] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#2 from [422] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#2 +Inversing boolean not [427] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#2 from [426] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#2 +Inversing boolean not [429] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#2 from [428] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#2 +Inversing boolean not [442] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [441] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 +Inversing boolean not [449] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [448] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 +Inversing boolean not [457] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#3 from [456] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#3 +Inversing boolean not [474] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#2 from [473] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#2 +Inversing boolean not [486] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#4 from [485] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#4 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -2707,7 +2709,7 @@ Alias gotoxy::x#4 = gotoxy::x#5 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#4 = gotoxy::y#5 Alias cputc::c#3 = cputc::c#4 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#5 cputs::s#4 Alias printf_padding::pad#3 = printf_padding::pad#4 printf_padding::pad#6 Alias printf_padding::i#2 = printf_padding::i#4 printf_padding::i#3 @@ -2901,7 +2903,7 @@ Simple Condition (bool~) cputc::$0 [217] if((byte) cputc::c#3==(byte) ' Simple Condition (bool~) cputc::$2 [223] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [233] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [235] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [269] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [269] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) printf_padding::$0 [277] if((byte) printf_padding::i#2<(byte) printf_padding::length#4) goto printf_padding::@2 Simple Condition (bool~) printf_uint::$5 [284] if((byte) 0!=(byte) printf_uint::format_sign_always#0) goto printf_uint::@1 Simple Condition (bool~) printf_schar::$0 [306] if((signed byte) printf_schar::value#3<(signed byte) 0) goto printf_schar::@1 @@ -10501,11 +10503,10 @@ cputs: { sta.z s+1 // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [208] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#2) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [209] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#2 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/printf-speed.asm b/src/test/ref/printf-speed.asm index 5284514a3..6c9aae7a6 100644 --- a/src/test/ref/printf-speed.asm +++ b/src/test/ref/printf-speed.asm @@ -332,10 +332,9 @@ tod_str: { cputs: { .label s = 4 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/printf-speed.log b/src/test/ref/printf-speed.log index ba888549d..cfdbc5923 100644 --- a/src/test/ref/printf-speed.log +++ b/src/test/ref/printf-speed.log @@ -508,9 +508,10 @@ cputs: scope:[cputs] from main::@4 main::@9 printf_number_buffer::@5 printf_str cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#5 ← phi( cputs/(to_nomodify byte*) cputs::s#6 cputs::@3/(to_nomodify byte*) cputs::s#7 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#5) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#5 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#8 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -1290,7 +1291,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -2198,7 +2200,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 0 in (bool~) printf_uint::$5 ← (number) 0 != (byte) printf_uint::format_sign_always#1 Adding number conversion cast (unumber) printf_uint::$2 in (byte) printf_uint::format_upper_case#2 ← phi( printf_uint::@1/(byte) printf_uint::format_upper_case#3 printf_uint::@2/(byte) printf_uint::format_upper_case#4 ) (byte) printf_uint::format_zero_padding#2 ← phi( printf_uint::@1/(byte) printf_uint::format_zero_padding#3 printf_uint::@2/(byte) printf_uint::format_zero_padding#4 ) @@ -2470,18 +2472,18 @@ Inversing boolean not [165] (bool~) gotoxy::$1 ← (byte) gotoxy::y#5 <= (byte) Inversing boolean not [169] (bool~) gotoxy::$3 ← (byte) gotoxy::x#5 < (byte) $28 from [168] (bool~) gotoxy::$2 ← (byte) gotoxy::x#5 >= (byte) $28 Inversing boolean not [195] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [194] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [206] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [205] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [287] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#1 from [286] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#1 -Inversing boolean not [291] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#1 from [290] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#1 -Inversing boolean not [293] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#1 from [292] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#1 -Inversing boolean not [306] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#1 from [305] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#1 -Inversing boolean not [313] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [312] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 -Inversing boolean not [321] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [320] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 -Inversing boolean not [338] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#1 from [337] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#1 -Inversing boolean not [350] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [349] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 -Inversing boolean not [368] (bool~) printf_string::$0 ← (byte) 0 == (byte) printf_string::format_min_length#1 from [367] (bool~) printf_string::$14 ← (byte) 0 != (byte) printf_string::format_min_length#1 -Inversing boolean not [372] (bool~) printf_string::$1 ← (byte) 0 == (byte) printf_string::format_justify_left#1 from [371] (bool~) printf_string::$15 ← (byte) 0 != (byte) printf_string::format_justify_left#1 -Inversing boolean not [387] (bool~) printf_string::$12 ← (signed byte) printf_string::padding#1 >= (signed byte) 0 from [386] (bool~) printf_string::$11 ← (signed byte) printf_string::padding#1 < (signed byte) 0 -Inversing boolean not [477] (bool~) main::$8 ← (byte~) main::$6 != (byte) 0 from [476] (bool~) main::$7 ← (byte~) main::$6 == (byte) 0 +Inversing boolean not [288] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#1 from [287] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#1 +Inversing boolean not [292] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#1 from [291] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#1 +Inversing boolean not [294] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#1 from [293] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#1 +Inversing boolean not [307] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#1 from [306] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#1 +Inversing boolean not [314] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [313] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 +Inversing boolean not [322] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [321] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 +Inversing boolean not [339] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#1 from [338] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#1 +Inversing boolean not [351] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [350] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 +Inversing boolean not [369] (bool~) printf_string::$0 ← (byte) 0 == (byte) printf_string::format_min_length#1 from [368] (bool~) printf_string::$14 ← (byte) 0 != (byte) printf_string::format_min_length#1 +Inversing boolean not [373] (bool~) printf_string::$1 ← (byte) 0 == (byte) printf_string::format_justify_left#1 from [372] (bool~) printf_string::$15 ← (byte) 0 != (byte) printf_string::format_justify_left#1 +Inversing boolean not [388] (bool~) printf_string::$12 ← (signed byte) printf_string::padding#1 >= (signed byte) 0 from [387] (bool~) printf_string::$11 ← (signed byte) printf_string::padding#1 < (signed byte) 0 +Inversing boolean not [478] (bool~) main::$8 ← (byte~) main::$6 != (byte) 0 from [477] (bool~) main::$7 ← (byte~) main::$6 == (byte) 0 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -2528,7 +2530,7 @@ Alias gotoxy::x#7 = gotoxy::x#8 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#7 = gotoxy::y#8 Alias cputc::c#3 = cputc::c#4 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#8 cputs::s#7 Alias printf_padding::pad#5 = printf_padding::pad#6 printf_padding::pad#8 Alias printf_padding::i#2 = printf_padding::i#4 printf_padding::i#3 @@ -2720,7 +2722,7 @@ Simple Condition (bool~) cputc::$0 [135] if((byte) cputc::c#3==(byte) ' Simple Condition (bool~) cputc::$2 [141] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [151] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [153] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [187] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [187] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) printf_padding::$0 [195] if((byte) printf_padding::i#2<(byte) printf_padding::length#6) goto printf_padding::@2 Simple Condition (bool~) printf_uint::$5 [202] if((byte) 0!=(byte) printf_uint::format_sign_always#0) goto printf_uint::@1 Simple Condition (bool~) printf_number_buffer::$0 [224] if((byte) 0==(byte) printf_number_buffer::format_min_length#0) goto printf_number_buffer::@1 @@ -8183,11 +8185,10 @@ cputs: { // [97] phi (to_nomodify byte*) cputs::s#5 = (to_nomodify byte*) cputs::s#6 [phi:cputs/cputs::@2->cputs::@1#0] -- register_copy // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [98] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#5) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [99] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#5 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/prng-xorshift.asm b/src/test/ref/prng-xorshift.asm index 82412d0c4..841066bf7 100644 --- a/src/test/ref/prng-xorshift.asm +++ b/src/test/ref/prng-xorshift.asm @@ -250,10 +250,9 @@ textcolor: { cputs: { .label s = $11 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/prng-xorshift.log b/src/test/ref/prng-xorshift.log index 57ecbed49..ebc783341 100644 --- a/src/test/ref/prng-xorshift.log +++ b/src/test/ref/prng-xorshift.log @@ -738,9 +738,10 @@ cputs: scope:[cputs] from main::@15 main::@8 printf_number_buffer::@5 cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#4 ← phi( cputs/(to_nomodify byte*) cputs::s#5 cputs::@3/(to_nomodify byte*) cputs::s#6 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#4) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#4 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#7 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -1596,7 +1597,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -2627,7 +2629,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 0 in (bool~) printf_ulong::$5 ← (number) 0 != (byte) printf_ulong::format_sign_always#1 Adding number conversion cast (unumber) printf_ulong::$2 in (byte) printf_ulong::format_upper_case#2 ← phi( printf_ulong::@1/(byte) printf_ulong::format_upper_case#3 printf_ulong::@2/(byte) printf_ulong::format_upper_case#4 ) (byte) printf_ulong::format_zero_padding#2 ← phi( printf_ulong::@1/(byte) printf_ulong::format_zero_padding#3 printf_ulong::@2/(byte) printf_ulong::format_zero_padding#4 ) @@ -2878,17 +2880,17 @@ Inversing boolean not [270] (bool~) gotoxy::$1 ← (byte) gotoxy::y#4 <= (byte) Inversing boolean not [274] (bool~) gotoxy::$3 ← (byte) gotoxy::x#4 < (byte) $28 from [273] (bool~) gotoxy::$2 ← (byte) gotoxy::x#4 >= (byte) $28 Inversing boolean not [300] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [299] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [311] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [310] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [423] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#2 from [422] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#2 -Inversing boolean not [427] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#2 from [426] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#2 -Inversing boolean not [429] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#2 from [428] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#2 -Inversing boolean not [442] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [441] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 -Inversing boolean not [449] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [448] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 -Inversing boolean not [457] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#3 from [456] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#3 -Inversing boolean not [474] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#2 from [473] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#2 -Inversing boolean not [486] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#4 from [485] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#4 -Inversing boolean not [529] (bool~) main::$8 ← (byte~) main::$17 != (byte) 0 from [528] (bool~) main::$7 ← (byte~) main::$17 == (byte) 0 -Inversing boolean not [556] (bool~) main::$12 ← (byte) main::row#1 != (byte) $19 from [555] (bool~) main::$11 ← (byte) main::row#1 == (byte) $19 -Inversing boolean not [562] (bool~) main::$14 ← (byte) main::col#1 <= (byte)(number) $28-(number) 5 from [561] (bool~) main::$13 ← (byte) main::col#1 > (byte)(number) $28-(number) 5 +Inversing boolean not [424] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#2 from [423] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#2 +Inversing boolean not [428] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#2 from [427] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#2 +Inversing boolean not [430] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#2 from [429] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#2 +Inversing boolean not [443] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [442] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 +Inversing boolean not [450] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [449] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 +Inversing boolean not [458] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#3 from [457] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#3 +Inversing boolean not [475] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#2 from [474] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#2 +Inversing boolean not [487] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#4 from [486] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#4 +Inversing boolean not [530] (bool~) main::$8 ← (byte~) main::$17 != (byte) 0 from [529] (bool~) main::$7 ← (byte~) main::$17 == (byte) 0 +Inversing boolean not [557] (bool~) main::$12 ← (byte) main::row#1 != (byte) $19 from [556] (bool~) main::$11 ← (byte) main::row#1 == (byte) $19 +Inversing boolean not [563] (bool~) main::$14 ← (byte) main::col#1 <= (byte)(number) $28-(number) 5 from [562] (bool~) main::$13 ← (byte) main::col#1 > (byte)(number) $28-(number) 5 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -2958,7 +2960,7 @@ Alias gotoxy::x#6 = gotoxy::x#7 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#6 = gotoxy::y#7 Alias cputc::c#3 = cputc::c#4 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#7 cputs::s#6 Alias textcolor::return#0 = textcolor::old#0 textcolor::return#4 textcolor::return#1 Alias printf_padding::pad#3 = printf_padding::pad#4 printf_padding::pad#6 @@ -3189,7 +3191,7 @@ Simple Condition (bool~) cputc::$0 [219] if((byte) cputc::c#3==(byte) ' Simple Condition (bool~) cputc::$2 [225] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [235] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [237] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [271] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [271] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) printf_padding::$0 [283] if((byte) printf_padding::i#2<(byte) printf_padding::length#4) goto printf_padding::@2 Simple Condition (bool~) printf_ulong::$5 [290] if((byte) 0!=(byte) printf_ulong::format_sign_always#0) goto printf_ulong::@1 Simple Condition (bool~) printf_uint::$5 [311] if((byte) 0!=(byte) printf_uint::format_sign_always#0) goto printf_uint::@1 @@ -10934,11 +10936,10 @@ cputs: { // [67] phi (to_nomodify byte*) cputs::s#4 = (to_nomodify byte*) cputs::s#5 [phi:cputs/cputs::@2->cputs::@1#0] -- register_copy // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [68] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#4) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [69] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#4 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/rand-1.asm b/src/test/ref/rand-1.asm index 0b93b5e4a..6ebb26d39 100644 --- a/src/test/ref/rand-1.asm +++ b/src/test/ref/rand-1.asm @@ -252,10 +252,9 @@ textcolor: { cputs: { .label s = $11 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/rand-1.log b/src/test/ref/rand-1.log index cfaf62189..cf9d299bf 100644 --- a/src/test/ref/rand-1.log +++ b/src/test/ref/rand-1.log @@ -757,9 +757,10 @@ cputs: scope:[cputs] from main::@16 main::@8 printf_number_buffer::@5 cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#4 ← phi( cputs/(to_nomodify byte*) cputs::s#5 cputs::@3/(to_nomodify byte*) cputs::s#6 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#4) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#4 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#7 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -1555,7 +1556,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -2642,7 +2644,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 0 in (bool~) printf_ulong::$5 ← (number) 0 != (byte) printf_ulong::format_sign_always#1 Adding number conversion cast (unumber) printf_ulong::$2 in (byte) printf_ulong::format_upper_case#2 ← phi( printf_ulong::@1/(byte) printf_ulong::format_upper_case#3 printf_ulong::@2/(byte) printf_ulong::format_upper_case#4 ) (byte) printf_ulong::format_zero_padding#2 ← phi( printf_ulong::@1/(byte) printf_ulong::format_zero_padding#3 printf_ulong::@2/(byte) printf_ulong::format_zero_padding#4 ) @@ -2890,17 +2892,17 @@ Inversing boolean not [282] (bool~) gotoxy::$1 ← (byte) gotoxy::y#4 <= (byte) Inversing boolean not [286] (bool~) gotoxy::$3 ← (byte) gotoxy::x#4 < (byte) $28 from [285] (bool~) gotoxy::$2 ← (byte) gotoxy::x#4 >= (byte) $28 Inversing boolean not [312] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [311] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [323] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [322] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [435] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#2 from [434] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#2 -Inversing boolean not [439] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#2 from [438] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#2 -Inversing boolean not [441] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#2 from [440] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#2 -Inversing boolean not [454] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [453] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 -Inversing boolean not [461] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [460] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 -Inversing boolean not [469] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#3 from [468] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#3 -Inversing boolean not [486] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#2 from [485] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#2 -Inversing boolean not [498] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#4 from [497] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#4 -Inversing boolean not [541] (bool~) main::$9 ← (byte~) main::$18 != (byte) 0 from [540] (bool~) main::$8 ← (byte~) main::$18 == (byte) 0 -Inversing boolean not [568] (bool~) main::$13 ← (byte) main::row#1 != (byte) $19 from [567] (bool~) main::$12 ← (byte) main::row#1 == (byte) $19 -Inversing boolean not [574] (bool~) main::$15 ← (byte) main::col#1 <= (byte)(number) $28-(number) 5 from [573] (bool~) main::$14 ← (byte) main::col#1 > (byte)(number) $28-(number) 5 +Inversing boolean not [436] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#2 from [435] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#2 +Inversing boolean not [440] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#2 from [439] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#2 +Inversing boolean not [442] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#2 from [441] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#2 +Inversing boolean not [455] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [454] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 +Inversing boolean not [462] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [461] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 +Inversing boolean not [470] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#3 from [469] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#3 +Inversing boolean not [487] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#2 from [486] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#2 +Inversing boolean not [499] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#4 from [498] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#4 +Inversing boolean not [542] (bool~) main::$9 ← (byte~) main::$18 != (byte) 0 from [541] (bool~) main::$8 ← (byte~) main::$18 == (byte) 0 +Inversing boolean not [569] (bool~) main::$13 ← (byte) main::row#1 != (byte) $19 from [568] (bool~) main::$12 ← (byte) main::row#1 == (byte) $19 +Inversing boolean not [575] (bool~) main::$15 ← (byte) main::col#1 <= (byte)(number) $28-(number) 5 from [574] (bool~) main::$14 ← (byte) main::col#1 > (byte)(number) $28-(number) 5 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -2972,7 +2974,7 @@ Alias gotoxy::x#6 = gotoxy::x#7 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#6 = gotoxy::y#7 Alias cputc::c#3 = cputc::c#4 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#7 cputs::s#6 Alias textcolor::return#0 = textcolor::old#0 textcolor::return#5 textcolor::return#1 Alias printf_padding::pad#3 = printf_padding::pad#4 printf_padding::pad#6 @@ -3201,7 +3203,7 @@ Simple Condition (bool~) cputc::$0 [228] if((byte) cputc::c#3==(byte) ' Simple Condition (bool~) cputc::$2 [234] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [244] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [246] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [280] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [280] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) printf_padding::$0 [292] if((byte) printf_padding::i#2<(byte) printf_padding::length#4) goto printf_padding::@2 Simple Condition (bool~) printf_ulong::$5 [299] if((byte) 0!=(byte) printf_ulong::format_sign_always#0) goto printf_ulong::@1 Simple Condition (bool~) printf_uint::$5 [320] if((byte) 0!=(byte) printf_uint::format_sign_always#0) goto printf_uint::@1 @@ -10994,11 +10996,10 @@ cputs: { // [69] phi (to_nomodify byte*) cputs::s#4 = (to_nomodify byte*) cputs::s#5 [phi:cputs/cputs::@2->cputs::@1#0] -- register_copy // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [70] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#4) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [71] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#4 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/sandbox.asm b/src/test/ref/sandbox.asm index b50bcefc6..cb53df16f 100644 --- a/src/test/ref/sandbox.asm +++ b/src/test/ref/sandbox.asm @@ -11,12 +11,12 @@ .label TIMELO = $a2 .label VICBANK = $d018 main: { - .label __4 = 6 - .label __13 = 6 - .label __18 = 6 - .label __19 = $11 - .label __20 = 6 - .label __21 = $f + .label __3 = 6 + .label __10 = 6 + .label __14 = 6 + .label __15 = $11 + .label __16 = 6 + .label __17 = $f .label v = 4 // test performance of 'div16u(10)' // test performance of 'div10' @@ -67,25 +67,25 @@ main: { bcc __b10 // (word)*TIMEHI << 8 lda TIMEHI - sta.z __20 + sta.z __16 lda #0 - sta.z __20+1 - lda.z __13 - sta.z __13+1 + sta.z __16+1 + lda.z __10 + sta.z __10+1 lda #0 - sta.z __13 + sta.z __10 // ((word)*TIMEHI << 8) + (word)*TIMELO lda TIMELO - sta.z __21 + sta.z __17 lda #0 - sta.z __21+1 + sta.z __17+1 // myprintf(strTemp, "200 DIV10 : %5d,%4d IN %04d FRAMESm", u, v, ((word)*TIMEHI << 8) + (word)*TIMELO) lda.z myprintf.w3 clc - adc.z __21 + adc.z __17 sta.z myprintf.w3 lda.z myprintf.w3+1 - adc.z __21+1 + adc.z __17+1 sta.z myprintf.w3+1 lda #= (byte) $28 Inversing boolean not [299] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [298] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [310] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [309] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [415] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#2 from [414] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#2 -Inversing boolean not [419] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#2 from [418] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#2 -Inversing boolean not [421] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#2 from [420] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#2 -Inversing boolean not [434] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [433] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 -Inversing boolean not [441] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [440] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 -Inversing boolean not [449] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#3 from [448] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#3 -Inversing boolean not [466] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#2 from [465] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#2 -Inversing boolean not [478] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#4 from [477] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#4 +Inversing boolean not [416] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#2 from [415] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#2 +Inversing boolean not [420] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#2 from [419] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#2 +Inversing boolean not [422] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#2 from [421] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#2 +Inversing boolean not [435] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [434] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 +Inversing boolean not [442] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [441] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 +Inversing boolean not [450] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#3 from [449] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#3 +Inversing boolean not [467] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#2 from [466] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#2 +Inversing boolean not [479] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#4 from [478] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#4 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -2705,7 +2707,7 @@ Alias gotoxy::x#4 = gotoxy::x#5 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#4 = gotoxy::y#5 Alias cputc::c#3 = cputc::c#4 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#8 cputs::s#7 Alias printf_padding::pad#3 = printf_padding::pad#4 printf_padding::pad#6 Alias printf_padding::i#2 = printf_padding::i#4 printf_padding::i#3 @@ -2900,7 +2902,7 @@ Simple Condition (bool~) cputc::$0 [217] if((byte) cputc::c#3==(byte) ' Simple Condition (bool~) cputc::$2 [223] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [233] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [235] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [269] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [269] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) printf_padding::$0 [277] if((byte) printf_padding::i#2<(byte) printf_padding::length#4) goto printf_padding::@2 Simple Condition (bool~) printf_uint::$5 [284] if((byte) 0!=(byte) printf_uint::format_sign_always#0) goto printf_uint::@1 Simple Condition (bool~) printf_uchar::$5 [305] if((byte) 0!=(byte) printf_uchar::format_sign_always#2) goto printf_uchar::@1 @@ -9322,11 +9324,10 @@ cputs: { // [51] phi (to_nomodify byte*) cputs::s#5 = (to_nomodify byte*) cputs::s#6 [phi:cputs/cputs::@2->cputs::@1#0] -- register_copy // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [52] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#5) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [53] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#5 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/stars-2.asm b/src/test/ref/stars-2.asm index 5d1c7213f..e0a22dfb4 100644 --- a/src/test/ref/stars-2.asm +++ b/src/test/ref/stars-2.asm @@ -172,10 +172,9 @@ printf_uchar: { cputs: { .label s = 3 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/stars-2.log b/src/test/ref/stars-2.log index 39aaa1595..d16a0550e 100644 --- a/src/test/ref/stars-2.log +++ b/src/test/ref/stars-2.log @@ -556,9 +556,10 @@ cputs: scope:[cputs] from main::@4 main::@6 printf_number_buffer::@5 cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#4 ← phi( cputs/(to_nomodify byte*) cputs::s#5 cputs::@3/(to_nomodify byte*) cputs::s#6 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#4) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#4 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#7 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -1144,7 +1145,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -1872,7 +1874,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) 0 in (bool~) printf_uchar::$5 ← (number) 0 != (byte) printf_uchar::format_sign_always#2 Adding number conversion cast (unumber) printf_uchar::$2 in (byte) printf_uchar::format_upper_case#3 ← phi( printf_uchar::@1/(byte) printf_uchar::format_upper_case#4 printf_uchar::@2/(byte) printf_uchar::format_upper_case#5 ) (byte) printf_uchar::format_zero_padding#3 ← phi( printf_uchar::@1/(byte) printf_uchar::format_zero_padding#4 printf_uchar::@2/(byte) printf_uchar::format_zero_padding#5 ) @@ -2043,14 +2045,14 @@ Inversing boolean not [188] (bool~) gotoxy::$1 ← (byte) gotoxy::y#2 <= (byte) Inversing boolean not [192] (bool~) gotoxy::$3 ← (byte) gotoxy::x#2 < (byte) $28 from [191] (bool~) gotoxy::$2 ← (byte) gotoxy::x#2 >= (byte) $28 Inversing boolean not [218] (bool~) cputc::$2 ← (byte) conio_cursor_x != (byte) $28 from [217] (bool~) cputc::$1 ← (byte) conio_cursor_x == (byte) $28 Inversing boolean not [229] (bool~) cscroll::$1 ← (byte) conio_cursor_y != (byte) $19 from [228] (bool~) cscroll::$0 ← (byte) conio_cursor_y == (byte) $19 -Inversing boolean not [310] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#1 from [309] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#1 -Inversing boolean not [314] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#1 from [313] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#1 -Inversing boolean not [316] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#1 from [315] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#1 -Inversing boolean not [329] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#1 from [328] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#1 -Inversing boolean not [336] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [335] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 -Inversing boolean not [344] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [343] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 -Inversing boolean not [361] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#1 from [360] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#1 -Inversing boolean not [373] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [372] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 +Inversing boolean not [311] (bool~) printf_number_buffer::$0 ← (byte) 0 == (byte) printf_number_buffer::format_min_length#1 from [310] (bool~) printf_number_buffer::$26 ← (byte) 0 != (byte) printf_number_buffer::format_min_length#1 +Inversing boolean not [315] (bool~) printf_number_buffer::$1 ← (byte) 0 == (byte) printf_number_buffer::format_justify_left#1 from [314] (bool~) printf_number_buffer::$27 ← (byte) 0 != (byte) printf_number_buffer::format_justify_left#1 +Inversing boolean not [317] (bool~) printf_number_buffer::$2 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#1 from [316] (bool~) printf_number_buffer::$28 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#1 +Inversing boolean not [330] (bool~) printf_number_buffer::$20 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#1 from [329] (bool~) printf_number_buffer::$29 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#1 +Inversing boolean not [337] (bool~) printf_number_buffer::$23 ← (signed byte) printf_number_buffer::padding#1 >= (signed byte) 0 from [336] (bool~) printf_number_buffer::$22 ← (signed byte) printf_number_buffer::padding#1 < (signed byte) 0 +Inversing boolean not [345] (bool~) printf_number_buffer::$7 ← (byte) 0 == (byte) printf_number_buffer::buffer_sign#2 from [344] (bool~) printf_number_buffer::$30 ← (byte) 0 != (byte) printf_number_buffer::buffer_sign#2 +Inversing boolean not [362] (bool~) printf_number_buffer::$12 ← (byte) 0 == (byte) printf_number_buffer::format_upper_case#1 from [361] (bool~) printf_number_buffer::$31 ← (byte) 0 != (byte) printf_number_buffer::format_upper_case#1 +Inversing boolean not [374] (bool~) printf_number_buffer::$14 ← (byte) 0 == (byte) printf_number_buffer::format_zero_padding#3 from [373] (bool~) printf_number_buffer::$32 ← (byte) 0 != (byte) printf_number_buffer::format_zero_padding#3 Successful SSA optimization Pass2UnaryNotSimplification Alias candidate removed (volatile)conio_line_text = gotoxy::$5 Alias candidate removed (volatile)conio_line_color = gotoxy::$6 @@ -2104,7 +2106,7 @@ Alias gotoxy::x#4 = gotoxy::x#5 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#4 = gotoxy::y#5 Alias cputc::c#3 = cputc::c#4 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#7 cputs::s#6 Alias printf_padding::pad#3 = printf_padding::pad#4 printf_padding::pad#6 Alias printf_padding::i#2 = printf_padding::i#4 printf_padding::i#3 @@ -2256,7 +2258,7 @@ Simple Condition (bool~) cputc::$0 [154] if((byte) cputc::c#3==(byte) ' Simple Condition (bool~) cputc::$2 [160] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [170] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [172] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [206] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [206] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) printf_padding::$0 [214] if((byte) printf_padding::i#2<(byte) printf_padding::length#4) goto printf_padding::@2 Simple Condition (bool~) printf_uchar::$5 [221] if((byte) 0!=(byte) printf_uchar::format_sign_always#2) goto printf_uchar::@1 Simple Condition (bool~) printf_number_buffer::$0 [243] if((byte) 0==(byte) printf_number_buffer::format_min_length#0) goto printf_number_buffer::@1 @@ -6238,11 +6240,10 @@ cputs: { // [46] phi (to_nomodify byte*) cputs::s#4 = (to_nomodify byte*) cputs::s#5 [phi:cputs/cputs::@2->cputs::@1#0] -- register_copy // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [47] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#4) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [48] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#4 -- pbuz1=_inc_pbuz1 inc.z s bne !+ diff --git a/src/test/ref/tod-1.asm b/src/test/ref/tod-1.asm index 6c7c82207..dcf8875b0 100644 --- a/src/test/ref/tod-1.asm +++ b/src/test/ref/tod-1.asm @@ -241,10 +241,9 @@ cputs: { lda #>tod_buffer sta.z s+1 __b1: - // c=*s++ + // while(c=*s++) ldy #0 lda (s),y - // while(c=*s++) inc.z s bne !+ inc.z s+1 diff --git a/src/test/ref/tod-1.log b/src/test/ref/tod-1.log index d38ac2243..3ebe7c072 100644 --- a/src/test/ref/tod-1.log +++ b/src/test/ref/tod-1.log @@ -234,9 +234,10 @@ cputs: scope:[cputs] from main::@6 cputs::@1: scope:[cputs] from cputs cputs::@3 (to_nomodify byte*) cputs::s#2 ← phi( cputs/(to_nomodify byte*) cputs::s#3 cputs::@3/(to_nomodify byte*) cputs::s#4 ) (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#2) + (byte~) cputs::$0 ← (byte) cputs::c#1 (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#2 - (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 - if((bool~) cputs::$1) goto cputs::@2 + (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 + if((bool~) cputs::$2) goto cputs::@2 to:cputs::@return cputs::@2: scope:[cputs] from cputs::@1 (to_nomodify byte*) cputs::s#5 ← phi( cputs::@1/(to_nomodify byte*) cputs::s#0 ) @@ -545,7 +546,8 @@ SYMBOL TABLE SSA (label) cputln::@1 (label) cputln::@return (void()) cputs((to_nomodify byte*) cputs::s) -(bool~) cputs::$1 +(byte~) cputs::$0 +(bool~) cputs::$2 (label) cputs::@1 (label) cputs::@2 (label) cputs::@3 @@ -836,7 +838,7 @@ Adding number conversion cast (unumber) $28 in (byte*) conio_line_text ← (byte Adding number conversion cast (unumber) $28 in (byte*) conio_line_color ← (byte*) conio_line_color - (number) $28 Adding number conversion cast (unumber) 0 in (byte) gotoxy::x#1 ← (number) 0 Adding number conversion cast (unumber) 0 in (byte) gotoxy::y#1 ← (number) 0 -Adding number conversion cast (unumber) 0 in (bool~) cputs::$1 ← (number) 0 != (byte) cputs::c#1 +Adding number conversion cast (unumber) 0 in (bool~) cputs::$2 ← (number) 0 != (byte~) cputs::$0 Adding number conversion cast (unumber) $80 in *((byte*)(const nomodify struct MOS6526_CIA*) CIA1+(const byte) OFFSET_STRUCT_MOS6526_CIA_TIMER_A_CONTROL) ← *((byte*)(const nomodify struct MOS6526_CIA*) CIA1+(const byte) OFFSET_STRUCT_MOS6526_CIA_TIMER_A_CONTROL) | (number) $80 Adding number conversion cast (unumber) $7f in *((byte*)(const nomodify struct MOS6526_CIA*) CIA1+(const byte) OFFSET_STRUCT_MOS6526_CIA_TIMER_B_CONTROL) ← *((byte*)(const nomodify struct MOS6526_CIA*) CIA1+(const byte) OFFSET_STRUCT_MOS6526_CIA_TIMER_B_CONTROL) & (number) $7f Adding number conversion cast (unumber) 4 in (byte~) tod_str::$0 ← (byte) tod_str::tod_HOURS#1 >> (number) 4 @@ -1007,7 +1009,7 @@ Alias gotoxy::x#5 = gotoxy::x#6 Alias gotoxy::line_offset#0 = gotoxy::$4 Alias gotoxy::y#5 = gotoxy::y#6 Alias cputc::c#1 = cputc::c#2 -Alias cputs::c#1 = cputs::c#2 +Alias cputs::c#1 = cputs::$0 cputs::c#2 Alias cputs::s#0 = cputs::s#5 cputs::s#4 Alias tod_read::return_TENTHS#0 = tod_read::tod_TENTHS#0 tod_read::tenths#0 tod_read::return_TENTHS#3 tod_read::return_TENTHS#1 Alias tod_read::return_SEC#0 = tod_read::tod_SEC#0 tod_read::secs#0 tod_read::return_SEC#3 tod_read::return_SEC#1 @@ -1060,7 +1062,7 @@ Simple Condition (bool~) cputc::$0 [45] if((byte) cputc::c#0==(byte) ' Simple Condition (bool~) cputc::$2 [51] if((byte) conio_cursor_x!=(byte) $28) goto cputc::@return Simple Condition (bool~) cscroll::$1 [61] if((byte) conio_cursor_y!=(byte) $19) goto cscroll::@return Simple Condition (bool~) cscroll::$7 [63] if((byte) 0!=(byte) conio_scroll_enable) goto cscroll::@3 -Simple Condition (bool~) cputs::$1 [97] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 +Simple Condition (bool~) cputs::$2 [97] if((byte) 0!=(byte) cputs::c#1) goto cputs::@2 Simple Condition (bool~) main::$5 [149] if((number) 0!=(number) 1) goto main::@2 Successful SSA optimization Pass2ConditionalJumpSimplification Constant right-side identified [66] (word) memcpy::num#0 ← (unumber)(number) $19*(number) $28-(number) $28 @@ -4259,11 +4261,10 @@ cputs: { sta.z s+1 // cputs::@1 __b1: - // c=*s++ + // while(c=*s++) // [73] (byte) cputs::c#1 ← *((to_nomodify byte*) cputs::s#2) -- vbuaa=_deref_pbuz1 ldy #0 lda (s),y - // while(c=*s++) // [74] (to_nomodify byte*) cputs::s#0 ← ++ (to_nomodify byte*) cputs::s#2 -- pbuz1=_inc_pbuz1 inc.z s bne !+