https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92395

--- Comment #1 from Vincent Riviere <vincent.riviere at freesbee dot fr> ---
Simplified testcase :

void f(char *begin, char *end)
{
    do
    {
        *end-- = 0;
    }
    while (end > begin);
}

Note that that the above code only manipulate pointers. No int type is
involved. Save it as a.c.

I use the official Ubuntu 19.10 Eoan Ermine.
m68k-linux-gnu-gcc --version
m68k-linux-gnu-gcc (Ubuntu 9.2.1-9ubuntu1) 9.2.1 20191008

m68k-linux-gnu-gcc -S -O2 -fomit-frame-pointer a.c -o -

f:
    move.l 4(%sp),%d0
    move.l 8(%sp),%a0
.L2:
    clr.b (%a0)
    subq.l #1,%a0
    cmp.l %d0,%a0
    jhi .L2
    rts

That's fine.

Now the same but with -mshort:

m68k-linux-gnu-gcc -mshort -S -O2 -fomit-frame-pointer a.c -o -

f:
    move.l 4(%sp),%d1
    move.l 8(%sp),%a0
.L2:
    clr.b (%a0)
    move.l %a0,%d0
    subq.l #1,%d0
    add.l #65535,%a0  // Madness
    cmp.l %d1,%d0
    jhi .L2
    rts

The  latter is wrong.

Reply via email to