This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [tree-profiling] Fix some leftouts of previous patch



On Dec 8, 2004, at 6:43 PM, Dale Johannesen wrote:


On Dec 8, 2004, at 3:10 PM, Andrew Pinski wrote:
On Dec 8, 2004, at 5:55 PM, Jan Hubicka wrote:
Hi,
this patch fix the frequency updating issues (I will still keep the
frequency updating around as I am not quite sure how we will want to
deal with the estimated profiles once available yet) and it also avoid
recursive inlining that helps some benchmarks.



Could back port the recursive inlining part to the mainline since I see that
we recursive inlining functions on the mainline which is a regression from
3.4.0?

It's a regression in some cases and an improvement in others, as usual with
changes to heuristics. Consider everybody's favorite CS 101 example of recursion:


unsigned int factorial(unsigned int x) { return (x==0) ? 1 : x*factorial(x-1); }

Inlining factorial(4) enough that all the calls go away is a clear win.
(It may be that most of the wins come in cases that shouldn't have been
written as recursion in the first place, like this one, but users do things
like that.)


I'm not saying this is necessarily a bad idea, but we should have more data.
I know of 1 case in SPEC where recursive inlining is a win (like the
factorial case, the recursion terminates in a couple of levels, and you
wind up with a leaf function). I don't know of any where it's a loss, but it
sounds like Jan might.

But the simple CS 101 example of recursion for factorial is actually already
optimized the correct way to be a loop instead of a call of a function.
cmpwi cr0,r3,0
li r2,1
beq- cr0,L6
mtctr r3
L5:
addi r0,r3,-1
mullw r2,r2,r3
mr r3,r0
bdnz L5
L6:
mr r3,r2
blr


This is because we do some tail recursion, we did not do before, Zdenek
implemented back when the tree-ssa was a branch.
But with -O3 we get:
_factorial:
        stmw r22,-40(r1)
        mr. r30,r3
        mflr r0
        li r3,1
        stw r0,8(r1)
        stwu r1,-112(r1)
        beq- cr0,L4
        addic. r29,r30,-1
        bne- cr0,L31
L7:
        mullw r3,r3,r30
L4:
        addi r1,r1,112
        lwz r0,8(r1)
        lmw r22,-40(r1)
        mtlr r0
        blr
L31:
        addic. r28,r30,-2
        li r0,1
        beq- cr0,L10
        addic. r27,r30,-3
        beq- cr0,L13
        addic. r26,r30,-4
        beq- cr0,L16
        addic. r25,r30,-5
        beq- cr0,L19
        addic. r24,r30,-6
        beq- cr0,L22
        addic. r23,r30,-7
        beq- cr0,L25
        addic. r22,r30,-8
        bne- cr0,L32
        mullw r0,r0,r23
L25:
        mullw r0,r0,r24
L22:
        mullw r0,r0,r25
L19:
        mullw r0,r0,r26
L16:
        mullw r0,r0,r27
L13:
        mullw r0,r0,r28
L10:
        mullw r3,r0,r29
        b L7
L32:
        addi r3,r30,-9
        bl _factorial
        mullw r0,r22,r3
        mullw r0,r0,r23
        b L25

which still has a recursive function.

Thanks,
Andrew Pinski


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]