[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#198172: [arm] gcc-3.3 miscompile pari with -O3



On Wed, Jun 25, 2003 at 09:27:33AM +0100, Philip Blundell wrote:
> On Thu, 2003-06-19 at 16:26, Bill Allombert wrote:
> > Package: gcc-3.3
> > Version: 1:3.3-3
> > Severity: normal
> > 
> > Dear GCC maintainers,
> > 
> > gcc 3.3 (1:3.3ds9-3) miscompile pari (2.1.5) on arm with -O3, whereas
> > gcc 3.2 (3.2.3 20030331) worked fine.
> > 
> > With -O2 gcc 3.3 works fine also
> > 
> > The preprocessed miscompiled file is available at
> > http://people.debian.org/~ballombe/misc/init.i.gz
> 
> Thanks for your report.  Can you give any details of the miscompilation?

Well, it look like return statement are uncorrectly optimised with -O3:

The following file exhibit the problem:

----test.c--------
typedef long *GEN;
#define typ(x)  ((((long)(x))&1)? 0: (((unsigned long) ((GEN) (x))[0]) >> 24))

GEN powrealraw(GEN x, long n);
GEN
powraw(GEN x, long n)
{
  if (typ(x)==16)
    return powrealraw(x,n);
  else
    return powrealraw(x,n);
}
------------------

Using a intermediary variable work around the problem:
GEN z=(typ(x)==16)? powrealraw(x,n): powrealraw(x,n);
return z;

Above is the diff of the asm file: 
-O2 test2.S
-O3 test.S

--- test2.S     2003-06-25 20:05:52.000000000 +0000
+++ test.S      2003-06-25 20:05:41.000000000 +0000
@@ -12,8 +12,8 @@
        mov     r2, r0
        mov     ip, r1
        bne     .L2
-       ldrb    r3, [r0, #3]    @ zero_extendqisi2
-       cmp     r3, #16
+       ldrb    lr, [r0, #3]    @ zero_extendqisi2
+       cmp     lr, #16
        beq     .L4
 .L2:
        mov     r0, r2

Here the supposed buggy test.S:
--test.S-------------------------
        .file   "test.c"
        .text
        .align  2
        .global powraw
        .type   powraw, %function
powraw:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 0, uses_anonymous_args = 0
        @ link register save eliminated.
        tst     r0, #1
        @ lr needed for prologue
        mov     r2, r0
        mov     ip, r1
        bne     .L2
        ldrb    lr, [r0, #3]    @ zero_extendqisi2
        cmp     lr, #16
        beq     .L4
.L2:
        mov     r0, r2
        mov     r1, ip
.L4:
        b       powrealraw
        .size   powraw, .-powraw
        .ident  "GCC: (GNU) 3.3 (Debian)"
------------------------------

A wild guess : '@ lr needed for prologue'
mean that lr must not be clobbered but 
'ldrb lr, [r0, #3]' clobber it (??)

Cheers,
-- 
Bill. <ballombe@debian.org>

Imagine a large red swirl here. 



Reply to: