public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/37810]  New: Bad store sinking job
@ 2008-10-12 15:14 carlo at gcc dot gnu dot org
  2008-10-12 15:21 ` [Bug tree-optimization/37810] " rguenth at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: carlo at gcc dot gnu dot org @ 2008-10-12 15:14 UTC (permalink / raw)
  To: gcc-bugs

The following code snippet:

void g();

struct A {
  int n;
  int m;

  A& operator++(void)
  {
    if (__builtin_expect(n == m, false))
      g();
    else
      ++n;
    return *this;
  }

  A() : n(0), m(0) { }

  friend bool operator!=(A const& a1, A const& a2) { return a1.n != a2.n; }
};

void testfunction(A& iter)
{
  A const end;
  while (iter != end)
    ++iter;
}

Results in the following assembly code, using maximum optimization:

        movl    (%rdi), %eax
        jmp     .L6

.L4:
        cmpl    %eax, 4(%rdi)     // n == m ?
        je      .L8               // unlikely jump
        addl    $1, %eax          // ++n
        movl    %eax, (%rdi)      // *** store result to memory ***
.L6:
        testl   %eax, %eax        // iter != end ?
        jne     .L4               // continue while loop


The storing (back) of %eax to (%rdi) remains inside the inner
loop no matter what I try. It could/should be moved outside
the loop, since nothing inside the L4 loop is accessing (%rdi)
or could possibly be accessing that memory.

This loop has two exits: below the last jne .L4, and the
jump to .L8. The store could be sinked to both exits.
This grows the code, but it seems reasonable to do for
a loop with a very small body, especially if one of the
exits is marked as unlikely :p.


-- 
           Summary: Bad store sinking job
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: carlo at gcc dot gnu dot org


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


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

end of thread, other threads:[~2021-07-27  7:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-37810-4@http.gcc.gnu.org/bugzilla/>
2021-07-26  4:35 ` [Bug tree-optimization/37810] Bad store sinking job pinskia at gcc dot gnu.org
2021-07-27  7:03 ` rguenth at gcc dot gnu.org
2008-10-12 15:14 [Bug tree-optimization/37810] New: " carlo at gcc dot gnu dot org
2008-10-12 15:21 ` [Bug tree-optimization/37810] " rguenth at gcc dot gnu dot org
2008-10-12 15:27 ` rguenth at gcc dot gnu dot org
2008-10-12 15:30 ` rguenth at gcc dot gnu dot org
2008-10-12 15:34 ` carlo at gcc dot gnu dot org
2009-04-03 12:34 ` rguenth at gcc dot gnu dot 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).