http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54919



             Bug #: 54919

           Summary: [4.6/4.7/4.8 Regression] gcc.dg/torture/pr54877.c

                    FAILs with -fvariable-expansion-in-unroller

    Classification: Unclassified

           Product: gcc

           Version: 4.8.0

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: rtl-optimization

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: zso...@seznam.cz





Created attachment 28439

  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28439

preprocessed source



Output:

$ gcc -O2 -ffast-math -funroll-loops -fvariable-expansion-in-unroller

testcase.c

$ ./a.out 

Aborted



What happens is that foo() returns -63 instead of -64.



.L15:

    movapd    xmm0, xmm2    # d, tmp71

    sub    eax, 8    # D.1761,

    subsd    xmm0, xmm1    # d, tmp69

    subsd    xmm0, xmm1    # d, tmp69

    subsd    xmm0, xmm1    # d, tmp69

1==>    movapd    xmm2, xmm0    # tmp71, d

2==>    subsd    xmm2, xmm1    # tmp71, tmp69

    jne    .L15    #,

3==>    addsd    xmm0, xmm2    # d, tmp71

    cvttsd2si    edx, xmm0    # D.1762, d



In each loop, 4 is subtracted, and finally, the sum is multiplied by 2 at (3).



The problem is that when (3) is executed, xmm2==-32 and xmm0==-31 ; so the

final sum is -63.



If (1) and (2) are swapped (and (2) uses xmm0 instead of xmm2), the code works

fine:



.L15:

    movapd    xmm0, xmm2    # d, tmp71

    sub    eax, 8    # D.1761,

    subsd    xmm0, xmm1    # d, tmp69

    subsd    xmm0, xmm1    # d, tmp69

    subsd    xmm0, xmm1    # d, tmp69

2==>    subsd    xmm0, xmm1    # tmp71, tmp69

1==>    movapd    xmm2, xmm0    # tmp71, d

    jne    .L15    #,

3==>    addsd    xmm0, xmm2    # d, tmp71

    cvttsd2si    edx, xmm0    # D.1762, d



Note foo() is inlined into main(), so the change has to be done in main() (or

the noinline attribute has to be added).



Tested revisions:

r192420 - fail

4.7 r191640 - fail

4.6 r191640 - fail

4.5 r191640 - fail

4.4 r191640 - OK

Reply via email to