Bug 42961 - [4.6 regression] IRA register preferencing bug
Summary: [4.6 regression] IRA register preferencing bug
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.5.0
: P2 normal
Target Milestone: 4.7.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization, ra
: 42969 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-02-04 22:05 UTC by Jan Hubicka
Modified: 2013-04-12 16:17 UTC (History)
4 users (show)

See Also:
Host: x86_64-linux
Target: x86_64-linux
Build:
Known to work: 4.3.4, 4.7.0
Known to fail:
Last reconfirmed: 2010-03-20 13:01:50


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Hubicka 2010-02-04 22:05:39 UTC
For following testcase:
int e,f;
float
main(float d,float c)
{
   float a;
   float e;
   if (e)
     a=d, e=c;
   else
     a=c, c=e;
   if (f)
     e=a;
   return e;
}
(it looks artifical, but all the moves are there just to make "a" to be only source or destination of reg-reg move that is not that uncommon in real world code)
we generate completely bogus:
main:
.LFB0:
        .cfi_startproc
        xorps   %xmm2, %xmm2
        movss   %xmm1, -4(%rsp)
        movl    -4(%rsp), %eax
        ucomiss %xmm2, %xmm2
        jp      .L7
        je      .L3
.L7:
        movss   %xmm0, -4(%rsp)
        movl    -4(%rsp), %eax
        movaps  %xmm1, %xmm2
.L3:
        movl    f(%rip), %edx
        testl   %edx, %edx
        je      .L4
        movl    %eax, -4(%rsp)
        movss   -4(%rsp), %xmm2
.L4:
        movaps  %xmm2, %xmm0
        ret

instead of
main:
.LFB2:
        movaps  %xmm0, %xmm3
        xorps   %xmm0, %xmm0
        movaps  %xmm1, %xmm2
        ucomiss %xmm0, %xmm0
        jp      .L2
        je      .L3
.L2:
        movaps  %xmm3, %xmm2
        movaps  %xmm1, %xmm0
.L3:
        movl    f(%rip), %eax
        testl   %eax, %eax
        je      .L4
        movaps  %xmm2, %xmm0
.L4:
        rep
        ret
.LFE2:

generated by GCC 4.3.2.

The problem is that IRA concludes wrong register preferencing:
    a3 (r62,l0) best SSE_REGS, cover SSE_REGS
    a2 (r61,l0) best SSE_FIRST_REG, cover SSE_REGS
    a1 (r59,l0) best GENERAL_REGS, cover GENERAL_REGS
    a0 (r58,l0) best SSE_FIRST_REG, cover SSE_REGS

this is because of movdf pattern having alternative for general regs.
This alternative is however useful primarily when the value is temporary for mem-mem moves, and IRA should be able to work this out.
Comment 1 Richard Biener 2010-02-05 10:52:16 UTC
*** Bug 42969 has been marked as a duplicate of this bug. ***
Comment 2 Jan Hubicka 2010-02-10 09:26:01 UTC
Subject: Re:   New: [4.5 regression] IRA register
	preferencing bug

Hi,
note that it is related to way we compute cost through alternatives.
I had very old patch for this http://www.x86-64.org/pipermail/patches/2001-February/001071.html
that would eventually help to remove the '#' constraints on all FP operations that are there
to avoid RA from mixing integer and FP classes. Perhaps IRA can now do something similar
and actually propagate the info?

Honza
Comment 3 Richard Biener 2010-04-06 11:20:48 UTC
GCC 4.5.0 is being released.  Deferring to 4.5.1.
Comment 4 Richard Biener 2010-07-31 09:29:43 UTC
GCC 4.5.1 is being released, adjusting target milestone.
Comment 5 Richard Biener 2010-12-16 13:02:54 UTC
GCC 4.5.2 is being released, adjusting target milestone.
Comment 6 Richard Biener 2011-04-28 14:51:12 UTC
GCC 4.5.3 is being released, adjusting target milestone.
Comment 7 Andrew Pinski 2012-01-05 01:02:51 UTC
This looks like it was fixed on the trunk, we no longer have any movss/movl.
Comment 8 Mikael Pettersson 2012-02-19 17:43:07 UTC
The movss instructions were eliminated on trunk by Vladimir Makarov's "patch to solve recent SPEC2000 degradation" in r178019:
http://gcc.gnu.org/ml/gcc-patches/2011-08/msg01954.html
http://gcc.gnu.org/ml/gcc-cvs/2011-08/msg01034.html

The code generation change at that point is:

--- pr42961.s-r178018   2012-02-19 18:22:46.000000000 +0100
+++ pr42961.s-r178019   2012-02-19 18:17:07.000000000 +0100
@@ -10,18 +10,17 @@
        ucomiss %xmm2, %xmm2
        jp      .L7
        jne     .L7
-       movss   %xmm1, -4(%rsp)
 .L2:
        movl    f(%rip), %eax
        testl   %eax, %eax
        je      .L4
-       movss   -4(%rsp), %xmm2
+       movaps  %xmm1, %xmm2
 .L4:
        movaps  %xmm2, %xmm0
        ret
 .L7:
        movaps  %xmm1, %xmm2
-       movss   %xmm0, -4(%rsp)
+       movaps  %xmm0, %xmm1
        jmp     .L2
        .cfi_endproc
 .LFE0:
Comment 9 Richard Biener 2012-07-02 11:04:19 UTC
The 4.5 branch is being closed, adjusting target milestone.
Comment 10 Jakub Jelinek 2013-04-12 16:17:33 UTC
The 4.6 branch has been closed, fixed in GCC 4.7.0.