Menu

#3758 Bad optimization of condition handling

closed-works-for-me
None
MCS51
5
2024-07-13
2024-07-11
No

Bad optimization of condition handling.

    for(;;) {
        __bit t;
        //EA=0;
        t=(timer==0);
        //EA=1;
        if(t) break;
    }

translate to

00104$:
;   main.c:8: t=(timer==0);
    mov a,_timer
    orl a,(_timer + 1)
    cjne    a,#0x01,00114$
00114$:
;   main.c:10: if(t) break;
    mov _main_t_30000_4,c
    jnc 00104$

Why isn't jnz used?

Discussion

  • Dmitry Kharitonov

    sdcc -v

    SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/sm83/tlcs90/ez80_z80/z80n/r800/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502/mos65c02 TD- 4.4.0 #14620 (MINGW64)
    published under GNU General Public License (GPL)
    
     
  • Maarten Brock

    Maarten Brock - 2024-07-13
    • status: open --> closed-works-for-me
    • assigned_to: Maarten Brock
    • Category: other --> MCS51
     
  • Maarten Brock

    Maarten Brock - 2024-07-13

    Sub-optimal code generation is not a bug. File this as a feature request next time, please.
    Further, I cannot reproduce this with version 4.4.2 #14916

     

Log in to post a comment.