Problem with optimisation in ARM code

Luke Diamand lgd@virata.com
Tue Nov 3 06:07:00 GMT 1998


Hi!

We have the following snippet of code:

typedef unsigned int U32;

void pdma(volatile U32 *a, U32 *b, U32 n)
{
   volatile U32 *addr = (volatile U32 *)((int)a + (int)b);

   if(n == 13) {
     asm ("stmia %0,{r0-r12}"
                   : /* no outputs */
                   : "r" (addr));
   }
}

When we compile saying:
% gcc -S -mapcs-32 foo.c 

we get sensible looking assembler. 

But when we add -O2 we get the following:
_pdma:
        @ args = 0, pretend = 0, frame = 0
        @ frame_needed = 1, current_function_anonymous_args = 0
        mov     ip, sp
        stmfd   sp!, {fp, ip, lr, pc}
        add     r0, r0, r1
        cmp     r2, #13
        sub     fp, ip, #4
        stmia r0,{r0-r12}
        ldmea   fp, {fp, sp, pc}

In other words, it seems to do the 'stmia' regardless of the value of
'n'. 
This is with egcs-2.91.57 19980901 (egcs-1.1 release), configured for
linux i686 host and arm-aout target. We get similar results with gcc
2.7.2.

Hints as to where to start looking would be gratefully received!

Luke Diamand
-- 
Virata http://www.virata.com
Cambridge
Tel: +44 1223 566919      Fax: +44 1223 566915



More information about the Gcc-bugs mailing list