Bug 14473 - Failure to use count register
Summary: Failure to use count register
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.4.0
: P2 enhancement
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2004-03-08 02:13 UTC by Anton Blanchard
Modified: 2004-10-07 23:42 UTC (History)
1 user (show)

See Also:
Host:
Target: powerpc-unknown-linux-gnu
Build:
Known to work:
Known to fail: 3.4.0 3.3.3 4.0.0 tree-ssa
Last reconfirmed: 2004-03-08 02:21:31


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anton Blanchard 2004-03-08 02:13:32 UTC
I found this in ppc32 3.3.3 (Debian), it also appears in 3.4.0 20040215.

If the loop count is large enough, it wont use the count register in the second
loop. eg:

#if 1
#define LOOPS 100000
#else
#define LOOPS 10
#endif
                                                                                
int main()
{
        unsigned long i;
                                                                                
        i = LOOPS;
        while (i--) {
                asm volatile("":::"memory");
        }
                                                                                
        i = LOOPS;
        while (i--) {
                asm volatile("":::"memory");
        }
}

produces the following code:

        lis 0,0x1
        ori 0,0,34464
        mtctr 0
.L13:
        bdnz .L13
        lis 0,0x1
        ori 0,0,34464
.L12:
        addic. 0,0,-1
        bne+ 0,.L12
        blr

If you reduce COUNT it will use the count register for both loops as expected
Comment 1 Andrew Pinski 2004-03-08 02:21:31 UTC
I can confirm this on the mainline and the tree-ssa, I have not looked to see if the doloop rewrite fixes 
it as I do not have the lno branch on the computer which I have access to right now.
Comment 2 Alan Modra 2004-03-08 05:52:12 UTC
I thought this looked familiar.  There's an old patch of mine at
http://gcc.gnu.org/ml/gcc-patches/2002-09/msg01194.html
Comment 3 Andrew Pinski 2004-06-04 05:52:15 UTC
Fixed on the mainline, most likely by the rewrite of doloop optimization.