public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/54919] New: [4.6/4.7/4.8 Regression] gcc.dg/torture/pr54877.c FAILs with -fvariable-expansion-in-unroller
@ 2012-10-13 10:18 zsojka at seznam dot cz
  2012-10-13 10:39 ` [Bug rtl-optimization/54919] " steven at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: zsojka at seznam dot cz @ 2012-10-13 10:18 UTC (permalink / raw)
  To: gcc-bugs


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: unassigned@gcc.gnu.org
        ReportedBy: zsojka@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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-06-12 13:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-13 10:18 [Bug rtl-optimization/54919] New: [4.6/4.7/4.8 Regression] gcc.dg/torture/pr54877.c FAILs with -fvariable-expansion-in-unroller zsojka at seznam dot cz
2012-10-13 10:39 ` [Bug rtl-optimization/54919] " steven at gcc dot gnu.org
2012-10-13 16:38 ` steven at gcc dot gnu.org
2012-10-13 18:06 ` hubicka at gcc dot gnu.org
2012-10-13 21:51 ` steven at gcc dot gnu.org
2012-10-14 19:29 ` steven at gcc dot gnu.org
2012-10-14 20:31 ` [Bug rtl-optimization/54919] [4.6/4.7 " steven at gcc dot gnu.org
2012-10-14 20:32 ` steven at gcc dot gnu.org
2013-04-03  9:45 ` rguenth at gcc dot gnu.org
2013-04-12 15:18 ` [Bug rtl-optimization/54919] [4.7 " jakub at gcc dot gnu.org
2014-06-12 13:18 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).