The following fragment when compiled -O -ffinite-math-only on arm-linux-gnueabi
should print 0.000000 but with gcc-4.1.2, 4.2.4, 4.3.3 it prints 99999.000000
#include <stdio.h>
#define test_min(x,y) ((x) > (y) ? (y) : (x))
int
main (void)
{
static float data [1];
float min = 99999.0 ;
min = test_min (min, data[0]) ;
printf("min = %f\n", min);
return min != 0.0 ;
}
This only happens for floats, not doubles. The main difference in the asm is
that without -ffinite-math-only (working) it goes
mov r0, r4
ldr r1, .L6+4
bl __aeabi_fcmplt
cmp r0, #0
ldr r3, .L6+4
moveq r4, r3
mov r0, r4
while with -ffinite-math-only (broken) it goes
ldr r5, .L5+4
mov r0, r4
mov r1, r5
bl __aeabi_fcmple
cmp r0, #0
movgt r4, r5
mov r0, r4
I guess that should be moveq.
This makes libvorbis fail on arm-linux-gnueabi when using softfloat.
See https://trac.xiph.org/ticket/1526 for a longer code example failing on
min() and max().
--
Summary: -O -ffinite-math-only gets min(x,y) optimization wrong
for SF on arm-*-gnueabi
Product: gcc
Version: 4.3.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: martinwguy at yahoo dot it
GCC target triplet: arm-linux-gnueabi
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39501