public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/52835] New: Incorrect code generated by gfortran 4.7.0
@ 2012-04-02 15:22 arnaud02 at users dot sourceforge.net
  2012-04-02 16:12 ` [Bug middle-end/52835] [4.7/4.8 Regression] -O3 wrongly optimizes loop __builtin_memcpy away burnus at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: arnaud02 at users dot sourceforge.net @ 2012-04-02 15:22 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 52835
           Summary: Incorrect code generated by gfortran 4.7.0
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: arnaud02@users.sourceforge.net


>uname -sm
Linux x86_64
>cat qq.f
      SUBROUTINE QQ2( ISU, ZSPM, RSV, MS )
      INTEGER :: ISU(MS)
      CHARACTER(8) :: ZSPM(MS)
      REAL :: RSV(MS)

      DO IS=1,MS
         ISU(IS)=0
         ZSPM(IS)=' '
         RSV(IS) =0.0
      ENDDO
      END subroutine qq2

      SUBROUTINE QQ()
      INTEGER, ALLOCATABLE :: ISU(:)
      CHARACTER(8), ALLOCATABLE :: ZSPM(:)
      REAL, ALLOCATABLE :: RSV(:)

      ALLOCATE( RSV(3) )
      ALLOCATE( ISU(3) )
      ALLOCATE( ZSPM(3) )
      CALL QQ2( ISU, ZSPM, RSV, 3 )
      write(*,*) '-->',zspm(1)
      END subroutine qq

      program p1
      call qq()
      end program p1
>gfortran470 -O3 -g qq.f -static-libgfortran ; valgrind --track-origins=yes ./a.out
==18017== Memcheck, a memory error detector
==18017== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==18017== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==18017== Command: ./a.out
==18017==
==18017== Syscall param write(buf) points to uninitialised byte(s)
==18017==    at 0x3541CC4150: __write_nocancel (in /lib64/libc-2.5.so)
==18017==    by 0x40981C: raw_write (unix.c:308)
==18017==    by 0x40F4FE: _gfortrani_fbuf_flush (unix.h:56)
==18017==    by 0x405416: _gfortrani_next_record (transfer.c:3397)
==18017==    by 0x405CF8: _gfortran_st_write_done (transfer.c:3592)
==18017==    by 0x401C5B: qq_ (qq.f:22)
==18017==    by 0x401CFC: main (qq.f:26)
==18017==  Address 0x4c2fb44 is 4 bytes inside a block of size 512 alloc'd
==18017==    at 0x4A0776F: malloc (vg_replace_malloc.c:263)
==18017==    by 0x4037B8: _gfortrani_get_mem (memory.c:43)
==18017==    by 0x40F38A: _gfortrani_fbuf_init (fbuf.c:43)
==18017==    by 0x408F89: _gfortrani_init_units (unit.c:585)
==18017==    by 0x403747: init (main.c:226)
==18017==    by 0x4196F5: ??? (in /tmp/arnaud/a.out)
==18017==    by 0x401612: ??? (in /tmp/arnaud/a.out)
==18017==    by 0x9CA212C00000000: ???
==18017==    by 0x419676: __libc_csu_init (in /tmp/arnaud/a.out)
==18017==    by 0x3541C1D84D: (below main) (in /lib64/libc-2.5.so)
==18017==  Uninitialised value was created by a heap allocation
==18017==    at 0x4A0776F: malloc (vg_replace_malloc.c:263)
==18017==    by 0x401BE0: qq_ (qq.f:20)
==18017==    by 0x401CFC: main (qq.f:26)
==18017==
 -->
==18017==
==18017== HEAP SUMMARY:
==18017==     in use at exit: 0 bytes in 0 blocks
==18017==   total heap usage: 20 allocs, 20 frees, 3,878 bytes allocated
==18017==
==18017== All heap blocks were freed -- no leaks are possible
==18017==
==18017== For counts of detected and suppressed errors, rerun with: -v
==18017== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)

The test case above demonstrates the problem observed on a large production
system. In qq2, zspm is not set properly to " " as shown by valgrind. This is
taking place only when compiled with "-O3". 

This is a regression with respect to gfortran 4.6.2.


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

* [Bug middle-end/52835] [4.7/4.8 Regression] -O3 wrongly optimizes loop __builtin_memcpy away
  2012-04-02 15:22 [Bug fortran/52835] New: Incorrect code generated by gfortran 4.7.0 arnaud02 at users dot sourceforge.net
@ 2012-04-02 16:12 ` burnus at gcc dot gnu.org
  2012-04-02 16:19 ` dominiq at lps dot ens.fr
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu.org @ 2012-04-02 16:12 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |wrong-code
   Last reconfirmed|                            |2012-04-02
          Component|fortran                     |middle-end
                 CC|                            |burnus at gcc dot gnu.org
     Ever Confirmed|0                           |1
            Summary|Incorrect code generated by |[4.7/4.8 Regression] -O3
                   |gfortran 4.7.0              |wrongly optimizes loop
                   |                            |__builtin_memcpy away
   Target Milestone|---                         |4.7.1

--- Comment #1 from Tobias Burnus <burnus at gcc dot gnu.org> 2012-04-02 16:11:37 UTC ---
Confirmed - and smells rather like a middle-end issue. (Or a rather convoluted
FE declaration bug.)


Works with my 2011-12-24-r182676 build
Fails with my 2012-02-28-r184613 build
(Note: Those contained some patches, which shouldn't™ affect the result.)

 * * *

Works with: gfortran -fdump-tree-optimized -funswitch-loops
-fpredictive-commoning -fgcse-after-reload -ftree-vectorize -finline-functions
-fipa-cp-clone -O2
(And fails with -O3 and the -fno-* version of those flags.) Thus, none of the
specific flags which get enabled with -O3 seems too blame.

 * * *

Looking at the optimized dump, the loop
      DO IS=1,MS
         ISU(IS)=0
         ZSPM(IS)=' '
         RSV(IS) =0.0
      ENDDO

gets replaced by:
  __builtin_memset (D.1976_27, 0, 12);
  __builtin_memset (D.1956_11, 0, 12);

That's almost fine, however, the
  ZSPM(is) = ' '
is lacking. With -O2 one finds in the loop:
  __builtin_memcpy (D.2078_113, &"        "[0], 8);

Note that ZSPM is an array of size 3 of character strings of length 8:
  character(len=8) :: ZSPM(MS)
where "MS" is 3.

The best (optimized) version would be something like "memset(ZSPM, " ", 3*8);".


In 4.6, one had (with -O3) and expanded loop with the following for [0], [1]
and [2]:
  D.1697_89 = &MEM[(character(kind=1)[0:D.1598][1:8] *)D.1577_23][0];
  __builtin_memcpy (D.1697_89, &"        "[0], 8);


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

* [Bug middle-end/52835] [4.7/4.8 Regression] -O3 wrongly optimizes loop __builtin_memcpy away
  2012-04-02 15:22 [Bug fortran/52835] New: Incorrect code generated by gfortran 4.7.0 arnaud02 at users dot sourceforge.net
  2012-04-02 16:12 ` [Bug middle-end/52835] [4.7/4.8 Regression] -O3 wrongly optimizes loop __builtin_memcpy away burnus at gcc dot gnu.org
@ 2012-04-02 16:19 ` dominiq at lps dot ens.fr
  2012-04-02 17:54 ` arnaud02 at users dot sourceforge.net
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dominiq at lps dot ens.fr @ 2012-04-02 16:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Dominique d'Humieres <dominiq at lps dot ens.fr> 2012-04-02 16:18:47 UTC ---
r183622 is OK
r183649 miscompiles the code.


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

* [Bug middle-end/52835] [4.7/4.8 Regression] -O3 wrongly optimizes loop __builtin_memcpy away
  2012-04-02 15:22 [Bug fortran/52835] New: Incorrect code generated by gfortran 4.7.0 arnaud02 at users dot sourceforge.net
  2012-04-02 16:12 ` [Bug middle-end/52835] [4.7/4.8 Regression] -O3 wrongly optimizes loop __builtin_memcpy away burnus at gcc dot gnu.org
  2012-04-02 16:19 ` dominiq at lps dot ens.fr
@ 2012-04-02 17:54 ` arnaud02 at users dot sourceforge.net
  2012-04-02 19:19 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: arnaud02 at users dot sourceforge.net @ 2012-04-02 17:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Arnaud Desitter <arnaud02 at users dot sourceforge.net> 2012-04-02 17:54:06 UTC ---
Additionally:
>cat xxx.f
      SUBROUTINE XXX(RES,ALP,REN,NN )
      DIMENSION ALP(NN),REN (NN),RES (NN)
      DO IP = 1,NN
         REN(IP) = 0.0
         ALP(IP) = 0.0
         CALL YYY(ALP(IP),REN(IP),RES(IP))
      ENDDO
      END
>gfortran470 -c -O3 -o xxx_O3.o xxx.f ; gfortran470 -c -O2 -o xxx_O2.o xxx.f ; nm xxx*.o

xxx_O2.o:
0000000000000000 T xxx_
                 U yyy_

xxx_O3.o:
                 U memset
0000000000000000 T xxx_

When compiled with -O3, the call to "YYY" is not generated. This is a pretty
serious wrong code generation.


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

* [Bug middle-end/52835] [4.7/4.8 Regression] -O3 wrongly optimizes loop __builtin_memcpy away
  2012-04-02 15:22 [Bug fortran/52835] New: Incorrect code generated by gfortran 4.7.0 arnaud02 at users dot sourceforge.net
                   ` (2 preceding siblings ...)
  2012-04-02 17:54 ` arnaud02 at users dot sourceforge.net
@ 2012-04-02 19:19 ` jakub at gcc dot gnu.org
  2012-04-02 19:38 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-04-02 19:19 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-04-02 19:18:22 UTC ---
Started with http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183624 and it is
ldist that incorrectly removes the call.


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

* [Bug middle-end/52835] [4.7/4.8 Regression] -O3 wrongly optimizes loop __builtin_memcpy away
  2012-04-02 15:22 [Bug fortran/52835] New: Incorrect code generated by gfortran 4.7.0 arnaud02 at users dot sourceforge.net
                   ` (3 preceding siblings ...)
  2012-04-02 19:19 ` jakub at gcc dot gnu.org
@ 2012-04-02 19:38 ` jakub at gcc dot gnu.org
  2012-04-03  8:49 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-04-02 19:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-04-02 19:38:31 UTC ---
Created attachment 27069
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27069
gcc48-pr52835.patch

Untested fix.  Ignoring failures from compute_*loop can't be right.


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

* [Bug middle-end/52835] [4.7/4.8 Regression] -O3 wrongly optimizes loop __builtin_memcpy away
  2012-04-02 15:22 [Bug fortran/52835] New: Incorrect code generated by gfortran 4.7.0 arnaud02 at users dot sourceforge.net
                   ` (4 preceding siblings ...)
  2012-04-02 19:38 ` jakub at gcc dot gnu.org
@ 2012-04-03  8:49 ` jakub at gcc dot gnu.org
  2012-04-03  9:06 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-04-03  8:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-04-03 08:49:18 UTC ---
Author: jakub
Date: Tue Apr  3 08:49:14 2012
New Revision: 186101

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186101
Log:
    PR tree-optimization/52835
    * tree-data-ref.c (build_rdg): Return NULL if
    compute_data_dependences_for_loop failed.

    * gfortran.dg/pr52835.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/pr52835.f90
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-data-ref.c


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

* [Bug middle-end/52835] [4.7/4.8 Regression] -O3 wrongly optimizes loop __builtin_memcpy away
  2012-04-02 15:22 [Bug fortran/52835] New: Incorrect code generated by gfortran 4.7.0 arnaud02 at users dot sourceforge.net
                   ` (5 preceding siblings ...)
  2012-04-03  8:49 ` jakub at gcc dot gnu.org
@ 2012-04-03  9:06 ` jakub at gcc dot gnu.org
  2012-04-03  9:12 ` jakub at gcc dot gnu.org
  2012-04-10 12:29 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-04-03  9:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-04-03 09:05:05 UTC ---
Author: jakub
Date: Tue Apr  3 09:05:00 2012
New Revision: 186103

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186103
Log:
    PR tree-optimization/52835
    * tree-data-ref.c (build_rdg): Return NULL if
    compute_data_dependences_for_loop failed.

    * gfortran.dg/pr52835.f90: New test.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/gfortran.dg/pr52835.f90
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_7-branch/gcc/tree-data-ref.c


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

* [Bug middle-end/52835] [4.7/4.8 Regression] -O3 wrongly optimizes loop __builtin_memcpy away
  2012-04-02 15:22 [Bug fortran/52835] New: Incorrect code generated by gfortran 4.7.0 arnaud02 at users dot sourceforge.net
                   ` (6 preceding siblings ...)
  2012-04-03  9:06 ` jakub at gcc dot gnu.org
@ 2012-04-03  9:12 ` jakub at gcc dot gnu.org
  2012-04-10 12:29 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-04-03  9:12 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-04-03 09:07:22 UTC ---
Fixed.


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

* [Bug middle-end/52835] [4.7/4.8 Regression] -O3 wrongly optimizes loop __builtin_memcpy away
  2012-04-02 15:22 [Bug fortran/52835] New: Incorrect code generated by gfortran 4.7.0 arnaud02 at users dot sourceforge.net
                   ` (7 preceding siblings ...)
  2012-04-03  9:12 ` jakub at gcc dot gnu.org
@ 2012-04-10 12:29 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-04-10 12:29 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |garfieldsk at gmail dot com

--- Comment #9 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-04-10 12:28:50 UTC ---
*** Bug 52920 has been marked as a duplicate of this bug. ***


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

end of thread, other threads:[~2012-04-10 12:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-02 15:22 [Bug fortran/52835] New: Incorrect code generated by gfortran 4.7.0 arnaud02 at users dot sourceforge.net
2012-04-02 16:12 ` [Bug middle-end/52835] [4.7/4.8 Regression] -O3 wrongly optimizes loop __builtin_memcpy away burnus at gcc dot gnu.org
2012-04-02 16:19 ` dominiq at lps dot ens.fr
2012-04-02 17:54 ` arnaud02 at users dot sourceforge.net
2012-04-02 19:19 ` jakub at gcc dot gnu.org
2012-04-02 19:38 ` jakub at gcc dot gnu.org
2012-04-03  8:49 ` jakub at gcc dot gnu.org
2012-04-03  9:06 ` jakub at gcc dot gnu.org
2012-04-03  9:12 ` jakub at gcc dot gnu.org
2012-04-10 12:29 ` 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).