cc65: cc65: Regression in code optimization
The following code is missing an optimization when compiled with the current cc65 version compared to 2.19:
int foo(unsigned char bar, unsigned char baz)
{
return (bar == 0 || baz == 0);
}
This is what cc65 2.19 generates with -Oirs:
jsr pusha
ldy #$01
ldx #$00
lda (sp),y
beq L0005
lda (sp,x)
beq L0005
txa
jmp incsp2 ; <--
L0005: tya
jmp incsp2
And this is what the current version generates:
jsr pusha
ldy #$01
ldx #$00
lda (sp),y
beq L0004
lda (sp,x)
beq L0004
txa
jmp L0001 ; <--
L0004: tya
L0001: jmp incsp2
The pattern is quite common. It is mostly a speed optimization but there are also cases in which the final jump can be removed, in which case it does also shrink the size of the generated code.
Let me know if you need more information.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (12 by maintainers)
Commits related to this issue
- test related to issue #1652, shows regression broken by #1231 and the case that #1231 improved. — committed to cc65/cc65 by mrdudz 2 years ago
- At the end of the optimizer run, remove jump cascades again. fixes the regression reported in #1652 — committed to cc65/cc65 by mrdudz 2 years ago
- test related to issue #1652, shows regression broken by #1231 and the case that #1231 improved. — committed to mrdudz/cc65 by mrdudz 2 years ago
- At the end of the optimizer run, remove jump cascades again. fixes the regression reported in #1652 — committed to mrdudz/cc65 by mrdudz 2 years ago
Easy. I looked at the generated code.
sim65 is able to count cycles. So for each test program in your nightly tests, record the number of total cycles it needs to run. Then, flag the test result for manual review if the number of cycles increases. If it decreases, use this number as the new nominal value. Needs some work but technically itโs quite easy.