public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/53419] New: loop incorrectly optimized to endless loop at -O2 for table delimited by extern addresses (x86-32)
@ 2012-05-19 19:41 gary at intrepid dot com
  2012-05-19 19:43 ` [Bug tree-optimization/53419] " gary at intrepid dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: gary at intrepid dot com @ 2012-05-19 19:41 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53419
           Summary: loop incorrectly optimized to endless loop at -O2 for
                    table delimited by extern addresses (x86-32)
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: gary@intrepid.com
              Host: x86-32
            Target: x86-32


The attached test case, duplicated below yields an infinite loop when compiled
by GCC 4.8 trunk version 187666.  This appears to be a relatively recent
regression
(likely between 185454 and 186243).

typedef unsigned int size_t;

typedef void (*func_ptr_t) (void);
extern func_ptr_t init_array_begin[1];
extern func_ptr_t init_array_end[1];

void
per_thread_init (void)
{
  size_t n_init = (init_array_end - init_array_begin);
  int i;
  for (i = 0; i < n_init; ++i)
    {
      func_ptr_t init_func = init_array_begin[i];
      if (init_func)
        (*init_func) ();
    }
}

At -O1, the loop looks like this:

.L4:
        movl    init_array_begin(,%ebx,4), %eax
        testl   %eax, %eax
        je      .L3
        call    *%eax
.L3:
        addl    $1, %ebx
        cmpl    %esi, %ebx
        jne     .L4

At -O2 it looks like this.

.L5:
        movl    init_array_begin, %eax
        testl   %eax, %eax
        je      .L3
        call    *%eax
.L3:
        cmpl    $1, %ebx
        jne     .L5

The comparison "cmpl    $1, %ebx" is problematic, as well as the lack of
indexing the array.


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

end of thread, other threads:[~2012-05-21 12:44 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-19 19:41 [Bug tree-optimization/53419] New: loop incorrectly optimized to endless loop at -O2 for table delimited by extern addresses (x86-32) gary at intrepid dot com
2012-05-19 19:43 ` [Bug tree-optimization/53419] " gary at intrepid dot com
2012-05-19 19:43 ` gary at intrepid dot com
2012-05-19 19:44 ` gary at intrepid dot com
2012-05-19 21:47 ` hjl.tools at gmail dot com
2012-05-19 22:09 ` pinskia at gcc dot gnu.org
2012-05-19 22:12 ` gary at intrepid dot com
2012-05-19 22:20 ` gary at intrepid dot com
2012-05-21 10:09 ` rguenth at gcc dot gnu.org
2012-05-21 10:41 ` jakub at gcc dot gnu.org
2012-05-21 12:45 ` 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).