https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126136
Bug ID: 126136
Summary: m68k: Wrong code for conditional value selection
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: kristerw at gcc dot gnu.org
Blocks: 118443
Target Milestone: ---
Target: m68k-elf
The following function is miscompiled for m68k with -Os:
int i;
char foo(char val)
{
i++;
if (i > 1)
return -1;
else
return val;
}
The generated code is:
foo:
move.l i,%d0
addq.l #1,%d0
move.l %d0,i
moveq #1,%d1
cmp.l %d0,%d1
sge %d0
or.b 7(%sp),%d0
rts
The comparison is inverted:
sge %d0
I.e., it looks like this is a copy-paste error from the case with `and` instead
of `or`, which is handled correctly:
int i;
char foo2(char val)
{
i++;
if (i > 1)
return 0;
else
return val;
}
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118443
[Bug 118443] [Meta bug] Bugs triggered by and blocking more smtgcc testing