From e6b9a4b2924f6e2bbb5f6e1c62e8c2e5cc7423e8 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sun, 8 May 2022 13:19:32 +0200 Subject: [PATCH] test related to issue #1652, shows regression broken by #1231 and the case that #1231 improved. --- test/val/bug1652-optimizer.c | 122 +++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 test/val/bug1652-optimizer.c diff --git a/test/val/bug1652-optimizer.c b/test/val/bug1652-optimizer.c new file mode 100644 index 000000000..7926ef770 --- /dev/null +++ b/test/val/bug1652-optimizer.c @@ -0,0 +1,122 @@ + +/* #1652 - Regression in code optimization */ + +#include + +/* better before pr#1231 + +before: + + jsr pusha + ldy #$01 + ldx #$00 + lda (sp),y + beq L0005 + lda (sp,x) + beq L0005 + txa + jmp incsp2 ; <-- +L0005: tya + jmp incsp2 + +after: + + jsr pusha + ldy #$01 + ldx #$00 + lda (sp),y + beq L0004 + lda (sp,x) + beq L0004 + txa + jmp L0001 ; <-- +L0004: tya +L0001: jmp incsp2 + +*/ + +int foo(unsigned char bar, unsigned char baz) +{ + return (bar == 0 || baz == 0); +} + +/* worse before pr#1231 + +before: +; +; y = 1; +; + lda #$01 + sta _y +; +; (*tablePtr)[y][x] = 83; +; + ldx #$00 + lda _y + jsr aslax2 + clc + adc _tablePtr + pha + txa + adc _tablePtr+1 + tax + pla + clc + adc _x + bcc L0019 + inx +L0019: + sta ptr1 + stx ptr1+1 + lda #$53 + ldy #$00 + sta (ptr1),y + +after: + +; +; y = 1; +; + lda #$01 + sta _y +; +; (*tablePtr)[y][x] = 83; +; + ldx #$00 + lda _y + jsr aslax2 + clc + adc _tablePtr + sta ptr1 + txa + adc _tablePtr+1 + sta ptr1+1 + ldy _x + lda #$53 + sta (ptr1),y +*/ + +typedef unsigned char array_t[4][4]; + +static array_t table = { + {12, 13, 14, 15}, + { 8, 9, 10, 11}, + { 4, 5, 6, 7}, + { 0, 1, 2, 3} +}; +static array_t *tablePtr = &table; + +static unsigned char y = 0, x; + +void pointed_array(void) +{ + x = 3; + y = 1; + (*tablePtr)[y][x] = 83; +} + +int main(void) +{ + pointed_array(); + return foo(2, 0) ? EXIT_SUCCESS : EXIT_FAILURE; +}