Auto increment in simple loops in gcc-4.2.0

"Tal Agmon" <Tal.Agmon@ceva-dsp.com>
Tue, 24 Jul 2007 19:57:31 +0300

          From comp.compilers

Related articles
Auto increment in simple loops in gcc-4.2.0 Tal.Agmon@ceva-dsp.com (Tal Agmon) (2007-07-24)
| List of all articles for this month |

From: "Tal Agmon" <Tal.Agmon@ceva-dsp.com>
Newsgroups: comp.compilers
Date: Tue, 24 Jul 2007 19:57:31 +0300
Organization: Compilers Central
Keywords: GCC, code, question
Posted-Date: 26 Jul 2007 00:58:22 EDT

Hi,


I'm writing a new port for gcc-4.2.0, I know it makes more sense to send
it to gcc mailing list, but I already did and got no answer from them.
So I wonder if someone has a clue about this:


I'm compiling the following c code with -O2 on ia64-linux, xtensa-linux,
bfin targets, gcc-4.2.0:


int loop(int a[], int b[],int sum)
    {
        unsigned int i;
        for (i = 0; i < 100; i++)
            sum+=a[i]*b[i];
        return sum;
    }


I don't see any auto increment of the pointers inside the loop in any
one of them. (You can see below the assembly code outputted by each
one).


I also simplified the loop to contain: sum+=a[i];
But nothing helps. Post modification is simply not done.


It seems strange this feature is neglected in such way in gcc-4.2.0.
Does anyone have an idea???


Thanks,
Tal.


xtensa-linux output:


                .file "loop_pointers.c"
                .global __mulsi3
                .text
                .literal_position
                .literal .LC2, __mulsi3@PLT
                .align 4
                .global loop
                .type loop, @function
loop:
                .frame sp, 32
                entry sp, 32
                l32i.n a11, a2, 0
                l32r a5, .LC2
                l32i.n a10, a3, 0
                mov.n a6, a2
                callx8 a5
                add.n a2, a4, a10
                movi.n a7, 4
                movi a4, 0x190
.L2:
                add.n a8, a7, a3
                add.n a9, a7, a6
                l32i.n a10, a8, 0
                l32i.n a11, a9, 0
                addi.n a7, a7, 4
                callx8 a5
                add.n a2, a2, a10
                bne a7, a4, .L2
                retw.n
                .size loop, .- loop
                .ident "GCC: (GNU) 4.2.0"


Ia64-linux output:


.file "loop_pointers.c"
.pred.safe_across_calls p1-p5,p16-p63
.text
.align 16
.global loop#
.proc loop#
loop:
.prologue
.mmb
ld4 r15 = [r33]
ld4 r14 = [r32]
nop 0
.mmi
setf.sig f9 = r34
addl r17 = 4, r0
.save ar.lc, r2
mov r2 = ar.lc
.body
;;
.mmi
setf.sig f7 = r15
setf.sig f8 = r14
mov ar.lc = 98
;;
.mmf
nop 0
nop 0
xma.l f6 = f7, f8, f9
.L2:
.mmi
add r14 = r17, r33
add r16 = r17, r32
adds r17 = 4, r17
;;
.mmi
ld4 r15 = [r14]
ld4 r14 = [r16]
nop 0
;;
.mmi
setf.sig f7 = r15
setf.sig f8 = r14
nop 0
;;
.mfb
nop 0
xma.l f6 = f7, f8, f6
br.cloop.sptk.few .L2
;;
.mib
getf.sig r8 = f6
mov ar.lc = r2
br.ret.sptk.many b0
.endp loop#
.ident "GCC: (GNU) 4.2.0"




bfin output:


.file "loop_pointers.c";
.text;
.align 4
.global _loop;
.type _loop, STT_FUNC;
_loop:
[--sp] = ( p5:3 );


P3 = R0;
P4 = R1;
LINK 0;
P0 = 4 (X);
P5 = 99 (X);
R1 = [P3];
R0 = [P4];
R0 *= R1;
R2 = R2 + R0;
LSETUP (L$L$2, L$L$8) LC1 = P5;
L$L$2:
P2 = P0 + P4;
P1 = P0 + P3;
R0 = [P2];
R1 = [P1];
R0 *= R1;
P0 += 4;
L$L$8:
R2 = R2 + R0;
UNLINK;
R0 = R2;
( p5:3 ) = [sp++];


rts;
.size _loop, .-_loop
.ident "GCC: (GNU) 4.2.0"


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.